@rex0220/kintone-sql-tools 2.1.0 → 2.1.2
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 +66 -30
- package/dist-mcp/ksql-mcp.js +67 -31
- package/dist-mcpb/ksql-mcp.mcpb +0 -0
- package/package.json +1 -1
package/dist-cli/ksql.js
CHANGED
|
@@ -1033,14 +1033,20 @@ var Parser = class {
|
|
|
1033
1033
|
}
|
|
1034
1034
|
const aggFunc = this.tryAggregateFunc();
|
|
1035
1035
|
if (aggFunc !== null) {
|
|
1036
|
-
const
|
|
1036
|
+
const ref = this.parseAggregateRef(aggFunc);
|
|
1037
1037
|
if (this.isArithOp(this.peek().kind)) {
|
|
1038
|
-
const
|
|
1039
|
-
const
|
|
1040
|
-
|
|
1041
|
-
return { type: "ARITH_AGG_COL", expr, alias: alias2 };
|
|
1038
|
+
const expr = this.continueAggArith(ref);
|
|
1039
|
+
const alias3 = this.consume("AS" /* AS */) ? this.parseAliasName() : null;
|
|
1040
|
+
return { type: "ARITH_AGG_COL", expr, alias: alias3 };
|
|
1042
1041
|
}
|
|
1043
|
-
|
|
1042
|
+
const alias2 = this.consume("AS" /* AS */) ? this.parseAliasName() : null;
|
|
1043
|
+
return {
|
|
1044
|
+
type: "AGGREGATE",
|
|
1045
|
+
func: ref.func,
|
|
1046
|
+
distinct: ref.distinct,
|
|
1047
|
+
arg: ref.arg,
|
|
1048
|
+
alias: alias2
|
|
1049
|
+
};
|
|
1044
1050
|
}
|
|
1045
1051
|
if (this.peek().kind === "(" /* LPAREN */ && this.peekAt(1).kind === "SELECT" /* SELECT */) {
|
|
1046
1052
|
this.advance();
|
|
@@ -1124,8 +1130,7 @@ var Parser = class {
|
|
|
1124
1130
|
}
|
|
1125
1131
|
const aggFunc = this.tryAggregateFunc();
|
|
1126
1132
|
if (aggFunc !== null) {
|
|
1127
|
-
|
|
1128
|
-
return { type: "AGG_REF", func: aggCol.func, distinct: aggCol.distinct, arg: aggCol.arg };
|
|
1133
|
+
return this.parseAggregateRef(aggFunc);
|
|
1129
1134
|
}
|
|
1130
1135
|
throw new ParseError("\u96C6\u8A08\u7B97\u8853\u5F0F\u306B\u306F\u96C6\u8A08\u95A2\u6570\u307E\u305F\u306F\u6570\u5024\u304C\u5FC5\u8981\u3067\u3059", this.peek());
|
|
1131
1136
|
}
|
|
@@ -1416,7 +1421,8 @@ var Parser = class {
|
|
|
1416
1421
|
const kind = this.peek().kind;
|
|
1417
1422
|
return map[kind] ?? null;
|
|
1418
1423
|
}
|
|
1419
|
-
|
|
1424
|
+
/** 集計関数参照を読む。SELECT 列の alias は呼び出し側で式全体の後に処理する。 */
|
|
1425
|
+
parseAggregateRef(func) {
|
|
1420
1426
|
this.advance();
|
|
1421
1427
|
this.expect("(" /* LPAREN */);
|
|
1422
1428
|
const distinct = this.consume("DISTINCT" /* DISTINCT */);
|
|
@@ -1427,8 +1433,7 @@ var Parser = class {
|
|
|
1427
1433
|
arg = this.parseArithAddSub();
|
|
1428
1434
|
}
|
|
1429
1435
|
this.expect(")" /* RPAREN */);
|
|
1430
|
-
|
|
1431
|
-
return { type: "AGGREGATE", func, distinct, arg, alias };
|
|
1436
|
+
return { type: "AGG_REF", func, distinct, arg };
|
|
1432
1437
|
}
|
|
1433
1438
|
// ----------------------------------------------------------
|
|
1434
1439
|
// FROM / JOIN
|
|
@@ -4462,8 +4467,12 @@ function project(rows, columns, scalarCache) {
|
|
|
4462
4467
|
const cols = projected2.length > 0 ? Object.keys(projected2[0]) : [];
|
|
4463
4468
|
return { rows: projected2, columns: cols };
|
|
4464
4469
|
}
|
|
4465
|
-
const orderedKeys = [];
|
|
4466
4470
|
const defaultFieldKeys = buildDefaultFieldOutputKeys(columns);
|
|
4471
|
+
const hasWildcard = columns.some(
|
|
4472
|
+
(col) => col.type === "WILDCARD" || col.type === "PARENT_WILDCARD"
|
|
4473
|
+
);
|
|
4474
|
+
const outputKeys = hasWildcard ? null : computeOutputKeys(columns, defaultFieldKeys);
|
|
4475
|
+
const orderedKeys = outputKeys ?? [];
|
|
4467
4476
|
const projected = rows.map((row, rowIdx) => {
|
|
4468
4477
|
const out = {};
|
|
4469
4478
|
for (const [colIdx, col] of columns.entries()) {
|
|
@@ -4480,58 +4489,58 @@ function project(rows, columns, scalarCache) {
|
|
|
4480
4489
|
break;
|
|
4481
4490
|
}
|
|
4482
4491
|
case "FIELD": {
|
|
4483
|
-
const key = col.alias ?? defaultFieldKeys.get(colIdx) ?? col.field;
|
|
4492
|
+
const key = outputKeys?.[colIdx] ?? col.alias ?? defaultFieldKeys.get(colIdx) ?? col.field;
|
|
4484
4493
|
out[key] = resolveFieldRef(row, col.field);
|
|
4485
|
-
if (rowIdx === 0) orderedKeys.push(key);
|
|
4494
|
+
if (outputKeys === null && rowIdx === 0) orderedKeys.push(key);
|
|
4486
4495
|
break;
|
|
4487
4496
|
}
|
|
4488
4497
|
case "LITERAL_COL": {
|
|
4489
|
-
const key = col.alias ?? `'${col.value}'`;
|
|
4498
|
+
const key = outputKeys?.[colIdx] ?? col.alias ?? `'${col.value}'`;
|
|
4490
4499
|
out[key] = col.value;
|
|
4491
|
-
if (rowIdx === 0) orderedKeys.push(key);
|
|
4500
|
+
if (outputKeys === null && rowIdx === 0) orderedKeys.push(key);
|
|
4492
4501
|
break;
|
|
4493
4502
|
}
|
|
4494
4503
|
case "AGGREGATE": {
|
|
4495
4504
|
const srcKey = aggregateSyntheticName2(col.func, col.distinct, col.arg);
|
|
4496
|
-
const dstKey = col.alias ?? srcKey;
|
|
4505
|
+
const dstKey = outputKeys?.[colIdx] ?? col.alias ?? srcKey;
|
|
4497
4506
|
out[dstKey] = row[col.alias ?? srcKey] ?? row[srcKey] ?? "0";
|
|
4498
|
-
if (rowIdx === 0) orderedKeys.push(dstKey);
|
|
4507
|
+
if (outputKeys === null && rowIdx === 0) orderedKeys.push(dstKey);
|
|
4499
4508
|
break;
|
|
4500
4509
|
}
|
|
4501
4510
|
case "ARITH_AGG_COL": {
|
|
4502
|
-
const key = col.alias ?? aggArithDefaultKey(col.expr);
|
|
4511
|
+
const key = outputKeys?.[colIdx] ?? col.alias ?? aggArithDefaultKey(col.expr);
|
|
4503
4512
|
out[key] = row[key] ?? "0";
|
|
4504
|
-
if (rowIdx === 0) orderedKeys.push(key);
|
|
4513
|
+
if (outputKeys === null && rowIdx === 0) orderedKeys.push(key);
|
|
4505
4514
|
break;
|
|
4506
4515
|
}
|
|
4507
4516
|
case "ARITH_COL": {
|
|
4508
4517
|
const val = evalArithExpr(col.expr, row);
|
|
4509
|
-
const key = col.alias ?? arithColDefaultKey(col.expr);
|
|
4518
|
+
const key = outputKeys?.[colIdx] ?? col.alias ?? arithColDefaultKey(col.expr);
|
|
4510
4519
|
out[key] = String(val);
|
|
4511
|
-
if (rowIdx === 0) orderedKeys.push(key);
|
|
4520
|
+
if (outputKeys === null && rowIdx === 0) orderedKeys.push(key);
|
|
4512
4521
|
break;
|
|
4513
4522
|
}
|
|
4514
4523
|
case "CASE_COL": {
|
|
4515
|
-
const key = col.alias ?? "case";
|
|
4524
|
+
const key = outputKeys?.[colIdx] ?? col.alias ?? "case";
|
|
4516
4525
|
out[key] = evalCaseWhen(col.expr, row);
|
|
4517
|
-
if (rowIdx === 0) orderedKeys.push(key);
|
|
4526
|
+
if (outputKeys === null && rowIdx === 0) orderedKeys.push(key);
|
|
4518
4527
|
break;
|
|
4519
4528
|
}
|
|
4520
4529
|
case "STRFUNC_COL": {
|
|
4521
|
-
const key = col.alias ?? stringFuncDefaultKey(col.expr);
|
|
4530
|
+
const key = outputKeys?.[colIdx] ?? col.alias ?? stringFuncDefaultKey(col.expr);
|
|
4522
4531
|
if (hasAggregateInStringFuncExpr2(col.expr)) {
|
|
4523
4532
|
const srcKey = stringFuncDefaultKey(col.expr);
|
|
4524
4533
|
out[key] = row[col.alias ?? srcKey] ?? row[srcKey] ?? evalStringFunc(col.expr, row);
|
|
4525
4534
|
} else {
|
|
4526
4535
|
out[key] = evalStringFunc(col.expr, row);
|
|
4527
4536
|
}
|
|
4528
|
-
if (rowIdx === 0) orderedKeys.push(key);
|
|
4537
|
+
if (outputKeys === null && rowIdx === 0) orderedKeys.push(key);
|
|
4529
4538
|
break;
|
|
4530
4539
|
}
|
|
4531
4540
|
case "SCALAR_SUBQUERY_COL": {
|
|
4532
|
-
const key = col.alias ?? "(subquery)";
|
|
4541
|
+
const key = outputKeys?.[colIdx] ?? col.alias ?? "(subquery)";
|
|
4533
4542
|
out[key] = scalarCache?.get(colIdx) ?? "";
|
|
4534
|
-
if (rowIdx === 0) orderedKeys.push(key);
|
|
4543
|
+
if (outputKeys === null && rowIdx === 0) orderedKeys.push(key);
|
|
4535
4544
|
break;
|
|
4536
4545
|
}
|
|
4537
4546
|
}
|
|
@@ -4540,6 +4549,31 @@ function project(rows, columns, scalarCache) {
|
|
|
4540
4549
|
});
|
|
4541
4550
|
return { rows: projected, columns: orderedKeys };
|
|
4542
4551
|
}
|
|
4552
|
+
function computeOutputKeys(columns, defaultFieldKeys) {
|
|
4553
|
+
return columns.map((col, colIdx) => {
|
|
4554
|
+
switch (col.type) {
|
|
4555
|
+
case "FIELD":
|
|
4556
|
+
return col.alias ?? defaultFieldKeys.get(colIdx) ?? col.field;
|
|
4557
|
+
case "LITERAL_COL":
|
|
4558
|
+
return col.alias ?? `'${col.value}'`;
|
|
4559
|
+
case "AGGREGATE":
|
|
4560
|
+
return col.alias ?? aggregateSyntheticName2(col.func, col.distinct, col.arg);
|
|
4561
|
+
case "ARITH_AGG_COL":
|
|
4562
|
+
return col.alias ?? aggArithDefaultKey(col.expr);
|
|
4563
|
+
case "ARITH_COL":
|
|
4564
|
+
return col.alias ?? arithColDefaultKey(col.expr);
|
|
4565
|
+
case "CASE_COL":
|
|
4566
|
+
return col.alias ?? "case";
|
|
4567
|
+
case "STRFUNC_COL":
|
|
4568
|
+
return col.alias ?? stringFuncDefaultKey(col.expr);
|
|
4569
|
+
case "SCALAR_SUBQUERY_COL":
|
|
4570
|
+
return col.alias ?? "(subquery)";
|
|
4571
|
+
case "WILDCARD":
|
|
4572
|
+
case "PARENT_WILDCARD":
|
|
4573
|
+
throw new Error("internal: computeOutputKeys received a wildcard column");
|
|
4574
|
+
}
|
|
4575
|
+
});
|
|
4576
|
+
}
|
|
4543
4577
|
function buildDefaultFieldOutputKeys(columns) {
|
|
4544
4578
|
const qualifierCollisionCount = /* @__PURE__ */ new Map();
|
|
4545
4579
|
for (const col of columns) {
|
|
@@ -5930,8 +5964,9 @@ async function executeInsertSelect(stmt, client, options, cacheContext, cteCache
|
|
|
5930
5964
|
const selectResult = cteCache !== void 0 && cteCache.size > 0 ? await executeQueryWithCte(stmt.select, client, options, cteCache, cacheContext) : await executeSelect(stmt.select, client, options, cacheContext);
|
|
5931
5965
|
const { rows, columns } = selectResult;
|
|
5932
5966
|
if (columns.length !== stmt.fields.length) {
|
|
5967
|
+
const emptySourceHint = columns.length === 0 && rows.length === 0 ? "\u3002\u7D50\u679C\u304C 0 \u884C\u306E\u305F\u3081\u5217\u3092\u7279\u5B9A\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08SELECT * \u3092\u7A7A\u30BD\u30FC\u30B9\u306B\u4F7F\u3046\u3068\u5217\u3092\u6C7A\u5B9A\u3067\u304D\u307E\u305B\u3093\u3002\u660E\u793A\u5217\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\uFF09" : "";
|
|
5933
5968
|
throw new Error(
|
|
5934
|
-
`SELECT \u306E\u5217\u6570\uFF08${columns.length}\uFF09\u3068 INSERT \u306E\u30D5\u30A3\u30FC\u30EB\u30C9\u6570\uFF08${stmt.fields.length}\uFF09\u304C\u4E00\u81F4\u3057\u307E\u305B\u3093`
|
|
5969
|
+
`SELECT \u306E\u5217\u6570\uFF08${columns.length}\uFF09\u3068 INSERT \u306E\u30D5\u30A3\u30FC\u30EB\u30C9\u6570\uFF08${stmt.fields.length}\uFF09\u304C\u4E00\u81F4\u3057\u307E\u305B\u3093${emptySourceHint}`
|
|
5935
5970
|
);
|
|
5936
5971
|
}
|
|
5937
5972
|
if (options.confirm) {
|
|
@@ -6404,8 +6439,9 @@ async function executeUpsertSelect(stmt, client, options, cacheContext, cteCache
|
|
|
6404
6439
|
const selectResult = cteCache !== void 0 && cteCache.size > 0 ? await executeQueryWithCte(stmt.select, client, options, cteCache, cacheContext) : await executeSelect(stmt.select, client, options, cacheContext);
|
|
6405
6440
|
const { rows, columns } = selectResult;
|
|
6406
6441
|
if (columns.length !== stmt.fields.length) {
|
|
6442
|
+
const emptySourceHint = columns.length === 0 && rows.length === 0 ? "\u3002\u7D50\u679C\u304C 0 \u884C\u306E\u305F\u3081\u5217\u3092\u7279\u5B9A\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08SELECT * \u3092\u7A7A\u30BD\u30FC\u30B9\u306B\u4F7F\u3046\u3068\u5217\u3092\u6C7A\u5B9A\u3067\u304D\u307E\u305B\u3093\u3002\u660E\u793A\u5217\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\uFF09" : "";
|
|
6407
6443
|
throw new Error(
|
|
6408
|
-
`SELECT \u306E\u5217\u6570\uFF08${columns.length}\uFF09\u3068 UPSERT \u306E\u30D5\u30A3\u30FC\u30EB\u30C9\u6570\uFF08${stmt.fields.length}\uFF09\u304C\u4E00\u81F4\u3057\u307E\u305B\u3093`
|
|
6444
|
+
`SELECT \u306E\u5217\u6570\uFF08${columns.length}\uFF09\u3068 UPSERT \u306E\u30D5\u30A3\u30FC\u30EB\u30C9\u6570\uFF08${stmt.fields.length}\uFF09\u304C\u4E00\u81F4\u3057\u307E\u305B\u3093${emptySourceHint}`
|
|
6409
6445
|
);
|
|
6410
6446
|
}
|
|
6411
6447
|
for (const key of stmt.keyFields) {
|
package/dist-mcp/ksql-mcp.js
CHANGED
|
@@ -31946,14 +31946,20 @@ var Parser = class {
|
|
|
31946
31946
|
}
|
|
31947
31947
|
const aggFunc = this.tryAggregateFunc();
|
|
31948
31948
|
if (aggFunc !== null) {
|
|
31949
|
-
const
|
|
31949
|
+
const ref = this.parseAggregateRef(aggFunc);
|
|
31950
31950
|
if (this.isArithOp(this.peek().kind)) {
|
|
31951
|
-
const
|
|
31952
|
-
const
|
|
31953
|
-
|
|
31954
|
-
return { type: "ARITH_AGG_COL", expr, alias: alias2 };
|
|
31951
|
+
const expr = this.continueAggArith(ref);
|
|
31952
|
+
const alias3 = this.consume("AS" /* AS */) ? this.parseAliasName() : null;
|
|
31953
|
+
return { type: "ARITH_AGG_COL", expr, alias: alias3 };
|
|
31955
31954
|
}
|
|
31956
|
-
|
|
31955
|
+
const alias2 = this.consume("AS" /* AS */) ? this.parseAliasName() : null;
|
|
31956
|
+
return {
|
|
31957
|
+
type: "AGGREGATE",
|
|
31958
|
+
func: ref.func,
|
|
31959
|
+
distinct: ref.distinct,
|
|
31960
|
+
arg: ref.arg,
|
|
31961
|
+
alias: alias2
|
|
31962
|
+
};
|
|
31957
31963
|
}
|
|
31958
31964
|
if (this.peek().kind === "(" /* LPAREN */ && this.peekAt(1).kind === "SELECT" /* SELECT */) {
|
|
31959
31965
|
this.advance();
|
|
@@ -32037,8 +32043,7 @@ var Parser = class {
|
|
|
32037
32043
|
}
|
|
32038
32044
|
const aggFunc = this.tryAggregateFunc();
|
|
32039
32045
|
if (aggFunc !== null) {
|
|
32040
|
-
|
|
32041
|
-
return { type: "AGG_REF", func: aggCol.func, distinct: aggCol.distinct, arg: aggCol.arg };
|
|
32046
|
+
return this.parseAggregateRef(aggFunc);
|
|
32042
32047
|
}
|
|
32043
32048
|
throw new ParseError("\u96C6\u8A08\u7B97\u8853\u5F0F\u306B\u306F\u96C6\u8A08\u95A2\u6570\u307E\u305F\u306F\u6570\u5024\u304C\u5FC5\u8981\u3067\u3059", this.peek());
|
|
32044
32049
|
}
|
|
@@ -32329,7 +32334,8 @@ var Parser = class {
|
|
|
32329
32334
|
const kind = this.peek().kind;
|
|
32330
32335
|
return map2[kind] ?? null;
|
|
32331
32336
|
}
|
|
32332
|
-
|
|
32337
|
+
/** 集計関数参照を読む。SELECT 列の alias は呼び出し側で式全体の後に処理する。 */
|
|
32338
|
+
parseAggregateRef(func) {
|
|
32333
32339
|
this.advance();
|
|
32334
32340
|
this.expect("(" /* LPAREN */);
|
|
32335
32341
|
const distinct = this.consume("DISTINCT" /* DISTINCT */);
|
|
@@ -32340,8 +32346,7 @@ var Parser = class {
|
|
|
32340
32346
|
arg = this.parseArithAddSub();
|
|
32341
32347
|
}
|
|
32342
32348
|
this.expect(")" /* RPAREN */);
|
|
32343
|
-
|
|
32344
|
-
return { type: "AGGREGATE", func, distinct, arg, alias };
|
|
32349
|
+
return { type: "AGG_REF", func, distinct, arg };
|
|
32345
32350
|
}
|
|
32346
32351
|
// ----------------------------------------------------------
|
|
32347
32352
|
// FROM / JOIN
|
|
@@ -35363,8 +35368,12 @@ function project(rows, columns, scalarCache) {
|
|
|
35363
35368
|
const cols = projected2.length > 0 ? Object.keys(projected2[0]) : [];
|
|
35364
35369
|
return { rows: projected2, columns: cols };
|
|
35365
35370
|
}
|
|
35366
|
-
const orderedKeys = [];
|
|
35367
35371
|
const defaultFieldKeys = buildDefaultFieldOutputKeys(columns);
|
|
35372
|
+
const hasWildcard = columns.some(
|
|
35373
|
+
(col) => col.type === "WILDCARD" || col.type === "PARENT_WILDCARD"
|
|
35374
|
+
);
|
|
35375
|
+
const outputKeys = hasWildcard ? null : computeOutputKeys(columns, defaultFieldKeys);
|
|
35376
|
+
const orderedKeys = outputKeys ?? [];
|
|
35368
35377
|
const projected = rows.map((row, rowIdx) => {
|
|
35369
35378
|
const out = {};
|
|
35370
35379
|
for (const [colIdx, col] of columns.entries()) {
|
|
@@ -35381,58 +35390,58 @@ function project(rows, columns, scalarCache) {
|
|
|
35381
35390
|
break;
|
|
35382
35391
|
}
|
|
35383
35392
|
case "FIELD": {
|
|
35384
|
-
const key = col.alias ?? defaultFieldKeys.get(colIdx) ?? col.field;
|
|
35393
|
+
const key = outputKeys?.[colIdx] ?? col.alias ?? defaultFieldKeys.get(colIdx) ?? col.field;
|
|
35385
35394
|
out[key] = resolveFieldRef(row, col.field);
|
|
35386
|
-
if (rowIdx === 0) orderedKeys.push(key);
|
|
35395
|
+
if (outputKeys === null && rowIdx === 0) orderedKeys.push(key);
|
|
35387
35396
|
break;
|
|
35388
35397
|
}
|
|
35389
35398
|
case "LITERAL_COL": {
|
|
35390
|
-
const key = col.alias ?? `'${col.value}'`;
|
|
35399
|
+
const key = outputKeys?.[colIdx] ?? col.alias ?? `'${col.value}'`;
|
|
35391
35400
|
out[key] = col.value;
|
|
35392
|
-
if (rowIdx === 0) orderedKeys.push(key);
|
|
35401
|
+
if (outputKeys === null && rowIdx === 0) orderedKeys.push(key);
|
|
35393
35402
|
break;
|
|
35394
35403
|
}
|
|
35395
35404
|
case "AGGREGATE": {
|
|
35396
35405
|
const srcKey = aggregateSyntheticName2(col.func, col.distinct, col.arg);
|
|
35397
|
-
const dstKey = col.alias ?? srcKey;
|
|
35406
|
+
const dstKey = outputKeys?.[colIdx] ?? col.alias ?? srcKey;
|
|
35398
35407
|
out[dstKey] = row[col.alias ?? srcKey] ?? row[srcKey] ?? "0";
|
|
35399
|
-
if (rowIdx === 0) orderedKeys.push(dstKey);
|
|
35408
|
+
if (outputKeys === null && rowIdx === 0) orderedKeys.push(dstKey);
|
|
35400
35409
|
break;
|
|
35401
35410
|
}
|
|
35402
35411
|
case "ARITH_AGG_COL": {
|
|
35403
|
-
const key = col.alias ?? aggArithDefaultKey(col.expr);
|
|
35412
|
+
const key = outputKeys?.[colIdx] ?? col.alias ?? aggArithDefaultKey(col.expr);
|
|
35404
35413
|
out[key] = row[key] ?? "0";
|
|
35405
|
-
if (rowIdx === 0) orderedKeys.push(key);
|
|
35414
|
+
if (outputKeys === null && rowIdx === 0) orderedKeys.push(key);
|
|
35406
35415
|
break;
|
|
35407
35416
|
}
|
|
35408
35417
|
case "ARITH_COL": {
|
|
35409
35418
|
const val = evalArithExpr(col.expr, row);
|
|
35410
|
-
const key = col.alias ?? arithColDefaultKey(col.expr);
|
|
35419
|
+
const key = outputKeys?.[colIdx] ?? col.alias ?? arithColDefaultKey(col.expr);
|
|
35411
35420
|
out[key] = String(val);
|
|
35412
|
-
if (rowIdx === 0) orderedKeys.push(key);
|
|
35421
|
+
if (outputKeys === null && rowIdx === 0) orderedKeys.push(key);
|
|
35413
35422
|
break;
|
|
35414
35423
|
}
|
|
35415
35424
|
case "CASE_COL": {
|
|
35416
|
-
const key = col.alias ?? "case";
|
|
35425
|
+
const key = outputKeys?.[colIdx] ?? col.alias ?? "case";
|
|
35417
35426
|
out[key] = evalCaseWhen(col.expr, row);
|
|
35418
|
-
if (rowIdx === 0) orderedKeys.push(key);
|
|
35427
|
+
if (outputKeys === null && rowIdx === 0) orderedKeys.push(key);
|
|
35419
35428
|
break;
|
|
35420
35429
|
}
|
|
35421
35430
|
case "STRFUNC_COL": {
|
|
35422
|
-
const key = col.alias ?? stringFuncDefaultKey(col.expr);
|
|
35431
|
+
const key = outputKeys?.[colIdx] ?? col.alias ?? stringFuncDefaultKey(col.expr);
|
|
35423
35432
|
if (hasAggregateInStringFuncExpr2(col.expr)) {
|
|
35424
35433
|
const srcKey = stringFuncDefaultKey(col.expr);
|
|
35425
35434
|
out[key] = row[col.alias ?? srcKey] ?? row[srcKey] ?? evalStringFunc(col.expr, row);
|
|
35426
35435
|
} else {
|
|
35427
35436
|
out[key] = evalStringFunc(col.expr, row);
|
|
35428
35437
|
}
|
|
35429
|
-
if (rowIdx === 0) orderedKeys.push(key);
|
|
35438
|
+
if (outputKeys === null && rowIdx === 0) orderedKeys.push(key);
|
|
35430
35439
|
break;
|
|
35431
35440
|
}
|
|
35432
35441
|
case "SCALAR_SUBQUERY_COL": {
|
|
35433
|
-
const key = col.alias ?? "(subquery)";
|
|
35442
|
+
const key = outputKeys?.[colIdx] ?? col.alias ?? "(subquery)";
|
|
35434
35443
|
out[key] = scalarCache?.get(colIdx) ?? "";
|
|
35435
|
-
if (rowIdx === 0) orderedKeys.push(key);
|
|
35444
|
+
if (outputKeys === null && rowIdx === 0) orderedKeys.push(key);
|
|
35436
35445
|
break;
|
|
35437
35446
|
}
|
|
35438
35447
|
}
|
|
@@ -35441,6 +35450,31 @@ function project(rows, columns, scalarCache) {
|
|
|
35441
35450
|
});
|
|
35442
35451
|
return { rows: projected, columns: orderedKeys };
|
|
35443
35452
|
}
|
|
35453
|
+
function computeOutputKeys(columns, defaultFieldKeys) {
|
|
35454
|
+
return columns.map((col, colIdx) => {
|
|
35455
|
+
switch (col.type) {
|
|
35456
|
+
case "FIELD":
|
|
35457
|
+
return col.alias ?? defaultFieldKeys.get(colIdx) ?? col.field;
|
|
35458
|
+
case "LITERAL_COL":
|
|
35459
|
+
return col.alias ?? `'${col.value}'`;
|
|
35460
|
+
case "AGGREGATE":
|
|
35461
|
+
return col.alias ?? aggregateSyntheticName2(col.func, col.distinct, col.arg);
|
|
35462
|
+
case "ARITH_AGG_COL":
|
|
35463
|
+
return col.alias ?? aggArithDefaultKey(col.expr);
|
|
35464
|
+
case "ARITH_COL":
|
|
35465
|
+
return col.alias ?? arithColDefaultKey(col.expr);
|
|
35466
|
+
case "CASE_COL":
|
|
35467
|
+
return col.alias ?? "case";
|
|
35468
|
+
case "STRFUNC_COL":
|
|
35469
|
+
return col.alias ?? stringFuncDefaultKey(col.expr);
|
|
35470
|
+
case "SCALAR_SUBQUERY_COL":
|
|
35471
|
+
return col.alias ?? "(subquery)";
|
|
35472
|
+
case "WILDCARD":
|
|
35473
|
+
case "PARENT_WILDCARD":
|
|
35474
|
+
throw new Error("internal: computeOutputKeys received a wildcard column");
|
|
35475
|
+
}
|
|
35476
|
+
});
|
|
35477
|
+
}
|
|
35444
35478
|
function buildDefaultFieldOutputKeys(columns) {
|
|
35445
35479
|
const qualifierCollisionCount = /* @__PURE__ */ new Map();
|
|
35446
35480
|
for (const col of columns) {
|
|
@@ -36831,8 +36865,9 @@ async function executeInsertSelect(stmt, client, options, cacheContext, cteCache
|
|
|
36831
36865
|
const selectResult = cteCache !== void 0 && cteCache.size > 0 ? await executeQueryWithCte(stmt.select, client, options, cteCache, cacheContext) : await executeSelect(stmt.select, client, options, cacheContext);
|
|
36832
36866
|
const { rows, columns } = selectResult;
|
|
36833
36867
|
if (columns.length !== stmt.fields.length) {
|
|
36868
|
+
const emptySourceHint = columns.length === 0 && rows.length === 0 ? "\u3002\u7D50\u679C\u304C 0 \u884C\u306E\u305F\u3081\u5217\u3092\u7279\u5B9A\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08SELECT * \u3092\u7A7A\u30BD\u30FC\u30B9\u306B\u4F7F\u3046\u3068\u5217\u3092\u6C7A\u5B9A\u3067\u304D\u307E\u305B\u3093\u3002\u660E\u793A\u5217\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\uFF09" : "";
|
|
36834
36869
|
throw new Error(
|
|
36835
|
-
`SELECT \u306E\u5217\u6570\uFF08${columns.length}\uFF09\u3068 INSERT \u306E\u30D5\u30A3\u30FC\u30EB\u30C9\u6570\uFF08${stmt.fields.length}\uFF09\u304C\u4E00\u81F4\u3057\u307E\u305B\u3093`
|
|
36870
|
+
`SELECT \u306E\u5217\u6570\uFF08${columns.length}\uFF09\u3068 INSERT \u306E\u30D5\u30A3\u30FC\u30EB\u30C9\u6570\uFF08${stmt.fields.length}\uFF09\u304C\u4E00\u81F4\u3057\u307E\u305B\u3093${emptySourceHint}`
|
|
36836
36871
|
);
|
|
36837
36872
|
}
|
|
36838
36873
|
if (options.confirm) {
|
|
@@ -37305,8 +37340,9 @@ async function executeUpsertSelect(stmt, client, options, cacheContext, cteCache
|
|
|
37305
37340
|
const selectResult = cteCache !== void 0 && cteCache.size > 0 ? await executeQueryWithCte(stmt.select, client, options, cteCache, cacheContext) : await executeSelect(stmt.select, client, options, cacheContext);
|
|
37306
37341
|
const { rows, columns } = selectResult;
|
|
37307
37342
|
if (columns.length !== stmt.fields.length) {
|
|
37343
|
+
const emptySourceHint = columns.length === 0 && rows.length === 0 ? "\u3002\u7D50\u679C\u304C 0 \u884C\u306E\u305F\u3081\u5217\u3092\u7279\u5B9A\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08SELECT * \u3092\u7A7A\u30BD\u30FC\u30B9\u306B\u4F7F\u3046\u3068\u5217\u3092\u6C7A\u5B9A\u3067\u304D\u307E\u305B\u3093\u3002\u660E\u793A\u5217\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\uFF09" : "";
|
|
37308
37344
|
throw new Error(
|
|
37309
|
-
`SELECT \u306E\u5217\u6570\uFF08${columns.length}\uFF09\u3068 UPSERT \u306E\u30D5\u30A3\u30FC\u30EB\u30C9\u6570\uFF08${stmt.fields.length}\uFF09\u304C\u4E00\u81F4\u3057\u307E\u305B\u3093`
|
|
37345
|
+
`SELECT \u306E\u5217\u6570\uFF08${columns.length}\uFF09\u3068 UPSERT \u306E\u30D5\u30A3\u30FC\u30EB\u30C9\u6570\uFF08${stmt.fields.length}\uFF09\u304C\u4E00\u81F4\u3057\u307E\u305B\u3093${emptySourceHint}`
|
|
37310
37346
|
);
|
|
37311
37347
|
}
|
|
37312
37348
|
for (const key of stmt.keyFields) {
|
|
@@ -39946,7 +39982,7 @@ Options:
|
|
|
39946
39982
|
-h, --help Show help
|
|
39947
39983
|
`);
|
|
39948
39984
|
}
|
|
39949
|
-
var SERVER_VERSION = true ? "2.1.
|
|
39985
|
+
var SERVER_VERSION = true ? "2.1.2" : "0.0.0-dev";
|
|
39950
39986
|
function createServer(args) {
|
|
39951
39987
|
const server = new McpServer({
|
|
39952
39988
|
name: "ksql-mcp",
|
package/dist-mcpb/ksql-mcp.mcpb
CHANGED
|
Binary file
|