@rex0220/kintone-sql-tools 3.50.0 → 3.51.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 +149 -26
- 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 +11 -11
- package/dist-engine/meta/esm.json +11 -11
- package/dist-engine/meta/umd.json +11 -11
- package/dist-mcp/ksql-mcp.js +152 -29
- package/dist-mcpb/ksql-mcp.mcpb +0 -0
- package/package.json +3 -2
package/dist-cli/ksql.js
CHANGED
|
@@ -578,7 +578,13 @@ function compareDecimal(left, right) {
|
|
|
578
578
|
// src/types/ast.ts
|
|
579
579
|
var NO_FROM_CTE_NAME = "__NO_FROM__";
|
|
580
580
|
function isRankingWindow(column) {
|
|
581
|
-
return column.windowKind
|
|
581
|
+
return column.windowKind === void 0 || column.windowKind === "RANKING";
|
|
582
|
+
}
|
|
583
|
+
function isAggregateWindow(column) {
|
|
584
|
+
return column.windowKind === "AGGREGATE";
|
|
585
|
+
}
|
|
586
|
+
function isValueWindow(column) {
|
|
587
|
+
return column.windowKind === "VALUE";
|
|
582
588
|
}
|
|
583
589
|
function makeNumberLiteral(raw) {
|
|
584
590
|
return { type: "NUMBER", value: Number(raw), raw };
|
|
@@ -1976,6 +1982,10 @@ var Parser = class {
|
|
|
1976
1982
|
const parsedAlias2 = this.consume("AS" /* AS */) ? this.parseAliasName() : null;
|
|
1977
1983
|
return this.withAliasDisplay({ type: "GROUPING_COL", ref, alias: parsedAlias2?.alias ?? null }, parsedAlias2);
|
|
1978
1984
|
}
|
|
1985
|
+
const valueWindowFunc = this.tryValueWindowFunc();
|
|
1986
|
+
if (valueWindowFunc !== null) {
|
|
1987
|
+
return this.parseValueWindowColumn(valueWindowFunc);
|
|
1988
|
+
}
|
|
1979
1989
|
if (this.tryAggregateFunc() === null && this.hasNestedAggregateWindowInSelectColumn()) {
|
|
1980
1990
|
throw new ParseError(
|
|
1981
1991
|
WINDOW_RESULT_IN_EXPRESSION_MESSAGE,
|
|
@@ -2086,6 +2096,22 @@ var Parser = class {
|
|
|
2086
2096
|
tryWindowFunc() {
|
|
2087
2097
|
return PARSER_WINDOW_FUNCTION_TOKEN_MAP[this.peek().kind] ?? null;
|
|
2088
2098
|
}
|
|
2099
|
+
tryValueWindowFunc(index = this.pos) {
|
|
2100
|
+
const token = this.tokens[index];
|
|
2101
|
+
if (token?.kind !== "IDENT" /* IDENT */ || this.tokens[index + 1]?.kind !== "(" /* LPAREN */) return null;
|
|
2102
|
+
const name = token.value.toUpperCase();
|
|
2103
|
+
if (name !== "LAG" && name !== "LEAD") return null;
|
|
2104
|
+
let depth = 0;
|
|
2105
|
+
for (let cursor = index + 1; cursor < this.tokens.length; cursor++) {
|
|
2106
|
+
const candidate = this.tokens[cursor];
|
|
2107
|
+
if (candidate.kind === "(" /* LPAREN */) depth++;
|
|
2108
|
+
else if (candidate.kind === ")" /* RPAREN */ && --depth === 0) {
|
|
2109
|
+
const next = this.tokens[cursor + 1];
|
|
2110
|
+
return next?.kind === "IDENT" /* IDENT */ && next.value.toUpperCase() === "OVER" ? name : null;
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
2113
|
+
return null;
|
|
2114
|
+
}
|
|
2089
2115
|
hasNestedAggregateWindowInSelectColumn() {
|
|
2090
2116
|
let depth = 0;
|
|
2091
2117
|
for (let index = this.pos; index < this.tokens.length; index++) {
|
|
@@ -2103,6 +2129,7 @@ var Parser = class {
|
|
|
2103
2129
|
}
|
|
2104
2130
|
}
|
|
2105
2131
|
}
|
|
2132
|
+
if (this.tryValueWindowFunc(index) !== null) return true;
|
|
2106
2133
|
if (token.kind === "(" /* LPAREN */) depth++;
|
|
2107
2134
|
else if (token.kind === ")" /* RPAREN */) depth--;
|
|
2108
2135
|
}
|
|
@@ -2134,6 +2161,54 @@ var Parser = class {
|
|
|
2134
2161
|
const parsedAlias = this.parseAliasName();
|
|
2135
2162
|
return this.withAliasDisplay({ type: "WINDOW_COL", func, partitionBy, orderBy, alias: parsedAlias.alias }, parsedAlias);
|
|
2136
2163
|
}
|
|
2164
|
+
parseValueWindowColumn(valueFunc) {
|
|
2165
|
+
this.advance();
|
|
2166
|
+
this.expect("(" /* LPAREN */);
|
|
2167
|
+
const arg = this.parseScalarValueExpr({ allowCase: true, allowAggregateArgs: false });
|
|
2168
|
+
let offset = 1;
|
|
2169
|
+
if (this.consume("," /* COMMA */)) {
|
|
2170
|
+
const token = this.expect("NUMBER" /* NUMBER */, `${valueFunc} \u306E offset \u306F\u975E\u8CA0\u306E\u6574\u6570\u30EA\u30C6\u30E9\u30EB\u3060\u3051\u3067\u3059`);
|
|
2171
|
+
offset = Number(token.value);
|
|
2172
|
+
if (!Number.isSafeInteger(offset) || offset < 0) {
|
|
2173
|
+
throw new ParseError(`${valueFunc} \u306E offset \u306F\u975E\u8CA0\u306E safe integer \u30EA\u30C6\u30E9\u30EB\u3060\u3051\u3067\u3059`, token);
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
this.expect(")" /* RPAREN */, `${valueFunc} \u306F expr \u3068\u7701\u7565\u53EF\u80FD\u306A offset \u306E 2 \u5F15\u6570\u307E\u3067\u3067\u3059`);
|
|
2177
|
+
this.expectSoftKeyword("OVER", `${valueFunc} \u306B\u306F OVER (...) \u304C\u5FC5\u8981\u3067\u3059`);
|
|
2178
|
+
this.expect("(" /* LPAREN */);
|
|
2179
|
+
const partitionBy = [];
|
|
2180
|
+
if (this.isSoftKeyword("PARTITION")) {
|
|
2181
|
+
this.advance();
|
|
2182
|
+
this.expect("BY" /* BY */, "PARTITION \u306E\u5F8C\u306B\u306F BY \u304C\u5FC5\u8981\u3067\u3059");
|
|
2183
|
+
do {
|
|
2184
|
+
const field = this.parseQualifiedIdent();
|
|
2185
|
+
partitionBy.push({ type: "FIELD", tableAlias: field.tableAlias, field: field.field });
|
|
2186
|
+
} while (this.consume("," /* COMMA */));
|
|
2187
|
+
}
|
|
2188
|
+
if (!this.consume("ORDER" /* ORDER */)) {
|
|
2189
|
+
throw new ParseError(`${valueFunc} \u306E OVER \u306B\u306F ORDER BY \u304C\u5FC5\u8981\u3067\u3059`, this.peek());
|
|
2190
|
+
}
|
|
2191
|
+
this.expect("BY" /* BY */);
|
|
2192
|
+
const orderBy = this.parseOrderBy(false);
|
|
2193
|
+
this.expect(")" /* RPAREN */);
|
|
2194
|
+
if (this.isArithOp(this.peek().kind) || this.peek().kind === "||" /* CONCAT_OP */) {
|
|
2195
|
+
throw new ParseError(WINDOW_RESULT_IN_EXPRESSION_MESSAGE, this.peek());
|
|
2196
|
+
}
|
|
2197
|
+
if (!this.consume("AS" /* AS */)) {
|
|
2198
|
+
throw new ParseError("\u30A6\u30A3\u30F3\u30C9\u30A6\u95A2\u6570\u306B\u306F AS alias \u304C\u5FC5\u8981\u3067\u3059", this.peek());
|
|
2199
|
+
}
|
|
2200
|
+
const parsedAlias = this.parseAliasName();
|
|
2201
|
+
return this.withAliasDisplay({
|
|
2202
|
+
type: "WINDOW_COL",
|
|
2203
|
+
windowKind: "VALUE",
|
|
2204
|
+
valueFunc,
|
|
2205
|
+
arg,
|
|
2206
|
+
offset,
|
|
2207
|
+
partitionBy,
|
|
2208
|
+
orderBy,
|
|
2209
|
+
alias: parsedAlias.alias
|
|
2210
|
+
}, parsedAlias);
|
|
2211
|
+
}
|
|
2137
2212
|
parseAggregateWindowColumn(ref) {
|
|
2138
2213
|
const supported = /* @__PURE__ */ new Set(["SUM", "COUNT", "AVG", "MIN", "MAX"]);
|
|
2139
2214
|
if (!supported.has(ref.func)) {
|
|
@@ -6343,7 +6418,7 @@ function collectRequiredFieldsByTable(stmt, plainGroupByPlan, sourceAware) {
|
|
|
6343
6418
|
case "SCALAR_SUBQUERY_COL":
|
|
6344
6419
|
break;
|
|
6345
6420
|
case "WINDOW_COL":
|
|
6346
|
-
if (col.windowKind === "AGGREGATE" && col.arg.type !== "WILDCARD") {
|
|
6421
|
+
if ((col.windowKind === "AGGREGATE" || col.windowKind === "VALUE") && col.arg.type !== "WILDCARD") {
|
|
6347
6422
|
walkAggregateArg(col.arg, "select");
|
|
6348
6423
|
}
|
|
6349
6424
|
for (const ref of col.partitionBy) addFieldRef(ref.field, ref.tableAlias, "select");
|
|
@@ -13835,10 +13910,17 @@ function applyWindow(rows, columns, optionOrders, sortKinds, fieldSemantics2, re
|
|
|
13835
13910
|
for (const partition of partitions.values()) {
|
|
13836
13911
|
const sortedResult = sortDecoratedRows(partition, window.orderBy, optionOrders, sortKinds, fieldSemantics2);
|
|
13837
13912
|
const sorted = sortedResult.rows;
|
|
13838
|
-
if (
|
|
13913
|
+
if (isAggregateWindow(window)) {
|
|
13839
13914
|
applyAggregateWindow(window, sortedResult, resolveAggSortKind);
|
|
13840
13915
|
continue;
|
|
13841
13916
|
}
|
|
13917
|
+
if (isValueWindow(window)) {
|
|
13918
|
+
applyValueWindow(window, sorted);
|
|
13919
|
+
continue;
|
|
13920
|
+
}
|
|
13921
|
+
if (!isRankingWindow(window)) {
|
|
13922
|
+
throw new Error(`InternalError: unknown window kind ${window.windowKind ?? "undefined"}`);
|
|
13923
|
+
}
|
|
13842
13924
|
let rank = 1;
|
|
13843
13925
|
let denseRank = 1;
|
|
13844
13926
|
for (let index = 0; index < sorted.length; index++) {
|
|
@@ -13853,6 +13935,20 @@ function applyWindow(rows, columns, optionOrders, sortKinds, fieldSemantics2, re
|
|
|
13853
13935
|
}
|
|
13854
13936
|
return rows;
|
|
13855
13937
|
}
|
|
13938
|
+
function evaluateValueWindowArg(arg, row) {
|
|
13939
|
+
const value = evalScalarValueExprNullable(arg, row);
|
|
13940
|
+
if (value === null || value === void 0) return "";
|
|
13941
|
+
if (typeof value === "number" && !Number.isFinite(value)) return "";
|
|
13942
|
+
return String(value);
|
|
13943
|
+
}
|
|
13944
|
+
function applyValueWindow(window, sorted) {
|
|
13945
|
+
const values = sorted.map((item) => evaluateValueWindowArg(window.arg, item.row));
|
|
13946
|
+
const direction = window.valueFunc === "LAG" ? -1 : 1;
|
|
13947
|
+
for (let index = 0; index < sorted.length; index++) {
|
|
13948
|
+
const target = index + direction * window.offset;
|
|
13949
|
+
sorted[index].row[window.alias] = target >= 0 && target < values.length ? values[target] : "";
|
|
13950
|
+
}
|
|
13951
|
+
}
|
|
13856
13952
|
function applyAggregateWindow(window, sortedResult, resolveAggSortKind) {
|
|
13857
13953
|
const sorted = sortedResult.rows;
|
|
13858
13954
|
const values = window.arg.type === "WILDCARD" ? null : aggregateRowValues(window.aggFunc, window.arg, sorted.map((item) => item.row));
|
|
@@ -14382,9 +14478,9 @@ function deriveOutputOrderSemantics(columns, resolveAggSortKind) {
|
|
|
14382
14478
|
if (column.type === "ARITH_COL" || column.type === "ARITH_AGG_COL") {
|
|
14383
14479
|
result.set(column.alias, syntheticSemantics("number"));
|
|
14384
14480
|
} else if (column.type === "WINDOW_COL") {
|
|
14385
|
-
if (isRankingWindow(column) || column.aggFunc === "COUNT" || column.aggFunc === "SUM" || column.aggFunc === "AVG") {
|
|
14481
|
+
if (isRankingWindow(column) || isAggregateWindow(column) && (column.aggFunc === "COUNT" || column.aggFunc === "SUM" || column.aggFunc === "AVG")) {
|
|
14386
14482
|
result.set(column.alias, syntheticSemantics("number"));
|
|
14387
|
-
} else if (column.arg.type !== "WILDCARD") {
|
|
14483
|
+
} else if ((isAggregateWindow(column) || isValueWindow(column)) && column.arg.type !== "WILDCARD") {
|
|
14388
14484
|
const semantics = resolveAggregateArgSemantics(column.arg, resolveAggSortKind) ?? "string";
|
|
14389
14485
|
result.set(column.alias, typeof semantics === "string" ? syntheticSemantics(semantics) : semantics);
|
|
14390
14486
|
}
|
|
@@ -16970,8 +17066,8 @@ async function executeBatchStatement(stmt, info, client, options, cacheContext,
|
|
|
16970
17066
|
tempTables
|
|
16971
17067
|
);
|
|
16972
17068
|
const first = resolvedStmt2.expr.query.columns[0];
|
|
16973
|
-
let numeric = first?.type === "ARITH_COL" || first?.type === "ARITH_AGG_COL" || first?.type === "WINDOW_COL" && (first.windowKind
|
|
16974
|
-
if (first?.type === "AGGREGATE" && first.func === "MODE" || first?.type === "WINDOW_COL" && first.windowKind === "AGGREGATE" && (first.aggFunc === "MIN" || first.aggFunc === "MAX")) {
|
|
17069
|
+
let numeric = first?.type === "ARITH_COL" || first?.type === "ARITH_AGG_COL" || first?.type === "WINDOW_COL" && (first.windowKind === void 0 || first.windowKind === "RANKING" || first.windowKind === "AGGREGATE" && (first.aggFunc === "COUNT" || first.aggFunc === "SUM" || first.aggFunc === "AVG")) || first?.type === "AGGREGATE" && (first.func === "COUNT" || first.func === "SUM" || first.func === "AVG" || first.func === "STDDEV_POP" || first.func === "STDDEV_SAMP" || first.func === "VAR_POP" || first.func === "VAR_SAMP" || first.func === "MEDIAN");
|
|
17070
|
+
if (first?.type === "AGGREGATE" && first.func === "MODE" || first?.type === "WINDOW_COL" && first.windowKind === "VALUE" || first?.type === "WINDOW_COL" && first.windowKind === "AGGREGATE" && (first.aggFunc === "MIN" || first.aggFunc === "MAX")) {
|
|
16975
17071
|
const meta = (await inferSelectColumnMeta(
|
|
16976
17072
|
resolvedStmt2.expr.query,
|
|
16977
17073
|
["__scalar__"],
|
|
@@ -17614,26 +17710,43 @@ function hasDefaultRangeAggregateWindow(stmt) {
|
|
|
17614
17710
|
(column) => column.type === "WINDOW_COL" && column.windowKind === "AGGREGATE" && column.orderBy.length > 0 && column.frame?.source === "DEFAULT"
|
|
17615
17711
|
);
|
|
17616
17712
|
}
|
|
17713
|
+
function hasWindowNeedingOrderProof(stmt) {
|
|
17714
|
+
return hasDefaultRangeAggregateWindow(stmt) || stmt.columns.some((column) => column.type === "WINDOW_COL" && column.windowKind === "VALUE");
|
|
17715
|
+
}
|
|
17716
|
+
function canProveTotalWindowOrder(stmt, orderBy, resolveField2, context) {
|
|
17717
|
+
if (context !== "DIRECT" || stmt.joins.length > 0 || stmt.from.cteName !== null || stmt.from.subtableCode != null) {
|
|
17718
|
+
return false;
|
|
17719
|
+
}
|
|
17720
|
+
return orderBy.some((item) => {
|
|
17721
|
+
if (item.key.type !== "FIELD_NAME") return false;
|
|
17722
|
+
const ref = aggregateFieldRef(item.key.name);
|
|
17723
|
+
return ref.field === "$id" || resolveField2(ref)?.fieldType === "RECORD_NUMBER";
|
|
17724
|
+
});
|
|
17725
|
+
}
|
|
17617
17726
|
function collectDefaultRangeWindowWarnings(stmt, resolveField2, context) {
|
|
17618
|
-
const canProveSinglePhysicalInput = context === "DIRECT" && stmt.joins.length === 0 && stmt.from.cteName === null && stmt.from.subtableCode == null;
|
|
17619
17727
|
const warnings = [];
|
|
17620
17728
|
for (const column of stmt.columns) {
|
|
17621
17729
|
if (column.type !== "WINDOW_COL" || column.windowKind !== "AGGREGATE" || column.orderBy.length === 0 || column.frame?.source !== "DEFAULT") continue;
|
|
17622
|
-
|
|
17623
|
-
if (item.key.type !== "FIELD_NAME") return false;
|
|
17624
|
-
const ref = aggregateFieldRef(item.key.name);
|
|
17625
|
-
return ref.field === "$id" || resolveField2(ref)?.fieldType === "RECORD_NUMBER";
|
|
17626
|
-
});
|
|
17627
|
-
if (hasTotalOrderKey) continue;
|
|
17730
|
+
if (canProveTotalWindowOrder(stmt, column.orderBy, resolveField2, context)) continue;
|
|
17628
17731
|
warnings.push(
|
|
17629
17732
|
`${column.alias} \u306F\u65E2\u5B9A\u30D5\u30EC\u30FC\u30E0\uFF08RANGE\uFF09\u3067\u8A55\u4FA1\u3055\u308C\u307E\u3059\u3002ORDER BY \u306E\u5024\u304C\u540C\u3058\u884C\u306F\u3059\u3079\u3066\u540C\u3058\u5024\u306B\u306A\u308A\u307E\u3059\u3002\u884C\u3054\u3068\u306E\u5024\u304C\u5FC5\u8981\u306A\u3089 ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW \u3092\u660E\u793A\u3059\u308B\u304B\u3001ORDER 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`
|
|
17630
17733
|
);
|
|
17631
17734
|
}
|
|
17735
|
+
for (const column of stmt.columns) {
|
|
17736
|
+
if (column.type !== "WINDOW_COL" || column.windowKind !== "VALUE") continue;
|
|
17737
|
+
if (canProveTotalWindowOrder(stmt, column.orderBy, resolveField2, context)) continue;
|
|
17738
|
+
warnings.push(
|
|
17739
|
+
`${column.alias} \u306E ORDER BY \u306F\u5168\u9806\u5E8F\u3067\u306A\u3044\u305F\u3081\u3001\u540C\u9806\u5185\u306E\u524D\u5F8C\u95A2\u4FC2\u306F\u672A\u898F\u5B9A\u3067\u3059\u3002\u30EC\u30B3\u30FC\u30C9\u756A\u53F7\u7B49\u3092 ORDER BY \u306B\u8FFD\u52A0\u3057\u3066\u304F\u3060\u3055\u3044\u3002`
|
|
17740
|
+
);
|
|
17741
|
+
}
|
|
17632
17742
|
return warnings;
|
|
17633
17743
|
}
|
|
17634
17744
|
function mergeSelectWarnings(result, additional) {
|
|
17635
17745
|
if (additional.length === 0) return result;
|
|
17636
|
-
|
|
17746
|
+
const merged = { ...result, warnings: [.../* @__PURE__ */ new Set([...result.warnings ?? [], ...additional])] };
|
|
17747
|
+
const meta = materializedMetaBySelectResult.get(result);
|
|
17748
|
+
if (meta) materializedMetaBySelectResult.set(merged, meta);
|
|
17749
|
+
return merged;
|
|
17637
17750
|
}
|
|
17638
17751
|
function selectCaseConditionsNeedFieldMetadata(stmt) {
|
|
17639
17752
|
const visit = (value) => {
|
|
@@ -17654,9 +17767,9 @@ function buildHavingFieldSemanticsResolver(stmt, rowResolver) {
|
|
|
17654
17767
|
else if (column.type === "ARITH_COL" || column.type === "ARITH_AGG_COL") {
|
|
17655
17768
|
semantics = syntheticSemantics("number");
|
|
17656
17769
|
} else if (column.type === "WINDOW_COL") {
|
|
17657
|
-
if (column.windowKind
|
|
17770
|
+
if (column.windowKind === void 0 || column.windowKind === "RANKING" || column.windowKind === "AGGREGATE" && (column.aggFunc === "COUNT" || column.aggFunc === "SUM" || column.aggFunc === "AVG")) {
|
|
17658
17771
|
semantics = syntheticSemantics("number");
|
|
17659
|
-
} else if (column.arg.type !== "WILDCARD") {
|
|
17772
|
+
} else if ((column.windowKind === "AGGREGATE" || column.windowKind === "VALUE") && column.arg.type !== "WILDCARD") {
|
|
17660
17773
|
semantics = inferAggregateArgMeta(column.arg, (ref) => {
|
|
17661
17774
|
const resolved = rowResolver(ref);
|
|
17662
17775
|
return resolved ? {
|
|
@@ -17753,7 +17866,7 @@ async function executeSelect(stmt, client, options, cacheContext, cteCache, capt
|
|
|
17753
17866
|
client,
|
|
17754
17867
|
cacheContext,
|
|
17755
17868
|
cteCache,
|
|
17756
|
-
|
|
17869
|
+
hasWindowNeedingOrderProof(stmt)
|
|
17757
17870
|
);
|
|
17758
17871
|
const defaultRangeWarnings = collectDefaultRangeWindowWarnings(
|
|
17759
17872
|
stmt,
|
|
@@ -18963,17 +19076,23 @@ function inferAggregateArgMeta(arg, resolveField2) {
|
|
|
18963
19076
|
return mergeExpressionColumnMeta(results);
|
|
18964
19077
|
}
|
|
18965
19078
|
function inferWindowColumnMeta(column, resolveField2) {
|
|
18966
|
-
if (column.windowKind
|
|
18967
|
-
return
|
|
19079
|
+
if (column.windowKind === "VALUE") {
|
|
19080
|
+
return inferAggregateArgMeta(column.arg, resolveField2);
|
|
18968
19081
|
}
|
|
18969
|
-
|
|
19082
|
+
if (column.windowKind === "AGGREGATE") {
|
|
19083
|
+
if (column.aggFunc === "COUNT" || column.aggFunc === "SUM" || column.aggFunc === "AVG") {
|
|
19084
|
+
return syntheticColumnMeta("number");
|
|
19085
|
+
}
|
|
19086
|
+
return column.arg.type === "WILDCARD" ? unknownStringColumnMeta() : inferAggregateArgMeta(column.arg, resolveField2);
|
|
19087
|
+
}
|
|
19088
|
+
return syntheticColumnMeta("number");
|
|
18970
19089
|
}
|
|
18971
19090
|
function withDisplayName(meta, displayName) {
|
|
18972
19091
|
return { ...meta ?? {}, displayName };
|
|
18973
19092
|
}
|
|
18974
19093
|
function selectNeedsSourceColumnMeta(stmt) {
|
|
18975
19094
|
return stmt.columns.some(
|
|
18976
|
-
(column) => column.type === "FIELD" || column.type === "WILDCARD" || column.type === "PARENT_WILDCARD" || column.type === "CASE_COL" || column.type === "AGGREGATE" && (column.func === "MIN" || column.func === "MAX" || column.func === "MODE") || column.type === "WINDOW_COL" && column.windowKind === "AGGREGATE" && (column.aggFunc === "MIN" || column.aggFunc === "MAX")
|
|
19095
|
+
(column) => column.type === "FIELD" || column.type === "WILDCARD" || column.type === "PARENT_WILDCARD" || column.type === "CASE_COL" || column.type === "AGGREGATE" && (column.func === "MIN" || column.func === "MAX" || column.func === "MODE") || column.type === "WINDOW_COL" && (column.windowKind === "VALUE" || column.windowKind === "AGGREGATE" && (column.aggFunc === "MIN" || column.aggFunc === "MAX"))
|
|
18977
19096
|
);
|
|
18978
19097
|
}
|
|
18979
19098
|
async function inferSelectColumnMeta(stmt, outputColumns, client, cacheContext, materializedTables, forLibraryCapture = false) {
|
|
@@ -19569,7 +19688,7 @@ async function executeFullScanWithCte(stmt, client, options, cteCache, cacheCont
|
|
|
19569
19688
|
client,
|
|
19570
19689
|
cacheContext,
|
|
19571
19690
|
cteCache,
|
|
19572
|
-
|
|
19691
|
+
hasWindowNeedingOrderProof(stmt)
|
|
19573
19692
|
);
|
|
19574
19693
|
const defaultRangeWarnings = collectDefaultRangeWindowWarnings(
|
|
19575
19694
|
stmt,
|
|
@@ -24163,7 +24282,7 @@ function buildSelectPlan(stmt, label, capabilities, orderPlans, plainGroupByPlan
|
|
|
24163
24282
|
}
|
|
24164
24283
|
}
|
|
24165
24284
|
for (const column of stmt.columns) {
|
|
24166
|
-
if (column.type !== "WINDOW_COL" || column.windowKind
|
|
24285
|
+
if (column.type !== "WINDOW_COL" || column.windowKind === void 0 || column.windowKind === "RANKING") continue;
|
|
24167
24286
|
const clauses = [];
|
|
24168
24287
|
if (column.partitionBy.length > 0) {
|
|
24169
24288
|
clauses.push(`PARTITION BY ${column.partitionBy.map(
|
|
@@ -24173,8 +24292,12 @@ function buildSelectPlan(stmt, label, capabilities, orderPlans, plainGroupByPlan
|
|
|
24173
24292
|
if (column.orderBy.length > 0) {
|
|
24174
24293
|
clauses.push(`ORDER BY ${column.orderBy.map(formatOrderByItem).join(", ")}`);
|
|
24175
24294
|
}
|
|
24176
|
-
|
|
24177
|
-
|
|
24295
|
+
if (column.windowKind === "VALUE") {
|
|
24296
|
+
lines.push(` window ${column.alias}: ${column.valueFunc}(offset=${column.offset}) OVER (${clauses.join(" ")})`);
|
|
24297
|
+
} else if (column.windowKind === "AGGREGATE") {
|
|
24298
|
+
lines.push(` window ${column.alias}: ${column.aggFunc} OVER (${clauses.join(" ")})`);
|
|
24299
|
+
lines.push(column.frame === null ? " frame: PARTITION ENTIRE" : ` frame: ${column.frame.unit} UNBOUNDED PRECEDING AND CURRENT ROW${column.frame.source === "DEFAULT" ? " (\u65E2\u5B9A)" : ""}`);
|
|
24300
|
+
}
|
|
24178
24301
|
}
|
|
24179
24302
|
if (totalCountPlan) {
|
|
24180
24303
|
const baseQuery = stmt.where === null ? "" : whereToKintone(stmt.where);
|