@rex0220/kintone-sql-tools 3.83.0 → 3.85.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
@@ -23465,6 +23465,11 @@ function walkDependency(node, context) {
23465
23465
  if (context.clause !== "SELECT" && ref.tableAlias === null) {
23466
23466
  const alias = resolveProjectedName(ref.field, context.aliases.keys());
23467
23467
  const targets = alias === void 0 ? [] : context.aliases.get(alias) ?? [];
23468
+ if (context.clause === "HAVING" && alias !== void 0 && targets.some((target) => target.type === "WINDOW_COL")) {
23469
+ throw new Error(
23470
+ `ArgumentError: HAVING \u304B\u3089\u306F\u540C\u3058 SELECT \u306E\u30A6\u30A3\u30F3\u30C9\u30A6\u95A2\u6570\u306E\u7D50\u679C\uFF08\u5225\u540D ${alias}\uFF09\u3092\u53C2\u7167\u3067\u304D\u307E\u305B\u3093\u3002HAVING \u306F\u30A6\u30A3\u30F3\u30C9\u30A6\u3088\u308A\u5148\u306B\u8A55\u4FA1\u3055\u308C\u307E\u3059\u3002WITH \u3067\u6BB5\u3092\u5206\u3051\u3001\u6B21\u306E\u6BB5\u306E WHERE \u3067\u7D5E\u3063\u3066\u304F\u3060\u3055\u3044 (reason=HAVING_WINDOW_ALIAS)`
23471
+ );
23472
+ }
23468
23473
  if (targets.length === 1 && alias !== void 0 && !context.resolvingAliases.has(alias)) {
23469
23474
  const resolvingAliases = new Set(context.resolvingAliases);
23470
23475
  resolvingAliases.add(alias);
@@ -23693,8 +23698,9 @@ function validateGroupingRefMembership(ref, resolve3, canonicalItems) {
23693
23698
  }
23694
23699
  function validateGroupingStatic(stmt) {
23695
23700
  const normalized = normalizeGroupingSpec(stmt);
23701
+ const projectedColumns = [...stmt.columns, ...stmt.hiddenWindows ?? []];
23696
23702
  const groupingRefs = [];
23697
- for (const column of stmt.columns) {
23703
+ for (const column of projectedColumns) {
23698
23704
  collectGroupingRefs(column, groupingRefs);
23699
23705
  }
23700
23706
  collectGroupingRefs(stmt.having, groupingRefs);
@@ -23702,7 +23708,7 @@ function validateGroupingStatic(stmt) {
23702
23708
  const forbiddenGroupingRefs = [];
23703
23709
  collectGroupingRefs(stmt.where, forbiddenGroupingRefs);
23704
23710
  collectGroupingRefs(stmt.joins, forbiddenGroupingRefs);
23705
- collectAggregateArgumentGroupingRefs(stmt.columns, forbiddenGroupingRefs);
23711
+ collectAggregateArgumentGroupingRefs(projectedColumns, forbiddenGroupingRefs);
23706
23712
  collectAggregateArgumentGroupingRefs(stmt.having, forbiddenGroupingRefs);
23707
23713
  if (forbiddenGroupingRefs.length > 0) {
23708
23714
  throw new Error(
@@ -23731,7 +23737,7 @@ function validateGroupingPlanning(stmt, resolve3, planningGuardHook = () => void
23731
23737
  validateGroupingStatic(stmt);
23732
23738
  const normalized = normalizeGroupingSpec(stmt);
23733
23739
  const groupingRefs = [];
23734
- for (const column of stmt.columns) {
23740
+ for (const column of [...stmt.columns, ...stmt.hiddenWindows ?? []]) {
23735
23741
  collectGroupingRefs(column, groupingRefs);
23736
23742
  }
23737
23743
  collectGroupingRefs(stmt.having, groupingRefs);
@@ -37734,7 +37740,7 @@ async function buildGroupingFieldResolver(stmt, client, cacheContext, materializ
37734
37740
  async function validateSelectGroupingPlanning(stmt, client, cacheContext, materializedTables) {
37735
37741
  resolvedGroupingSpecs.delete(stmt);
37736
37742
  const normalized = normalizeGroupingSpec(stmt);
37737
- const hasGroupingNodes = JSON.stringify(stmt.columns).includes('"GROUPING_') || JSON.stringify(stmt.orderBy).includes('"GROUPING_');
37743
+ const hasGroupingNodes = JSON.stringify(stmt.columns).includes('"GROUPING_') || JSON.stringify(stmt.hiddenWindows ?? []).includes('"GROUPING_') || JSON.stringify(stmt.orderBy).includes('"GROUPING_');
37738
37744
  if (normalized.type === "GROUPING_SETS" || hasGroupingNodes) {
37739
37745
  const resolver = await buildGroupingFieldResolver(stmt, client, cacheContext, materializedTables);
37740
37746
  const resolvedSpec = validateGroupingPlanning(