@rex0220/kintone-sql-tools 3.50.0 → 3.52.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,49 @@ 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
+ }
17726
+ function tieBreakAdvice(context, kind) {
17727
+ if (context !== "DIRECT") {
17728
+ 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";
17729
+ }
17730
+ 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";
17731
+ }
17617
17732
  function collectDefaultRangeWindowWarnings(stmt, resolveField2, context) {
17618
- const canProveSinglePhysicalInput = context === "DIRECT" && stmt.joins.length === 0 && stmt.from.cteName === null && stmt.from.subtableCode == null;
17619
17733
  const warnings = [];
17620
17734
  for (const column of stmt.columns) {
17621
17735
  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;
17736
+ if (canProveTotalWindowOrder(stmt, column.orderBy, resolveField2, context)) continue;
17628
17737
  warnings.push(
17629
- `${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`
17738
+ `${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\u3001` + tieBreakAdvice(context, "RANGE")
17739
+ );
17740
+ }
17741
+ for (const column of stmt.columns) {
17742
+ if (column.type !== "WINDOW_COL" || column.windowKind !== "VALUE") continue;
17743
+ if (canProveTotalWindowOrder(stmt, column.orderBy, resolveField2, context)) continue;
17744
+ warnings.push(
17745
+ `${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` + tieBreakAdvice(context, "VALUE")
17630
17746
  );
17631
17747
  }
17632
17748
  return warnings;
17633
17749
  }
17634
17750
  function mergeSelectWarnings(result, additional) {
17635
17751
  if (additional.length === 0) return result;
17636
- return { ...result, warnings: [.../* @__PURE__ */ new Set([...result.warnings ?? [], ...additional])] };
17752
+ const merged = { ...result, warnings: [.../* @__PURE__ */ new Set([...result.warnings ?? [], ...additional])] };
17753
+ const meta = materializedMetaBySelectResult.get(result);
17754
+ if (meta) materializedMetaBySelectResult.set(merged, meta);
17755
+ return merged;
17637
17756
  }
