@rex0220/kintone-sql-tools 3.32.0 → 3.33.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 +83 -29
- package/dist-engine/index.cjs +9 -9
- package/dist-engine/index.mjs +9 -9
- package/dist-engine/ksql-engine.umd.js +9 -9
- package/dist-engine/meta/bundle-baseline.json +7 -7
- package/dist-engine/meta/cjs.json +7 -7
- package/dist-engine/meta/esm.json +7 -7
- package/dist-engine/meta/umd.json +7 -7
- package/dist-mcp/ksql-mcp.js +85 -31
- package/dist-mcpb/ksql-mcp.mcpb +0 -0
- package/package.json +1 -1
package/dist-cli/ksql.js
CHANGED
|
@@ -4260,6 +4260,15 @@ function containsStatisticalAggregate(value, seen = /* @__PURE__ */ new Set()) {
|
|
|
4260
4260
|
if (record.type === "FIELD" && typeof record.field === "string" && /^(STDDEV_POP|STDDEV_SAMP|VAR_POP|VAR_SAMP|MEDIAN|MODE)\(/i.test(record.field)) return true;
|
|
4261
4261
|
return Object.values(record).some((child) => Array.isArray(child) ? child.some((entry) => containsStatisticalAggregate(entry, seen)) : containsStatisticalAggregate(child, seen));
|
|
4262
4262
|
}
|
|
4263
|
+
function containsAggregate(value, seen = /* @__PURE__ */ new Set()) {
|
|
4264
|
+
if (value === null || typeof value !== "object") return false;
|
|
4265
|
+
if (seen.has(value)) return false;
|
|
4266
|
+
seen.add(value);
|
|
4267
|
+
const record = value;
|
|
4268
|
+
if ((record.type === "AGGREGATE" || record.type === "AGG_REF") && typeof record.func === "string" && !STATISTICAL_AGGREGATES.has(record.func)) return true;
|
|
4269
|
+
if (record.type === "FIELD" && typeof record.field === "string" && /^(COUNT|SUM|AVG|MIN|MAX|GROUP_CONCAT)\(/i.test(record.field)) return true;
|
|
4270
|
+
return Object.values(record).some((child) => Array.isArray(child) ? child.some((entry) => containsAggregate(entry, seen)) : containsAggregate(child, seen));
|
|
4271
|
+
}
|
|
4263
4272
|
function completeInputReasons(stmt) {
|
|
4264
4273
|
const reasons = /* @__PURE__ */ new Set();
|
|
4265
4274
|
if (isDmlType(stmt.type)) {
|
|
@@ -4289,6 +4298,7 @@ function completeInputReasons(stmt) {
|
|
|
4289
4298
|
break;
|
|
4290
4299
|
}
|
|
4291
4300
|
if (containsStatisticalAggregate(stmt)) reasons.add("STATISTICAL_AGGREGATE");
|
|
4301
|
+
if (containsAggregate(stmt)) reasons.add("AGGREGATE");
|
|
4292
4302
|
return reasons;
|
|
4293
4303
|
}
|
|
4294
4304
|
function requiresCompleteInput(stmt) {
|
|
@@ -4297,11 +4307,15 @@ function requiresCompleteInput(stmt) {
|
|
|
4297
4307
|
function unionCompleteInputReasons(stmt) {
|
|
4298
4308
|
const reasons = stmt.left.type === "SELECT" ? selectCompleteInputReasons(stmt.left) : unionCompleteInputReasons(stmt.left);
|
|
4299
4309
|
addReasons(reasons, selectCompleteInputReasons(stmt.right));
|
|
4310
|
+
if (!stmt.all) reasons.add("DISTINCT");
|
|
4300
4311
|
return reasons;
|
|
4301
4312
|
}
|
|
4302
4313
|
function selectCompleteInputReasons(stmt) {
|
|
4303
4314
|
const reasons = /* @__PURE__ */ new Set();
|
|
4304
|
-
|
|
4315
|
+
const grouping = normalizeGroupingSpec(stmt);
|
|
4316
|
+
if (grouping.type === "GROUPING_SETS") reasons.add("GROUPING_SETS");
|
|
4317
|
+
if (grouping.type === "PLAIN") reasons.add("GROUP_BY");
|
|
4318
|
+
if (stmt.distinct) reasons.add("DISTINCT");
|
|
4305
4319
|
if (stmt.orderBy.length > 0) reasons.add("LOCAL_ORDER");
|
|
4306
4320
|
for (const column of stmt.columns) {
|
|
4307
4321
|
if (column.type === "WINDOW_COL" && column.orderBy.length > 0) reasons.add("WINDOW_ORDER");
|
|
@@ -4313,6 +4327,7 @@ function selectCompleteInputReasons(stmt) {
|
|
|
4313
4327
|
addReasons(reasons, whereCompleteInputReasons(stmt.where));
|
|
4314
4328
|
addReasons(reasons, whereCompleteInputReasons(stmt.having));
|
|
4315
4329
|
if (containsStatisticalAggregate(stmt)) reasons.add("STATISTICAL_AGGREGATE");
|
|
4330
|
+
if (containsAggregate(stmt)) reasons.add("AGGREGATE");
|
|
4316
4331
|
return reasons;
|
|
4317
4332
|
}
|
|
4318
4333
|
function whereCompleteInputReasons(where) {
|
|
@@ -6505,19 +6520,19 @@ function collectNonAggregateFieldRefs(node, out) {
|
|
|
6505
6520
|
}
|
|
6506
6521
|
Object.values(value).forEach((item) => collectNonAggregateFieldRefs(item, out));
|
|
6507
6522
|
}
|
|
6508
|
-
function
|
|
6523
|
+
function containsAggregate2(node) {
|
|
6509
6524
|
if (node === null || typeof node !== "object") return false;
|
|
6510
|
-
if (Array.isArray(node)) return node.some(
|
|
6525
|
+
if (Array.isArray(node)) return node.some(containsAggregate2);
|
|
6511
6526
|
const value = node;
|
|
6512
6527
|
if (value["type"] === "AGG_REF" || value["type"] === "AGG_ARITH") return true;
|
|
6513
6528
|
if (value["type"] === "SELECT" || value["type"] === "SCALAR_SUBQUERY") return false;
|
|
6514
|
-
return Object.values(value).some(
|
|
6529
|
+
return Object.values(value).some(containsAggregate2);
|
|
6515
6530
|
}
|
|
6516
6531
|
function isAggregateMaterializedAlias(column) {
|
|
6517
6532
|
if (!("alias" in column) || column.alias === null) return false;
|
|
6518
6533
|
if (column.type === "AGGREGATE" || column.type === "ARITH_AGG_COL") return true;
|
|
6519
6534
|
if (column.type === "STRFUNC_COL" || column.type === "SCALAR_VALUE_COL") {
|
|
6520
|
-
return
|
|
6535
|
+
return containsAggregate2(column);
|
|
6521
6536
|
}
|
|
6522
6537
|
return false;
|
|
6523
6538
|
}
|
|
@@ -10893,8 +10908,9 @@ function getLastId(records) {
|
|
|
10893
10908
|
return Number.isFinite(id) ? id : 0;
|
|
10894
10909
|
}
|
|
10895
10910
|
var FetchAllLimitError = class extends Error {
|
|
10896
|
-
constructor(message) {
|
|
10911
|
+
constructor(message, completeInputWrapped = false) {
|
|
10897
10912
|
super(message);
|
|
10913
|
+
this.completeInputWrapped = completeInputWrapped;
|
|
10898
10914
|
this.name = "FetchAllLimitError";
|
|
10899
10915
|
}
|
|
10900
10916
|
};
|
|
@@ -12405,7 +12421,7 @@ function classifyPreGroupAlias(column) {
|
|
|
12405
12421
|
case "STRFUNC_COL":
|
|
12406
12422
|
case "SCALAR_VALUE_COL":
|
|
12407
12423
|
case "SCALAR_SUBQUERY_COL":
|
|
12408
|
-
return
|
|
12424
|
+
return containsAggregate2(column) || containsAggregateColumnNode(column) ? "AGGREGATE_DEPENDENT" : "SAFE";
|
|
12409
12425
|
}
|
|
12410
12426
|
}
|
|
12411
12427
|
var SUBTABLE_SYSTEM_COLUMNS = ["_pid", "_rid", "_idx"];
|
|
@@ -17064,11 +17080,21 @@ async function validateSelectGroupingPlanning(stmt, client, cacheContext, materi
|
|
|
17064
17080
|
}
|
|
17065
17081
|
function completeInputErrorPrefix(reasons) {
|
|
17066
17082
|
const reasonList = [...reasons].join(", ");
|
|
17067
|
-
const
|
|
17083
|
+
const aggregateSubjects = [
|
|
17084
|
+
["GROUPING_SETS", "\u5C0F\u8A08\u30FB\u7DCF\u8A08\u306E\u6B63\u3057\u3044\u7D50\u679C"],
|
|
17085
|
+
["STATISTICAL_AGGREGATE", "\u7D71\u8A08\u96C6\u7D04\u306E\u6B63\u3057\u3044\u7D50\u679C"],
|
|
17086
|
+
["AGGREGATE", "\u96C6\u8A08\u306E\u6B63\u3057\u3044\u7D50\u679C"],
|
|
17087
|
+
["GROUP_BY", "\u30B0\u30EB\u30FC\u30D7\u96C6\u8A08\u306E\u6B63\u3057\u3044\u7D50\u679C"],
|
|
17088
|
+
["DISTINCT", "DISTINCT \u306E\u6B63\u3057\u3044\u7D50\u679C"]
|
|
17089
|
+
];
|
|
17090
|
+
const hasAggregateReason = aggregateSubjects.some(([reason]) => reasons.has(reason));
|
|
17091
|
+
const hasOrderReason = reasons.has("LOCAL_ORDER") || reasons.has("WINDOW_ORDER");
|
|
17092
|
+
const legacySubject = reasons.size === 1 && reasons.has("STATISTICAL_AGGREGATE") ? "\u7D71\u8A08\u96C6\u7D04\u306E\u6B63\u3057\u3044\u7D50\u679C" : reasons.size === 1 && reasons.has("GROUPING_SETS") ? "\u5C0F\u8A08\u30FB\u7DCF\u8A08\u306E\u6B63\u3057\u3044\u7D50\u679C" : reasons.size === 1 && reasons.has("AGGREGATE") ? "\u96C6\u8A08\u306E\u6B63\u3057\u3044\u7D50\u679C" : reasons.size === 1 && reasons.has("GROUP_BY") ? "\u30B0\u30EB\u30FC\u30D7\u96C6\u8A08\u306E\u6B63\u3057\u3044\u7D50\u679C" : reasons.size === 1 && reasons.has("DISTINCT") ? "DISTINCT \u306E\u6B63\u3057\u3044\u7D50\u679C" : reasons.has("GROUPING_SETS") ? "\u30AF\u30A8\u30EA\u306E\u6B63\u3057\u3044\u7D50\u679C" : "ORDER BY\u306E\u6B63\u3057\u3044\u7D50\u679C";
|
|
17093
|
+
const subject = reasons.has("DML") || reasons.has("VALIDATE") ? legacySubject : hasAggregateReason && hasOrderReason ? "\u30AF\u30A8\u30EA\u306E\u6B63\u3057\u3044\u7D50\u679C" : hasAggregateReason ? aggregateSubjects.find(([reason]) => reasons.has(reason))[1] : "ORDER BY\u306E\u6B63\u3057\u3044\u7D50\u679C";
|
|
17068
17094
|
return `${subject}\u306B\u306F\u5B8C\u5168\u306A\u5019\u88DC\u96C6\u5408\u304C\u5FC5\u8981\u3067\u3059\u3002complete input reason: ${reasonList}\u3002`;
|
|
17069
17095
|
}
|
|
17070
17096
|
function buildCompleteInputPolicy(stmt, options, orderPlan) {
|
|
17071
|
-
const reasons = orderPlan?.kind === "CANONICAL_REST_TOP_N" || orderPlan?.kind === "KORDER_NATIVE" || orderPlan?.kind === "KORDER_CURSOR" ? completeInputReasons({ ...stmt, orderBy: [] }) : completeInputReasons(stmt);
|
|
17097
|
+
const reasons = stmt.type === "SELECT" && (orderPlan?.kind === "CANONICAL_REST_TOP_N" || orderPlan?.kind === "KORDER_NATIVE" || orderPlan?.kind === "KORDER_CURSOR") ? completeInputReasons({ ...stmt, orderBy: [] }) : completeInputReasons(stmt);
|
|
17072
17098
|
const truncateWasDisabled = reasons.size > 0 && options.onLimitReached === "truncate";
|
|
17073
17099
|
return {
|
|
17074
17100
|
reasons,
|
|
@@ -17077,9 +17103,10 @@ function buildCompleteInputPolicy(stmt, options, orderPlan) {
|
|
|
17077
17103
|
};
|
|
17078
17104
|
}
|
|
17079
17105
|
function throwCompleteInputError(policy, error) {
|
|
17080
|
-
if (policy.reasons.size > 0 && error instanceof FetchAllLimitError) {
|
|
17106
|
+
if (policy.reasons.size > 0 && error instanceof FetchAllLimitError && !error.completeInputWrapped) {
|
|
17081
17107
|
throw new FetchAllLimitError(
|
|
17082
|
-
completeInputErrorPrefix(policy.reasons) + (policy.truncateWasDisabled ? "onLimit=truncate\u306F\u4F7F\u7528\u3067\u304D\u307E\u305B\u3093\u3002" : "") + error.message
|
|
17108
|
+
completeInputErrorPrefix(policy.reasons) + (policy.truncateWasDisabled ? "onLimit=truncate\u306F\u4F7F\u7528\u3067\u304D\u307E\u305B\u3093\u3002" : "") + error.message,
|
|
17109
|
+
true
|
|
17083
17110
|
);
|
|
17084
17111
|
}
|
|
17085
17112
|
throw error;
|
|
@@ -18312,26 +18339,53 @@ async function executeFullScanSelect(stmt, client, options, cacheContext, cteCac
|
|
|
18312
18339
|
return { type: "SELECT", rows, columns, rowCount: rows.length, warnings: [...warnings] };
|
|
18313
18340
|
}
|
|
18314
18341
|
async function executeUnion(stmt, client, options, cacheContext, captureColumnMeta = false, forLibraryCapture = false) {
|
|
18315
|
-
const
|
|
18316
|
-
|
|
18317
|
-
|
|
18318
|
-
|
|
18319
|
-
|
|
18320
|
-
|
|
18321
|
-
|
|
18322
|
-
|
|
18323
|
-
|
|
18324
|
-
|
|
18342
|
+
const completePolicy = buildCompleteInputPolicy(stmt, options, null);
|
|
18343
|
+
return withCompleteInputPolicy(completePolicy, async () => {
|
|
18344
|
+
const effectiveOptions = completePolicy.effectiveOptions;
|
|
18345
|
+
const [leftResult, rightResult] = await Promise.all([
|
|
18346
|
+
stmt.left.type === "UNION" ? executeUnion(
|
|
18347
|
+
stmt.left,
|
|
18348
|
+
client,
|
|
18349
|
+
effectiveOptions,
|
|
18350
|
+
cacheContext,
|
|
18351
|
+
captureColumnMeta,
|
|
18352
|
+
forLibraryCapture
|
|
18353
|
+
) : executeSelect(
|
|
18354
|
+
stmt.left,
|
|
18355
|
+
client,
|
|
18356
|
+
effectiveOptions,
|
|
18357
|
+
cacheContext,
|
|
18358
|
+
void 0,
|
|
18359
|
+
captureColumnMeta,
|
|
18360
|
+
forLibraryCapture
|
|
18361
|
+
),
|
|
18362
|
+
executeSelect(
|
|
18363
|
+
stmt.right,
|
|
18364
|
+
client,
|
|
18365
|
+
effectiveOptions,
|
|
18366
|
+
cacheContext,
|
|
18367
|
+
void 0,
|
|
18368
|
+
captureColumnMeta,
|
|
18369
|
+
forLibraryCapture
|
|
18370
|
+
)
|
|
18371
|
+
]);
|
|
18372
|
+
const leftCols = leftResult.columns;
|
|
18373
|
+
const rightCols = rightResult.columns;
|
|
18374
|
+
const remappedRight = rightResult.rows.map((row) => {
|
|
18375
|
+
const mapped = {};
|
|
18376
|
+
leftCols.forEach((col, i) => {
|
|
18377
|
+
mapped[col] = row[rightCols[i] ?? col] ?? "";
|
|
18378
|
+
});
|
|
18379
|
+
return mapped;
|
|
18325
18380
|
});
|
|
18326
|
-
|
|
18381
|
+
const combined = [...leftResult.rows, ...remappedRight];
|
|
18382
|
+
const rows = stmt.all ? combined : deduplicateRows(combined, leftCols);
|
|
18383
|
+
const result = { type: "SELECT", rows, columns: leftCols, rowCount: rows.length };
|
|
18384
|
+
if (captureColumnMeta) {
|
|
18385
|
+
materializedMetaBySelectResult.set(result, mergeUnionColumnMeta(leftResult, rightResult));
|
|
18386
|
+
}
|
|
18387
|
+
return result;
|
|
18327
18388
|
});
|
|
18328
|
-
const combined = [...leftResult.rows, ...remappedRight];
|
|
18329
|
-
const rows = stmt.all ? combined : deduplicateRows(combined, leftCols);
|
|
18330
|
-
const result = { type: "SELECT", rows, columns: leftCols, rowCount: rows.length };
|
|
18331
|
-
if (captureColumnMeta) {
|
|
18332
|
-
materializedMetaBySelectResult.set(result, mergeUnionColumnMeta(leftResult, rightResult));
|
|
18333
|
-
}
|
|
18334
|
-
return result;
|
|
18335
18389
|
}
|
|
18336
18390
|
function deduplicateRows(rows, columns) {
|
|
18337
18391
|
const seen = /* @__PURE__ */ new Set();
|