@rex0220/kintone-sql-tools 3.57.0 → 3.58.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-cli/ksql.js +173 -69
- package/dist-engine/index.cjs +12 -12
- package/dist-engine/index.mjs +12 -12
- package/dist-engine/ksql-engine.umd.js +12 -12
- package/dist-engine/meta/bundle-baseline.json +7 -7
- package/dist-engine/meta/cjs.json +5 -5
- package/dist-engine/meta/esm.json +5 -5
- package/dist-engine/meta/umd.json +5 -5
- package/dist-mcp/ksql-mcp.js +175 -71
- package/dist-mcpb/ksql-mcp.mcpb +0 -0
- package/package.json +1 -1
package/dist-cli/ksql.js
CHANGED
|
@@ -10780,11 +10780,11 @@ function validatePostImage(record, fieldIndex, numberPrecision, statementNumber,
|
|
|
10780
10780
|
else normalizedRecord[field.code] = { value: preserveCodeObjects(raw, field.fieldType, result.value) };
|
|
10781
10781
|
}
|
|
10782
10782
|
for (const [tableCode, children] of fieldIndex.subtables) {
|
|
10783
|
-
const
|
|
10784
|
-
if (!Array.isArray(
|
|
10783
|
+
const sourceRows2 = record[tableCode]?.value;
|
|
10784
|
+
if (!Array.isArray(sourceRows2)) continue;
|
|
10785
10785
|
const normalizedRows = normalizedRecord[tableCode]?.value;
|
|
10786
|
-
for (let rowIndex = 0; rowIndex <
|
|
10787
|
-
const sourceRow =
|
|
10786
|
+
for (let rowIndex = 0; rowIndex < sourceRows2.length; rowIndex++) {
|
|
10787
|
+
const sourceRow = sourceRows2[rowIndex];
|
|
10788
10788
|
const normalizedRow = normalizedRows[rowIndex];
|
|
10789
10789
|
for (const field of children) {
|
|
10790
10790
|
const raw = sourceRow.value?.[field.code]?.value;
|
|
@@ -13539,6 +13539,65 @@ async function deriveEmptyWildcardColumns(fields, subtableCode, loadProcessStatu
|
|
|
13539
13539
|
}
|
|
13540
13540
|
|
|
13541
13541
|
// src/engine/process.ts
|
|
13542
|
+
var materializedSelectValues = /* @__PURE__ */ new WeakMap();
|
|
13543
|
+
var sourceRows = /* @__PURE__ */ new WeakMap();
|
|
13544
|
+
function asProcessingRow(source) {
|
|
13545
|
+
if (sourceRows.has(source)) return source;
|
|
13546
|
+
let row;
|
|
13547
|
+
row = new Proxy(source, {
|
|
13548
|
+
get(target, property, receiver) {
|
|
13549
|
+
if (typeof property !== "string" || Object.prototype.hasOwnProperty.call(target, property)) {
|
|
13550
|
+
return Reflect.get(target, property, receiver);
|
|
13551
|
+
}
|
|
13552
|
+
return getMaterializedLookupValue(row, property);
|
|
13553
|
+
},
|
|
13554
|
+
has(target, property) {
|
|
13555
|
+
return Reflect.has(target, property) || typeof property === "string" && getMaterializedLookupValue(row, property) !== void 0;
|
|
13556
|
+
},
|
|
13557
|
+
getOwnPropertyDescriptor(target, property) {
|
|
13558
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(target, property);
|
|
13559
|
+
if (descriptor || typeof property !== "string") return descriptor;
|
|
13560
|
+
const value = getMaterializedLookupValue(row, property);
|
|
13561
|
+
return value === void 0 ? void 0 : { configurable: true, enumerable: false, writable: false, value };
|
|
13562
|
+
}
|
|
13563
|
+
});
|
|
13564
|
+
sourceRows.set(row, source);
|
|
13565
|
+
return row;
|
|
13566
|
+
}
|
|
13567
|
+
function sourceRowForEvaluation(row) {
|
|
13568
|
+
return sourceRows.get(row) ?? row;
|
|
13569
|
+
}
|
|
13570
|
+
function materializedValuesFor(row) {
|
|
13571
|
+
let values = materializedSelectValues.get(row);
|
|
13572
|
+
if (!values) {
|
|
13573
|
+
values = { byColumn: /* @__PURE__ */ new Map(), byLookupKey: /* @__PURE__ */ new Map() };
|
|
13574
|
+
materializedSelectValues.set(row, values);
|
|
13575
|
+
}
|
|
13576
|
+
return values;
|
|
13577
|
+
}
|
|
13578
|
+
function setMaterializedSelectValue(row, columnIndex, value, lookupKeys = []) {
|
|
13579
|
+
const values = materializedValuesFor(row);
|
|
13580
|
+
values.byColumn.set(columnIndex, value);
|
|
13581
|
+
for (const key of lookupKeys) values.byLookupKey.set(key, value);
|
|
13582
|
+
}
|
|
13583
|
+
function getMaterializedSelectValue(row, columnIndex) {
|
|
13584
|
+
return materializedSelectValues.get(row)?.byColumn.get(columnIndex);
|
|
13585
|
+
}
|
|
13586
|
+
function getMaterializedLookupValue(row, key) {
|
|
13587
|
+
return materializedSelectValues.get(row)?.byLookupKey.get(key);
|
|
13588
|
+
}
|
|
13589
|
+
function getLegacyMaterializedValue(row, key) {
|
|
13590
|
+
return materializedSelectValues.has(row) ? void 0 : row[key];
|
|
13591
|
+
}
|
|
13592
|
+
function havingEvaluationRow(row) {
|
|
13593
|
+
const lookups = materializedSelectValues.get(row)?.byLookupKey;
|
|
13594
|
+
if (!lookups || lookups.size === 0) return row;
|
|
13595
|
+
const evaluationRow = { ...row };
|
|
13596
|
+
for (const [key, value] of lookups) evaluationRow[key] = value;
|
|
13597
|
+
const groupingMeta = getGroupingRowMeta(row);
|
|
13598
|
+
if (groupingMeta) attachGroupingRowMeta(evaluationRow, groupingMeta.includedCanonicalIds);
|
|
13599
|
+
return evaluationRow;
|
|
13600
|
+
}
|
|
13542
13601
|
function flatten(record, alias) {
|
|
13543
13602
|
const row = {};
|
|
13544
13603
|
for (const [field, fv] of Object.entries(record)) {
|
|
@@ -13643,7 +13702,7 @@ function applyGroupBy(rows, groupByKeys, columns, resolveAggSortKind, resolution
|
|
|
13643
13702
|
}
|
|
13644
13703
|
const result = [];
|
|
13645
13704
|
for (const groupRows of groups.values()) {
|
|
13646
|
-
const outRow = { ...groupRows[0] };
|
|
13705
|
+
const outRow = asProcessingRow({ ...groupRows[0] });
|
|
13647
13706
|
for (const k of groupByKeys) {
|
|
13648
13707
|
if (k.type === "ARITH_KEY") {
|
|
13649
13708
|
outRow[arithColDefaultKey(k.expr)] = String(evalArithExpr(k.expr, groupRows[0]));
|
|
@@ -13695,7 +13754,7 @@ function applyGroupingSets(rows, spec, columns, resolveAggSortKind, limits = {})
|
|
|
13695
13754
|
}
|
|
13696
13755
|
const includedCanonicalIds = new Set(set.items.map((item) => item.canonicalId));
|
|
13697
13756
|
for (const groupRows of buckets) {
|
|
13698
|
-
const outRow = { ...groupRows[0] };
|
|
13757
|
+
const outRow = asProcessingRow({ ...groupRows[0] });
|
|
13699
13758
|
const includedValues = /* @__PURE__ */ new Map();
|
|
13700
13759
|
for (const item of set.items) {
|
|
13701
13760
|
if (!includedValues.has(item.canonicalId)) {
|
|
@@ -13725,32 +13784,52 @@ function materializeAggregateColumns(outRow, groupRows, columns, resolveAggSortK
|
|
|
13725
13784
|
if (col.type === "AGGREGATE") {
|
|
13726
13785
|
const syntheticKey = aggregateSyntheticName(col.func, col.distinct, col.arg);
|
|
13727
13786
|
const value = String(evalAggregate(col.func, col.distinct, col.arg, col.separator, groupRows, resolveAggSortKind));
|
|
13728
|
-
|
|
13729
|
-
|
|
13787
|
+
setMaterializedSelectValue(
|
|
13788
|
+
outRow,
|
|
13789
|
+
columnIndex,
|
|
13790
|
+
value,
|
|
13791
|
+
col.alias ? [col.alias, syntheticKey] : [syntheticKey]
|
|
13792
|
+
);
|
|
13730
13793
|
} else if (col.type === "ARITH_AGG_COL") {
|
|
13731
13794
|
materializeAggregateDependencies(outRow, groupRows, col.expr, resolveAggSortKind);
|
|
13732
13795
|
const outputKey = col.alias ?? aggArithDefaultKey(col.expr);
|
|
13733
|
-
|
|
13796
|
+
setMaterializedSelectValue(
|
|
13797
|
+
outRow,
|
|
13798
|
+
columnIndex,
|
|
13799
|
+
String(evalAggArithExpr(col.expr, groupRows, resolveAggSortKind)),
|
|
13800
|
+
[outputKey]
|
|
13801
|
+
);
|
|
13734
13802
|
} else if (col.type === "STRFUNC_COL" && hasAggregateInStringFuncExpr2(col.expr)) {
|
|
13735
13803
|
materializeAggregateDependencies(outRow, groupRows, col.expr, resolveAggSortKind);
|
|
13736
13804
|
const outputKey = col.alias ?? stringFuncDefaultKey(col.expr);
|
|
13737
13805
|
const resolvedExpr = resolveAggInStringFuncExpr(col.expr, groupRows, resolveAggSortKind);
|
|
13738
|
-
outRow
|
|
13806
|
+
setMaterializedSelectValue(outRow, columnIndex, evalStringFunc(resolvedExpr, outRow), [outputKey]);
|
|
13739
13807
|
} else if (col.type === "SCALAR_VALUE_COL" && scalarValueHasAggregate2(col.expr)) {
|
|
13740
13808
|
materializeAggregateDependencies(outRow, groupRows, col.expr, resolveAggSortKind);
|
|
13741
13809
|
const outputKey = col.alias ?? scalarValueDefaultKey(col.expr);
|
|
13742
13810
|
const resolvedExpr = resolveAggInScalarValue(col.expr, groupRows, resolveAggSortKind);
|
|
13743
|
-
|
|
13811
|
+
setMaterializedSelectValue(
|
|
13812
|
+
outRow,
|
|
13813
|
+
columnIndex,
|
|
13814
|
+
String(evalScalarValueExpr(resolvedExpr, outRow)),
|
|
13815
|
+
[outputKey]
|
|
13816
|
+
);
|
|
13744
13817
|
} else if (col.type === "CASE_COL" && containsAggregate2(col.expr)) {
|
|
13745
13818
|
materializeAggregateDependencies(outRow, groupRows, col.expr, resolveAggSortKind);
|
|
13746
13819
|
const resolvedExpr = resolveAggInCaseExpr(col.expr, groupRows, resolveAggSortKind);
|
|
13747
13820
|
const resolveAggregateSemantics = (field) => field.aggregateRef ? aggregateResultSemantics(field.aggregateRef, resolveAggSortKind) : void 0;
|
|
13748
|
-
|
|
13821
|
+
const value = evalCaseWhen(
|
|
13749
13822
|
resolvedExpr,
|
|
13750
13823
|
outRow,
|
|
13751
13824
|
void 0,
|
|
13752
13825
|
resolveAggregateSemantics
|
|
13753
13826
|
);
|
|
13827
|
+
setMaterializedSelectValue(
|
|
13828
|
+
outRow,
|
|
13829
|
+
columnIndex,
|
|
13830
|
+
value,
|
|
13831
|
+
[caseMaterializedKey(col.alias, columnIndex)]
|
|
13832
|
+
);
|
|
13754
13833
|
}
|
|
13755
13834
|
}
|
|
13756
13835
|
}
|
|
@@ -13776,8 +13855,8 @@ function materializeAggregateDependencies(outRow, rows, node, resolveAggSortKind
|
|
|
13776
13855
|
collectAggregateRefs(node, refs);
|
|
13777
13856
|
for (const ref of refs) {
|
|
13778
13857
|
const key = aggregateSyntheticName(ref.func, ref.distinct, ref.arg);
|
|
13779
|
-
if (outRow
|
|
13780
|
-
|
|
13858
|
+
if (getMaterializedLookupValue(outRow, key) !== void 0) continue;
|
|
13859
|
+
const value = String(evalAggregate(
|
|
13781
13860
|
ref.func,
|
|
13782
13861
|
ref.distinct,
|
|
13783
13862
|
ref.arg,
|
|
@@ -13785,6 +13864,7 @@ function materializeAggregateDependencies(outRow, rows, node, resolveAggSortKind
|
|
|
13785
13864
|
rows,
|
|
13786
13865
|
resolveAggSortKind
|
|
13787
13866
|
));
|
|
13867
|
+
materializedValuesFor(outRow).byLookupKey.set(key, value);
|
|
13788
13868
|
}
|
|
13789
13869
|
}
|
|
13790
13870
|
function evalGroupByKey(key, row, resolution, columns, aliasEvaluationContext) {
|
|
@@ -13899,7 +13979,8 @@ function evalAggregate(func, distinct, arg, separator, rows, resolveAggSortKind)
|
|
|
13899
13979
|
}
|
|
13900
13980
|
}
|
|
13901
13981
|
function aggregateRowValues(func, arg, rows) {
|
|
13902
|
-
return rows.map((
|
|
13982
|
+
return rows.map((processingRow) => {
|
|
13983
|
+
const row = sourceRowForEvaluation(processingRow);
|
|
13903
13984
|
let strVal;
|
|
13904
13985
|
if (arg.type === "FIELD_REF") {
|
|
13905
13986
|
const raw = row[arg.field];
|
|
@@ -13980,7 +14061,13 @@ function aggregateResultSemantics(ref, resolver) {
|
|
|
13980
14061
|
}
|
|
13981
14062
|
function applyHaving(rows, having, resolveFieldType, resolveFieldSemantics2) {
|
|
13982
14063
|
if (having === null) return rows;
|
|
13983
|
-
return rows.filter((row) => evalWhere(
|
|
14064
|
+
return rows.filter((row) => evalWhere(
|
|
14065
|
+
having,
|
|
14066
|
+
havingEvaluationRow(row),
|
|
14067
|
+
resolveFieldType,
|
|
14068
|
+
void 0,
|
|
14069
|
+
resolveFieldSemantics2
|
|
14070
|
+
));
|
|
13984
14071
|
}
|
|
13985
14072
|
function applyDistinct(rows, columns, scalarCache, resolveFieldType, resolveFieldSemantics2) {
|
|
13986
14073
|
if (rows.length === 0) return rows;
|
|
@@ -14092,13 +14179,14 @@ var NUMERIC_ORDER_FUNCTIONS = /* @__PURE__ */ new Set([
|
|
|
14092
14179
|
"WEEK"
|
|
14093
14180
|
]);
|
|
14094
14181
|
function evalOrderKey(key, row, aliasEvaluator) {
|
|
14182
|
+
const sourceRow = sourceRowForEvaluation(row);
|
|
14095
14183
|
switch (key.type) {
|
|
14096
14184
|
case "FIELD_NAME":
|
|
14097
|
-
return aliasEvaluator?.(key.name, row) ?? row[key.name] ?? "";
|
|
14185
|
+
return aliasEvaluator?.(key.name, row) ?? getMaterializedLookupValue(row, key.name) ?? sourceRow[key.name] ?? "";
|
|
14098
14186
|
case "ARITH_KEY":
|
|
14099
|
-
return String(evalArithExpr(key.expr,
|
|
14187
|
+
return String(evalArithExpr(key.expr, sourceRow));
|
|
14100
14188
|
case "FUNC_KEY":
|
|
14101
|
-
return evalStringFunc(key.expr,
|
|
14189
|
+
return evalStringFunc(key.expr, sourceRow);
|
|
14102
14190
|
case "GROUPING_KEY":
|
|
14103
14191
|
return evalGroupingRef(key.ref, row);
|
|
14104
14192
|
}
|
|
@@ -14110,38 +14198,41 @@ function buildOrderByAliasEvaluator(columns, scalarCache, resolveFieldType, reso
|
|
|
14110
14198
|
const alias = column.alias;
|
|
14111
14199
|
switch (column.type) {
|
|
14112
14200
|
case "FIELD":
|
|
14113
|
-
evaluators.set(alias, (row) => resolveFieldRef(row, column.field));
|
|
14201
|
+
evaluators.set(alias, (row) => resolveFieldRef(sourceRowForEvaluation(row), column.field));
|
|
14114
14202
|
break;
|
|
14115
14203
|
case "LITERAL_COL":
|
|
14116
14204
|
evaluators.set(alias, () => column.value);
|
|
14117
14205
|
break;
|
|
14118
14206
|
case "AGGREGATE": {
|
|
14119
|
-
|
|
14120
|
-
evaluators.set(alias, (row) => row[alias] ?? row[source] ?? "0");
|
|
14207
|
+
evaluators.set(alias, (row) => getMaterializedSelectValue(row, columnIndex) ?? "0");
|
|
14121
14208
|
break;
|
|
14122
14209
|
}
|
|
14123
14210
|
case "ARITH_AGG_COL": {
|
|
14124
|
-
|
|
14125
|
-
evaluators.set(alias, (row) => row[alias] ?? row[source] ?? "0");
|
|
14211
|
+
evaluators.set(alias, (row) => getMaterializedSelectValue(row, columnIndex) ?? "0");
|
|
14126
14212
|
break;
|
|
14127
14213
|
}
|
|
14128
14214
|
case "WINDOW_COL":
|
|
14129
|
-
evaluators.set(alias, (row) => row
|
|
14215
|
+
evaluators.set(alias, (row) => getMaterializedSelectValue(row, columnIndex) ?? "");
|
|
14130
14216
|
break;
|
|
14131
14217
|
case "ARITH_COL":
|
|
14132
|
-
evaluators.set(alias, (row) => String(evalArithExpr(column.expr, row)));
|
|
14218
|
+
evaluators.set(alias, (row) => String(evalArithExpr(column.expr, sourceRowForEvaluation(row))));
|
|
14133
14219
|
break;
|
|
14134
14220
|
case "STRFUNC_COL": {
|
|
14135
14221
|
const source = stringFuncDefaultKey(column.expr);
|
|
14136
|
-
evaluators.set(alias, (row) => hasAggregateInStringFuncExpr2(column.expr) ? row
|
|
14222
|
+
evaluators.set(alias, (row) => hasAggregateInStringFuncExpr2(column.expr) ? getMaterializedSelectValue(row, columnIndex) ?? getMaterializedLookupValue(row, source) ?? evalStringFunc(column.expr, sourceRowForEvaluation(row), resolveFieldType, resolveFieldSemantics2) : evalStringFunc(column.expr, sourceRowForEvaluation(row), resolveFieldType, resolveFieldSemantics2));
|
|
14137
14223
|
break;
|
|
14138
14224
|
}
|
|
14139
14225
|
case "CASE_COL":
|
|
14140
|
-
evaluators.set(alias, (row) => containsAggregate2(column.expr) ? row
|
|
14226
|
+
evaluators.set(alias, (row) => containsAggregate2(column.expr) ? getMaterializedSelectValue(row, columnIndex) ?? "" : evalCaseWhen(column.expr, sourceRowForEvaluation(row), resolveFieldType, resolveFieldSemantics2));
|
|
14141
14227
|
break;
|
|
14142
14228
|
case "SCALAR_VALUE_COL": {
|
|
14143
14229
|
const source = scalarValueDefaultKey(column.expr);
|
|
14144
|
-
evaluators.set(alias, (row) => scalarValueHasAggregate2(column.expr) ? row
|
|
14230
|
+
evaluators.set(alias, (row) => scalarValueHasAggregate2(column.expr) ? getMaterializedSelectValue(row, columnIndex) ?? getMaterializedLookupValue(row, source) ?? "" : String(evalScalarValueExpr(
|
|
14231
|
+
column.expr,
|
|
14232
|
+
sourceRowForEvaluation(row),
|
|
14233
|
+
resolveFieldType,
|
|
14234
|
+
resolveFieldSemantics2
|
|
14235
|
+
)));
|
|
14145
14236
|
break;
|
|
14146
14237
|
}
|
|
14147
14238
|
case "SCALAR_SUBQUERY_COL":
|
|
@@ -14157,9 +14248,10 @@ function buildOrderByAliasEvaluator(columns, scalarCache, resolveFieldType, reso
|
|
|
14157
14248
|
return (name, row) => evaluators.get(name)?.(row);
|
|
14158
14249
|
}
|
|
14159
14250
|
function applyWindow(rows, columns, optionOrders, sortKinds, fieldSemantics2, resolveAggSortKind) {
|
|
14160
|
-
const windows = columns.
|
|
14251
|
+
const windows = columns.map((column, columnIndex) => ({ column, columnIndex })).filter((item) => item.column.type === "WINDOW_COL");
|
|
14161
14252
|
if (rows.length === 0 || windows.length === 0) return rows;
|
|
14162
|
-
for (
|
|
14253
|
+
for (let index = 0; index < rows.length; index++) rows[index] = asProcessingRow(rows[index]);
|
|
14254
|
+
for (const { column: window, columnIndex } of windows) {
|
|
14163
14255
|
const partitions = /* @__PURE__ */ new Map();
|
|
14164
14256
|
for (const row of rows) {
|
|
14165
14257
|
const key = JSON.stringify(window.partitionBy.map((ref) => resolveWindowField(row, ref)));
|
|
@@ -14171,11 +14263,11 @@ function applyWindow(rows, columns, optionOrders, sortKinds, fieldSemantics2, re
|
|
|
14171
14263
|
const sortedResult = sortDecoratedRows(partition, window.orderBy, optionOrders, sortKinds, fieldSemantics2);
|
|
14172
14264
|
const sorted = sortedResult.rows;
|
|
14173
14265
|
if (isAggregateWindow(window)) {
|
|
14174
|
-
applyAggregateWindow(window, sortedResult, resolveAggSortKind);
|
|
14266
|
+
applyAggregateWindow(window, columnIndex, sortedResult, resolveAggSortKind);
|
|
14175
14267
|
continue;
|
|
14176
14268
|
}
|
|
14177
14269
|
if (isValueWindow(window)) {
|
|
14178
|
-
applyValueWindow(window, sorted);
|
|
14270
|
+
applyValueWindow(window, columnIndex, sorted);
|
|
14179
14271
|
continue;
|
|
14180
14272
|
}
|
|
14181
14273
|
if (!isRankingWindow(window)) {
|
|
@@ -14189,27 +14281,32 @@ function applyWindow(rows, columns, optionOrders, sortKinds, fieldSemantics2, re
|
|
|
14189
14281
|
denseRank++;
|
|
14190
14282
|
}
|
|
14191
14283
|
const value = window.func === "ROW_NUMBER" ? index + 1 : window.func === "RANK" ? rank : denseRank;
|
|
14192
|
-
sorted[index].row
|
|
14284
|
+
setMaterializedSelectValue(sorted[index].row, columnIndex, String(value), [window.alias]);
|
|
14193
14285
|
}
|
|
14194
14286
|
}
|
|
14195
14287
|
}
|
|
14196
14288
|
return rows;
|
|
14197
14289
|
}
|
|
14198
14290
|
function evaluateValueWindowArg(arg, row) {
|
|
14199
|
-
const value = evalScalarValueExprNullable(arg, row);
|
|
14291
|
+
const value = evalScalarValueExprNullable(arg, sourceRowForEvaluation(row));
|
|
14200
14292
|
if (value === null || value === void 0) return "";
|
|
14201
14293
|
if (typeof value === "number" && !Number.isFinite(value)) return "";
|
|
14202
14294
|
return String(value);
|
|
14203
14295
|
}
|
|
14204
|
-
function applyValueWindow(window, sorted) {
|
|
14296
|
+
function applyValueWindow(window, columnIndex, sorted) {
|
|
14205
14297
|
const values = sorted.map((item) => evaluateValueWindowArg(window.arg, item.row));
|
|
14206
14298
|
const direction = window.valueFunc === "LAG" ? -1 : 1;
|
|
14207
14299
|
for (let index = 0; index < sorted.length; index++) {
|
|
14208
14300
|
const target = index + direction * window.offset;
|
|
14209
|
-
|
|
14301
|
+
setMaterializedSelectValue(
|
|
14302
|
+
sorted[index].row,
|
|
14303
|
+
columnIndex,
|
|
14304
|
+
target >= 0 && target < values.length ? values[target] : "",
|
|
14305
|
+
[window.alias]
|
|
14306
|
+
);
|
|
14210
14307
|
}
|
|
14211
14308
|
}
|
|
14212
|
-
function applyAggregateWindow(window, sortedResult, resolveAggSortKind) {
|
|
14309
|
+
function applyAggregateWindow(window, columnIndex, sortedResult, resolveAggSortKind) {
|
|
14213
14310
|
const sorted = sortedResult.rows;
|
|
14214
14311
|
const values = window.arg.type === "WILDCARD" ? null : aggregateRowValues(window.aggFunc, window.arg, sorted.map((item) => item.row));
|
|
14215
14312
|
const comparison = window.arg.type === "WILDCARD" ? void 0 : resolveAggregateArgSemantics(window.arg, resolveAggSortKind);
|
|
@@ -14242,23 +14339,29 @@ function applyAggregateWindow(window, sortedResult, resolveAggSortKind) {
|
|
|
14242
14339
|
}
|
|
14243
14340
|
if (window.frame === null) {
|
|
14244
14341
|
const finalValue = output[output.length - 1];
|
|
14245
|
-
for (const item of sorted)
|
|
14342
|
+
for (const item of sorted) {
|
|
14343
|
+
setMaterializedSelectValue(item.row, columnIndex, finalValue, [window.alias]);
|
|
14344
|
+
}
|
|
14246
14345
|
return;
|
|
14247
14346
|
}
|
|
14248
14347
|
if (window.frame.unit === "RANGE") {
|
|
14249
14348
|
for (let start = 0; start < sorted.length; ) {
|
|
14250
14349
|
let end = start;
|
|
14251
14350
|
while (end + 1 < sorted.length && sortedResult.compare(sorted[end], sorted[end + 1]) === 0) end++;
|
|
14252
|
-
for (let index = start; index <= end; index++)
|
|
14351
|
+
for (let index = start; index <= end; index++) {
|
|
14352
|
+
setMaterializedSelectValue(sorted[index].row, columnIndex, output[end], [window.alias]);
|
|
14353
|
+
}
|
|
14253
14354
|
start = end + 1;
|
|
14254
14355
|
}
|
|
14255
14356
|
return;
|
|
14256
14357
|
}
|
|
14257
|
-
for (let index = 0; index < sorted.length; index++)
|
|
14358
|
+
for (let index = 0; index < sorted.length; index++) {
|
|
14359
|
+
setMaterializedSelectValue(sorted[index].row, columnIndex, output[index], [window.alias]);
|
|
14360
|
+
}
|
|
14258
14361
|
}
|
|
14259
14362
|
function resolveWindowField(row, ref) {
|
|
14260
14363
|
const name = ref.tableAlias ? `${ref.tableAlias}.${ref.field}` : ref.field;
|
|
14261
|
-
return resolveFieldRef(row, name);
|
|
14364
|
+
return resolveFieldRef(sourceRowForEvaluation(row), name);
|
|
14262
14365
|
}
|
|
14263
14366
|
function applyLimit(rows, limit, offset) {
|
|
14264
14367
|
const start = offset ?? 0;
|
|
@@ -14266,41 +14369,42 @@ function applyLimit(rows, limit, offset) {
|
|
|
14266
14369
|
return rows.slice(start, start + limit);
|
|
14267
14370
|
}
|
|
14268
14371
|
function evaluateSelectColumnValue(column, row, columnIndex, context = {}) {
|
|
14372
|
+
const sourceRow = sourceRowForEvaluation(row);
|
|
14269
14373
|
switch (column.type) {
|
|
14270
14374
|
case "VARIABLE_COL":
|
|
14271
14375
|
throw new Error(`internal error: unresolved SELECT variable @${column.name}`);
|
|
14272
14376
|
case "WILDCARD": {
|
|
14273
|
-
const keys = context.wildcardKeys ?? Object.keys(
|
|
14377
|
+
const keys = context.wildcardKeys ?? Object.keys(sourceRow);
|
|
14274
14378
|
return {
|
|
14275
14379
|
kind: "EXPANDED",
|
|
14276
|
-
entries: keys.map((key) => [key,
|
|
14380
|
+
entries: keys.map((key) => [key, sourceRow[key] !== void 0 ? sourceRow[key] : null])
|
|
14277
14381
|
};
|
|
14278
14382
|
}
|
|
14279
14383
|
case "PARENT_WILDCARD": {
|
|
14280
|
-
const keys = context.parentWildcardKeys ?? Object.keys(
|
|
14384
|
+
const keys = context.parentWildcardKeys ?? Object.keys(sourceRow).filter((key) => key.startsWith("_p.")).sort();
|
|
14281
14385
|
return {
|
|
14282
14386
|
kind: "EXPANDED",
|
|
14283
|
-
entries: keys.map((key) => [key,
|
|
14387
|
+
entries: keys.map((key) => [key, sourceRow[key] !== void 0 ? sourceRow[key] : null])
|
|
14284
14388
|
};
|
|
14285
14389
|
}
|
|
14286
14390
|
case "FIELD":
|
|
14287
|
-
return resolveFieldRef(
|
|
14391
|
+
return resolveFieldRef(sourceRow, column.field);
|
|
14288
14392
|
case "LITERAL_COL":
|
|
14289
14393
|
return column.value;
|
|
14290
14394
|
case "AGGREGATE": {
|
|
14291
14395
|
const source = aggregateSyntheticName(column.func, column.distinct, column.arg);
|
|
14292
|
-
return row
|
|
14396
|
+
return getMaterializedSelectValue(row, columnIndex) ?? getMaterializedLookupValue(row, column.alias ?? source) ?? getMaterializedLookupValue(row, source) ?? getLegacyMaterializedValue(row, column.alias ?? source) ?? getLegacyMaterializedValue(row, source) ?? "0";
|
|
14293
14397
|
}
|
|
14294
14398
|
case "ARITH_AGG_COL": {
|
|
14295
14399
|
const source = column.alias ?? aggArithDefaultKey(column.expr);
|
|
14296
|
-
return row
|
|
14400
|
+
return getMaterializedSelectValue(row, columnIndex) ?? getMaterializedLookupValue(row, source) ?? getLegacyMaterializedValue(row, source) ?? "0";
|
|
14297
14401
|
}
|
|
14298
14402
|
case "ARITH_COL":
|
|
14299
|
-
return String(evalArithExpr(column.expr,
|
|
14403
|
+
return String(evalArithExpr(column.expr, sourceRow));
|
|
14300
14404
|
case "CASE_COL":
|
|
14301
|
-
return containsAggregate2(column.expr) ? row
|
|
14405
|
+
return containsAggregate2(column.expr) ? getMaterializedSelectValue(row, columnIndex) ?? getMaterializedLookupValue(row, caseMaterializedKey(column.alias, columnIndex)) ?? getLegacyMaterializedValue(row, caseMaterializedKey(column.alias, columnIndex)) ?? "" : evalCaseWhen(
|
|
14302
14406
|
column.expr,
|
|
14303
|
-
|
|
14407
|
+
sourceRow,
|
|
14304
14408
|
context.resolveFieldType,
|
|
14305
14409
|
context.resolveFieldSemantics
|
|
14306
14410
|
);
|
|
@@ -14308,23 +14412,23 @@ function evaluateSelectColumnValue(column, row, columnIndex, context = {}) {
|
|
|
14308
14412
|
return evalGroupingRef(column.ref, row);
|
|
14309
14413
|
case "STRFUNC_COL": {
|
|
14310
14414
|
const source = stringFuncDefaultKey(column.expr);
|
|
14311
|
-
return hasAggregateInStringFuncExpr2(column.expr) ? row
|
|
14415
|
+
return hasAggregateInStringFuncExpr2(column.expr) ? getMaterializedSelectValue(row, columnIndex) ?? getMaterializedLookupValue(row, column.alias ?? source) ?? getMaterializedLookupValue(row, source) ?? getLegacyMaterializedValue(row, column.alias ?? source) ?? getLegacyMaterializedValue(row, source) ?? evalStringFunc(
|
|
14312
14416
|
column.expr,
|
|
14313
|
-
|
|
14417
|
+
sourceRow,
|
|
14314
14418
|
context.resolveFieldType,
|
|
14315
14419
|
context.resolveFieldSemantics
|
|
14316
14420
|
) : evalStringFunc(
|
|
14317
14421
|
column.expr,
|
|
14318
|
-
|
|
14422
|
+
sourceRow,
|
|
14319
14423
|
context.resolveFieldType,
|
|
14320
14424
|
context.resolveFieldSemantics
|
|
14321
14425
|
);
|
|
14322
14426
|
}
|
|
14323
14427
|
case "SCALAR_VALUE_COL": {
|
|
14324
14428
|
const source = scalarValueDefaultKey(column.expr);
|
|
14325
|
-
return scalarValueHasAggregate2(column.expr) ? row
|
|
14429
|
+
return scalarValueHasAggregate2(column.expr) ? getMaterializedSelectValue(row, columnIndex) ?? getMaterializedLookupValue(row, column.alias ?? source) ?? getMaterializedLookupValue(row, source) ?? getLegacyMaterializedValue(row, column.alias ?? source) ?? getLegacyMaterializedValue(row, source) ?? "" : String(evalScalarValueExpr(
|
|
14326
14430
|
column.expr,
|
|
14327
|
-
|
|
14431
|
+
sourceRow,
|
|
14328
14432
|
context.resolveFieldType,
|
|
14329
14433
|
context.resolveFieldSemantics
|
|
14330
14434
|
));
|
|
@@ -14332,7 +14436,7 @@ function evaluateSelectColumnValue(column, row, columnIndex, context = {}) {
|
|
|
14332
14436
|
case "SCALAR_SUBQUERY_COL":
|
|
14333
14437
|
return context.scalarCache?.get(columnIndex) ?? "";
|
|
14334
14438
|
case "WINDOW_COL":
|
|
14335
|
-
return row
|
|
14439
|
+
return getMaterializedSelectValue(row, columnIndex) ?? getMaterializedLookupValue(row, column.alias) ?? getLegacyMaterializedValue(row, column.alias) ?? "";
|
|
14336
14440
|
}
|
|
14337
14441
|
}
|
|
14338
14442
|
function buildDistinctTuple(columns, row, context = {}) {
|
|
@@ -16426,9 +16530,9 @@ function render(value) {
|
|
|
16426
16530
|
function buildImportRecordPayload(top, subtables, rowIdMode) {
|
|
16427
16531
|
const record = {};
|
|
16428
16532
|
for (const [code, value] of top) record[code] = { value };
|
|
16429
|
-
for (const [tableCode,
|
|
16533
|
+
for (const [tableCode, sourceRows2] of subtables) {
|
|
16430
16534
|
record[tableCode] = {
|
|
16431
|
-
value:
|
|
16535
|
+
value: sourceRows2.map((sourceRow) => ({
|
|
16432
16536
|
...rowIdMode === "PRESERVE" && sourceRow.rowId ? { id: sourceRow.rowId } : {},
|
|
16433
16537
|
value: Object.fromEntries([...sourceRow.values].map(([childCode, value]) => [childCode, { value }]))
|
|
16434
16538
|
}))
|
|
@@ -17991,7 +18095,7 @@ function canProveTotalWindowOrder(stmt, orderBy, resolveField2, context) {
|
|
|
17991
18095
|
}
|
|
17992
18096
|
function tieBreakAdvice(context, kind) {
|
|
17993
18097
|
if (context !== "DIRECT") {
|
|
17994
|
-
return "\u305D\u306E\u8868\u306E\u4E2D\u3067\u4E00\u610F\u306B\u306A\u308B\u5217\uFF08\u5143\u306E\u96C6\u7D04\u306E\u30AD\u30FC\u306A\u3069\uFF09\u3092 ORDER BY \u306B\u542B\u3081\u3066\u304F\u3060\u3055\u3044\u3002\u96C6\u7D04\u7D50\u679C\u306E\u5217\u306F\u4E00\u610F\u3067\u3082\u8A3C\u660E\u3067\u304D\u306A\u3044\u305F\u3081\u3001\u3059\u3067\u306B\u4E00\u610F\u306A\u5834\u5408\u3082\u3053\u306E\u8B66\u544A\u304C\u51FA\u307E\u3059\u3002";
|
|
18098
|
+
return "\u305D\u306E\u8868\u306E\u4E2D\u3067\u4E00\u610F\u306B\u306A\u308B\u5217\uFF08\u5143\u306E\u96C6\u7D04\u306E\u30AD\u30FC\u306A\u3069\uFF09\u3092 ORDER BY \u306B\u542B\u3081\u3066\u304F\u3060\u3055\u3044\u3002\u96C6\u7D04\u7D50\u679C\u306E\u5217\u306F\u4E00\u610F\u3067\u3082\u8A3C\u660E\u3067\u304D\u306A\u3044\u305F\u3081\u3001\u3059\u3067\u306B\u4E00\u610F\u306A\u5834\u5408\u3082\u3053\u306E\u8B66\u544A\u304C\u51FA\u307E\u3059\u3002\u5143\u306E\u96C6\u7D04\u306E\u30AD\u30FC\u3092\u3059\u3079\u3066 ORDER BY \u306B\u542B\u3081\u3066\u3044\u308B\u306A\u3089\u3001\u3053\u306E\u8B66\u544A\u306F\u7121\u8996\u3057\u3066\u69CB\u3044\u307E\u305B\u3093\u3002";
|
|
17995
18099
|
}
|
|
17996
18100
|
return kind === "RANGE" ? "ORDER BY \u306B\u30EC\u30B3\u30FC\u30C9\u756A\u53F7\u306A\u3069\u306E\u30BF\u30A4\u30D6\u30EC\u30FC\u30AF\u30AD\u30FC\u3092\u8DB3\u3057\u3066\u304F\u3060\u3055\u3044\u3002" : "\u30EC\u30B3\u30FC\u30C9\u756A\u53F7\u7B49\u3092 ORDER BY \u306B\u8FFD\u52A0\u3057\u3066\u304F\u3060\u3055\u3044\u3002";
|
|
17997
18101
|
}
|
|
@@ -20370,10 +20474,10 @@ async function tryFetchJoinRecordsBySourceKeys(stmt, join2, tables, client, maxR
|
|
|
20370
20474
|
} else {
|
|
20371
20475
|
return null;
|
|
20372
20476
|
}
|
|
20373
|
-
const
|
|
20374
|
-
if (!
|
|
20477
|
+
const sourceRows2 = tables.get(sourceAlias);
|
|
20478
|
+
if (!sourceRows2) return null;
|
|
20375
20479
|
const keys = /* @__PURE__ */ new Set();
|
|
20376
|
-
for (const row of
|
|
20480
|
+
for (const row of sourceRows2) {
|
|
20377
20481
|
const raw = row[sourceField]?.value;
|
|
20378
20482
|
const txt = toScalarText(raw).trim();
|
|
20379
20483
|
if (txt.length > 0) keys.add(txt);
|
|
@@ -21283,7 +21387,7 @@ async function materializeValidationCandidates(stmt, operation, client, options,
|
|
|
21283
21387
|
);
|
|
21284
21388
|
}
|
|
21285
21389
|
let rows;
|
|
21286
|
-
let
|
|
21390
|
+
let sourceRows2;
|
|
21287
21391
|
let sourcePresence;
|
|
21288
21392
|
let sourceRowErrors;
|
|
21289
21393
|
let evaluationTypes;
|
|
@@ -21304,7 +21408,7 @@ async function materializeValidationCandidates(stmt, operation, client, options,
|
|
|
21304
21408
|
throw customCheckParseError("CHECK \u4ED8\u304D DML \u30BD\u30FC\u30B9 SELECT \u306E\u51FA\u529B\u540D\u306F\u4E00\u610F\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059");
|
|
21305
21409
|
}
|
|
21306
21410
|
assertInsertCheckRefs(stmt, selectResult.columns);
|
|
21307
|
-
|
|
21411
|
+
sourceRows2 = selectResult.rows;
|
|
21308
21412
|
sourcePresence = selectResult.importPresence;
|
|
21309
21413
|
sourceRowErrors = selectResult.importRowErrors;
|
|
21310
21414
|
const meta = selectResult.columnMeta;
|
|
@@ -21325,7 +21429,7 @@ async function materializeValidationCandidates(stmt, operation, client, options,
|
|
|
21325
21429
|
)),
|
|
21326
21430
|
preErrors: [...sourceRowErrors?.[index] ?? []],
|
|
21327
21431
|
record: {},
|
|
21328
|
-
evaluationRow:
|
|
21432
|
+
evaluationRow: sourceRows2?.[index] ?? Object.fromEntries(
|
|
21329
21433
|
stmt.fields.map((field, i) => [field, renderValidationValue(values[i])])
|
|
21330
21434
|
),
|
|
21331
21435
|
evaluationFieldTypes: evaluationTypes
|
|
@@ -21621,7 +21725,7 @@ async function resolveUpdateFromMatchedRecords(stmt, from, client, options, cach
|
|
|
21621
21725
|
const checkScope = await resolveUpdateFromCheckScope(stmt, from, client, cacheContext, tempTables);
|
|
21622
21726
|
const sourceFields = [...new Set(stmt.assignments.filter((a) => a.value.type === "SOURCE_FIELD").map((a) => a.value.type === "SOURCE_FIELD" ? a.value.field : "").concat(checkScope.sourceFields))];
|
|
21623
21727
|
const requiredSourceFields = [.../* @__PURE__ */ new Set([from.joinKeyField, ...sourceFields])];
|
|
21624
|
-
const
|
|
21728
|
+
const sourceRows2 = await loadUpdateFromSourceRows(
|
|
21625
21729
|
from,
|
|
21626
21730
|
requiredSourceFields,
|
|
21627
21731
|
sourceFields,
|
|
@@ -21632,7 +21736,7 @@ async function resolveUpdateFromMatchedRecords(stmt, from, client, options, cach
|
|
|
21632
21736
|
);
|
|
21633
21737
|
const sourceByKey = /* @__PURE__ */ new Map();
|
|
21634
21738
|
const sourceQueryByKey = /* @__PURE__ */ new Map();
|
|
21635
|
-
for (const row of
|
|
21739
|
+
for (const row of sourceRows2) {
|
|
21636
21740
|
if (!Object.prototype.hasOwnProperty.call(row, from.joinKeyField)) {
|
|
21637
21741
|
throw new Error(`ArgumentError: UPDATE ... FROM source column ${from.joinKeyField} does not exist.`);
|
|
21638
21742
|
}
|