@rex0220/kintone-sql-tools 3.49.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 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 !== "AGGREGATE";
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 (!isRankingWindow(window)) {
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 !== "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");
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
- const hasTotalOrderKey = canProveSinglePhysicalInput && column.orderBy.some((item) => {
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
- return { ...result, warnings: [.../* @__PURE__ */ new Set([...result.warnings ?? [], ...additional])] };
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 !== "AGGREGATE" || column.aggFunc === "COUNT" || column.aggFunc === "SUM" || column.aggFunc === "AVG") {
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
- hasDefaultRangeAggregateWindow(stmt)
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 !== "AGGREGATE" || column.aggFunc === "COUNT" || column.aggFunc === "SUM" || column.aggFunc === "AVG") {
18967
- return syntheticColumnMeta("number");
19079
+ if (column.windowKind === "VALUE") {
19080
+ return inferAggregateArgMeta(column.arg, resolveField2);
18968
19081
  }
18969
- return column.arg.type === "WILDCARD" ? unknownStringColumnMeta() : inferAggregateArgMeta(column.arg, resolveField2);
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) {
@@ -19349,6 +19468,13 @@ async function executeFullScanSelect(stmt, client, options, cacheContext, cteCac
19349
19468
  );
19350
19469
  return { type: "SELECT", rows, columns, rowCount: rows.length, warnings: [...warnings] };
19351
19470
  }
19471
+ function assertUnionColumnCount(leftColumns, rightColumns) {
19472
+ if (leftColumns.length === rightColumns.length) return;
19473
+ throw new Error(
19474
+ `ArgumentError: UNION \u306E\u5DE6\u53F3\u3067\u5217\u6570\u304C\u4E00\u81F4\u3057\u307E\u305B\u3093\uFF08\u5DE6 ${leftColumns.length} \u5217 / \u53F3 ${rightColumns.length} \u5217\uFF09\u3002
19475
+ UNION \u306F\u5217\u3092\u4F4D\u7F6E\u3067\u5BFE\u5FDC\u3055\u305B\u308B\u305F\u3081\u3001\u4E21\u8FBA\u306E\u5217\u6570\u3092\u63C3\u3048\u3066\u304F\u3060\u3055\u3044`
19476
+ );
19477
+ }
19352
19478
  async function executeUnion(stmt, client, options, cacheContext, captureColumnMeta = false, forLibraryCapture = false) {
19353
19479
  const completePolicy = buildCompleteInputPolicy(stmt, options, null);
19354
19480
  return withCompleteInputPolicy(completePolicy, async () => {
@@ -19384,6 +19510,7 @@ async function executeUnion(stmt, client, options, cacheContext, captureColumnMe
19384
19510
  ]);
19385
19511
  const leftCols = leftResult.columns;
19386
19512
  const rightCols = rightResult.columns;
19513
+ assertUnionColumnCount(leftCols, rightCols);
19387
19514
  const remappedRight = rightResult.rows.map((row) => {
19388
19515
  const mapped = {};
19389
19516
  leftCols.forEach((col, i) => {
@@ -19471,6 +19598,7 @@ async function executeQueryWithCte(query, client, options, cteCache, cacheContex
19471
19598
  ]);
19472
19599
  const leftCols = leftResult.columns;
19473
19600
  const rightCols = rightResult.columns;
19601
+ assertUnionColumnCount(leftCols, rightCols);
19474
19602
  const remapped = rightResult.rows.map((row) => {
19475
19603
  const mapped = {};
19476
19604
  leftCols.forEach((col, i) => {
@@ -19560,7 +19688,7 @@ async function executeFullScanWithCte(stmt, client, options, cteCache, cacheCont
19560
19688
  client,
19561
19689
  cacheContext,
19562
19690
  cteCache,
19563
- hasDefaultRangeAggregateWindow(stmt)
19691
+ hasWindowNeedingOrderProof(stmt)
19564
19692
  );
19565
19693
  const defaultRangeWarnings = collectDefaultRangeWindowWarnings(
19566
19694
  stmt,
@@ -22990,9 +23118,23 @@ async function executeUpsertSelect(stmt, client, options, cacheContext, cteCache
22990
23118
  updatedCount: toUpdate.length
22991
23119
  };
22992
23120
  }
23121
+ var SHOW_APPS_COLUMNS = Object.freeze([
23122
+ "\u30A2\u30D7\u30EAID",
23123
+ "\u30A2\u30D7\u30EA\u540D",
23124
+ "\u8AAC\u660E"
23125
+ ]);
23126
+ var DESCRIBE_COLUMNS = Object.freeze([
23127
+ "\u30D5\u30A3\u30FC\u30EB\u30C9\u30B3\u30FC\u30C9",
23128
+ "\u30E9\u30D9\u30EB",
23129
+ "\u30BF\u30A4\u30D7",
23130
+ "\u30EB\u30C3\u30AF\u30A2\u30C3\u30D7",
23131
+ "\u30B3\u30D4\u30FC\u5143",
23132
+ "\u91CD\u8907\u7981\u6B62",
23133
+ "\u8A08\u7B97\u5F0F"
23134
+ ]);
22993
23135
  async function executeShowApps(client) {
22994
23136
  const apps = await client.getApps();
22995
- const columns = ["\u30A2\u30D7\u30EAID", "\u30A2\u30D7\u30EA\u540D", "\u8AAC\u660E"];
23137
+ const columns = [...SHOW_APPS_COLUMNS];
22996
23138
  const rows = apps.map((a) => ({
22997
23139
  "\u30A2\u30D7\u30EAID": String(a.appId),
22998
23140
  "\u30A2\u30D7\u30EA\u540D": a.name,
@@ -23002,15 +23144,7 @@ async function executeShowApps(client) {
23002
23144
  }
23003
23145
  async function executeDescribe(stmt, client, cacheContext) {
23004
23146
  const fields = await getFieldsCached(stmt.appId, client, cacheContext);
23005
- const columns = [
23006
- "\u30D5\u30A3\u30FC\u30EB\u30C9\u30B3\u30FC\u30C9",
23007
- "\u30E9\u30D9\u30EB",
23008
- "\u30BF\u30A4\u30D7",
23009
- "\u30EB\u30C3\u30AF\u30A2\u30C3\u30D7",
23010
- "\u30B3\u30D4\u30FC\u5143",
23011
- "\u91CD\u8907\u7981\u6B62",
23012
- "\u8A08\u7B97\u5F0F"
23013
- ];
23147
+ const columns = [...DESCRIBE_COLUMNS];
23014
23148
  const rows = fields.map((f) => ({
23015
23149
  "\u30D5\u30A3\u30FC\u30EB\u30C9\u30B3\u30FC\u30C9": f.code,
23016
23150
  "\u30E9\u30D9\u30EB": f.label,
@@ -24148,7 +24282,7 @@ function buildSelectPlan(stmt, label, capabilities, orderPlans, plainGroupByPlan
24148
24282
  }
24149
24283
  }
24150
24284
  for (const column of stmt.columns) {
24151
- if (column.type !== "WINDOW_COL" || column.windowKind !== "AGGREGATE") continue;
24285
+ if (column.type !== "WINDOW_COL" || column.windowKind === void 0 || column.windowKind === "RANKING") continue;
24152
24286
  const clauses = [];
24153
24287
  if (column.partitionBy.length > 0) {
24154
24288
  clauses.push(`PARTITION BY ${column.partitionBy.map(
@@ -24158,8 +24292,12 @@ function buildSelectPlan(stmt, label, capabilities, orderPlans, plainGroupByPlan
24158
24292
  if (column.orderBy.length > 0) {
24159
24293
  clauses.push(`ORDER BY ${column.orderBy.map(formatOrderByItem).join(", ")}`);
24160
24294
  }
24161
- lines.push(` window ${column.alias}: ${column.aggFunc} OVER (${clauses.join(" ")})`);
24162
- lines.push(column.frame === null ? " frame: PARTITION ENTIRE" : ` frame: ${column.frame.unit} UNBOUNDED PRECEDING AND CURRENT ROW${column.frame.source === "DEFAULT" ? " (\u65E2\u5B9A)" : ""}`);
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
+ }
24163
24301
  }
24164
24302
  if (totalCountPlan) {
24165
24303
  const baseQuery = stmt.where === null ? "" : whereToKintone(stmt.where);