17638
17757
  function selectCaseConditionsNeedFieldMetadata(stmt) {
17639
17758
  const visit = (value) => {
@@ -17654,9 +17773,9 @@ function buildHavingFieldSemanticsResolver(stmt, rowResolver) {
17654
17773
  else if (column.type === "ARITH_COL" || column.type === "ARITH_AGG_COL") {
17655
17774
  semantics = syntheticSemantics("number");
17656
17775
  } else if (column.type === "WINDOW_COL") {
17657
- if (column.windowKind !== "AGGREGATE" || column.aggFunc === "COUNT" || column.aggFunc === "SUM" || column.aggFunc === "AVG") {
17776
+ if (column.windowKind === void 0 || column.windowKind === "RANKING" || column.windowKind === "AGGREGATE" && (column.aggFunc === "COUNT" || column.aggFunc === "SUM" || column.aggFunc === "AVG")) {
17658
17777
  semantics = syntheticSemantics("number");
17659
- } else if (column.arg.type !== "WILDCARD") {
17778
+ } else if ((column.windowKind === "AGGREGATE" || column.windowKind === "VALUE") && column.arg.type !== "WILDCARD") {
17660
17779
  semantics = inferAggregateArgMeta(column.arg, (ref) => {
17661
17780
  const resolved = rowResolver(ref);
17662
17781
  return resolved ? {
@@ -17753,7 +17872,7 @@ async function executeSelect(stmt, client, options, cacheContext, cteCache, capt
17753
17872
  client,
17754
17873
  cacheContext,
17755
17874
  cteCache,
17756
- hasDefaultRangeAggregateWindow(stmt)
17875
+ hasWindowNeedingOrderProof(stmt)
17757
17876
  );
17758
17877
  const defaultRangeWarnings = collectDefaultRangeWindowWarnings(
17759
17878
  stmt,
@@ -18963,17 +19082,23 @@ function inferAggregateArgMeta(arg, resolveField2) {
18963
19082
  return mergeExpressionColumnMeta(results);
18964
19083
  }
18965
19084
  function inferWindowColumnMeta(column, resolveField2) {
18966
- if (column.windowKind !== "AGGREGATE" || column.aggFunc === "COUNT" || column.aggFunc === "SUM" || column.aggFunc === "AVG") {
18967
- return syntheticColumnMeta("number");
19085
+ if (column.windowKind === "VALUE") {
19086
+ return inferAggregateArgMeta(column.arg, resolveField2);
19087
+ }
19088
+ if (column.windowKind === "AGGREGATE") {
19089
+ if (column.aggFunc === "COUNT" || column.aggFunc === "SUM" || column.aggFunc === "AVG") {
19090
+ return syntheticColumnMeta("number");
19091
+ }
19092
+ return column.arg.type === "WILDCARD" ? unknownStringColumnMeta() : inferAggregateArgMeta(column.arg, resolveField2);
18968
19093
  }
18969
- return column.arg.type === "WILDCARD" ? unknownStringColumnMeta() : inferAggregateArgMeta(column.arg, resolveField2);
19094
+ return syntheticColumnMeta("number");
18970
19095
  }
18971
19096
  function withDisplayName(meta, displayName) {
18972
19097
  return { ...meta ?? {}, displayName };
18973
19098
  }
18974
19099
  function selectNeedsSourceColumnMeta(stmt) {
18975
19100
  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")
19101
+ (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
19102
  );
18978
19103
  }
18979
19104
  async function inferSelectColumnMeta(stmt, outputColumns, client, cacheContext, materializedTables, forLibraryCapture = false) {
@@ -19569,7 +19694,7 @@ async function executeFullScanWithCte(stmt, client, options, cteCache, cacheCont
19569
19694
  client,
19570
19695
  cacheContext,
19571
19696
  cteCache,
19572
- hasDefaultRangeAggregateWindow(stmt)
19697
+ hasWindowNeedingOrderProof(stmt)
19573
19698
  );
19574
19699
  const defaultRangeWarnings = collectDefaultRangeWindowWarnings(
19575
19700
  stmt,
@@ -24163,7 +24288,7 @@ function buildSelectPlan(stmt, label, capabilities, orderPlans, plainGroupByPlan
24163
24288
  }
24164
24289
  }
24165
24290
  for (const column of stmt.columns) {
24166
- if (column.type !== "WINDOW_COL" || column.windowKind !== "AGGREGATE") continue;
24291
+ if (column.type !== "WINDOW_COL" || column.windowKind === void 0 || column.windowKind === "RANKING") continue;
24167
24292
  const clauses = [];
24168
24293
  if (column.partitionBy.length > 0) {
24169
24294
  clauses.push(`PARTITION BY ${column.partitionBy.map(
@@ -24173,8 +24298,12 @@ function buildSelectPlan(stmt, label, capabilities, orderPlans, plainGroupByPlan
24173
24298
  if (column.orderBy.length > 0) {
24174
24299
  clauses.push(`ORDER BY ${column.orderBy.map(formatOrderByItem).join(", ")}`);
24175
24300
  }
24176
- lines.push(` window ${column.alias}: ${column.aggFunc} OVER (${clauses.join(" ")})`);
24177
- lines.push(column.frame === null ? " frame: PARTITION ENTIRE" : ` frame: ${column.frame.unit} UNBOUNDED PRECEDING AND CURRENT ROW${column.frame.source === "DEFAULT" ? " (\u65E2\u5B9A)" : ""}`);
24301
+ if (column.windowKind === "VALUE") {
24302
+ lines.push(` window ${column.alias}: ${column.valueFunc}(offset=${column.offset}) OVER (${clauses.join(" ")})`);
24303
+ } else if (column.windowKind === "AGGREGATE") {
24304
+ lines.push(` window ${column.alias}: ${column.aggFunc} OVER (${clauses.join(" ")})`);
24305
+ lines.push(column.frame === null ? " frame: PARTITION ENTIRE" : ` frame: ${column.frame.unit} UNBOUNDED PRECEDING AND CURRENT ROW${column.frame.source === "DEFAULT" ? " (\u65E2\u5B9A)" : ""}`);
24306
+ }
24178
24307
  }
24179
24308
  if (totalCountPlan) {
24180
24309
  const baseQuery = stmt.where === null ? "" : whereToKintone(stmt.where);