sof-mssql 2.1.0 → 2.2.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/queryGenerator/index.d.ts +0 -4
- package/dist/queryGenerator/index.d.ts.map +1 -1
- package/dist/queryGenerator/index.js +1 -9
- package/dist/queryGenerator/index.js.map +1 -1
- package/dist/queryGenerator/treeWalker/aliasGenerator.d.ts +26 -0
- package/dist/queryGenerator/treeWalker/aliasGenerator.d.ts.map +1 -0
- package/dist/queryGenerator/treeWalker/aliasGenerator.js +31 -0
- package/dist/queryGenerator/treeWalker/aliasGenerator.js.map +1 -0
- package/dist/queryGenerator/treeWalker/classify.d.ts +19 -0
- package/dist/queryGenerator/treeWalker/classify.d.ts.map +1 -0
- package/dist/queryGenerator/treeWalker/classify.js +36 -0
- package/dist/queryGenerator/treeWalker/classify.js.map +1 -0
- package/dist/queryGenerator/treeWalker/compile.d.ts +29 -0
- package/dist/queryGenerator/treeWalker/compile.d.ts.map +1 -0
- package/dist/queryGenerator/treeWalker/compile.js +98 -0
- package/dist/queryGenerator/treeWalker/compile.js.map +1 -0
- package/dist/queryGenerator/treeWalker/cteTemplates.d.ts +50 -0
- package/dist/queryGenerator/treeWalker/cteTemplates.d.ts.map +1 -0
- package/dist/queryGenerator/treeWalker/cteTemplates.js +95 -0
- package/dist/queryGenerator/treeWalker/cteTemplates.js.map +1 -0
- package/dist/queryGenerator/treeWalker/index.d.ts +6 -0
- package/dist/queryGenerator/treeWalker/index.d.ts.map +1 -0
- package/dist/queryGenerator/treeWalker/index.js +9 -0
- package/dist/queryGenerator/treeWalker/index.js.map +1 -0
- package/dist/queryGenerator/treeWalker/mergeSiblings.d.ts +28 -0
- package/dist/queryGenerator/treeWalker/mergeSiblings.d.ts.map +1 -0
- package/dist/queryGenerator/treeWalker/mergeSiblings.js +54 -0
- package/dist/queryGenerator/treeWalker/mergeSiblings.js.map +1 -0
- package/dist/queryGenerator/treeWalker/operators/columnsOnly.d.ts +40 -0
- package/dist/queryGenerator/treeWalker/operators/columnsOnly.d.ts.map +1 -0
- package/dist/queryGenerator/treeWalker/operators/columnsOnly.js +56 -0
- package/dist/queryGenerator/treeWalker/operators/columnsOnly.js.map +1 -0
- package/dist/queryGenerator/treeWalker/operators/forEach.d.ts +45 -0
- package/dist/queryGenerator/treeWalker/operators/forEach.d.ts.map +1 -0
- package/dist/queryGenerator/treeWalker/operators/forEach.js +144 -0
- package/dist/queryGenerator/treeWalker/operators/forEach.js.map +1 -0
- package/dist/queryGenerator/treeWalker/operators/group.d.ts +35 -0
- package/dist/queryGenerator/treeWalker/operators/group.d.ts.map +1 -0
- package/dist/queryGenerator/treeWalker/operators/group.js +56 -0
- package/dist/queryGenerator/treeWalker/operators/group.js.map +1 -0
- package/dist/queryGenerator/treeWalker/operators/repeat.d.ts +45 -0
- package/dist/queryGenerator/treeWalker/operators/repeat.d.ts.map +1 -0
- package/dist/queryGenerator/treeWalker/operators/repeat.js +110 -0
- package/dist/queryGenerator/treeWalker/operators/repeat.js.map +1 -0
- package/dist/queryGenerator/treeWalker/operators/unionAll.d.ts +54 -0
- package/dist/queryGenerator/treeWalker/operators/unionAll.d.ts.map +1 -0
- package/dist/queryGenerator/treeWalker/operators/unionAll.js +121 -0
- package/dist/queryGenerator/treeWalker/operators/unionAll.js.map +1 -0
- package/dist/queryGenerator/treeWalker/render.d.ts +34 -0
- package/dist/queryGenerator/treeWalker/render.d.ts.map +1 -0
- package/dist/queryGenerator/treeWalker/render.js +41 -0
- package/dist/queryGenerator/treeWalker/render.js.map +1 -0
- package/dist/queryGenerator/treeWalker/types.d.ts +66 -0
- package/dist/queryGenerator/treeWalker/types.d.ts.map +1 -0
- package/dist/queryGenerator/treeWalker/types.js +14 -0
- package/dist/queryGenerator/treeWalker/types.js.map +1 -0
- package/dist/queryGenerator/treeWalker/walker.d.ts +36 -0
- package/dist/queryGenerator/treeWalker/walker.d.ts.map +1 -0
- package/dist/queryGenerator/treeWalker/walker.js +58 -0
- package/dist/queryGenerator/treeWalker/walker.js.map +1 -0
- package/dist/queryGenerator.d.ts +8 -94
- package/dist/queryGenerator.d.ts.map +1 -1
- package/dist/queryGenerator.js +16 -268
- package/dist/queryGenerator.js.map +1 -1
- package/package.json +1 -1
- package/dist/queryGenerator/ForEachProcessor.d.ts +0 -127
- package/dist/queryGenerator/ForEachProcessor.d.ts.map +0 -1
- package/dist/queryGenerator/ForEachProcessor.js +0 -351
- package/dist/queryGenerator/ForEachProcessor.js.map +0 -1
- package/dist/queryGenerator/RepeatProcessor.d.ts +0 -177
- package/dist/queryGenerator/RepeatProcessor.d.ts.map +0 -1
- package/dist/queryGenerator/RepeatProcessor.js +0 -336
- package/dist/queryGenerator/RepeatProcessor.js.map +0 -1
- package/dist/queryGenerator/SelectClauseBuilder.d.ts +0 -108
- package/dist/queryGenerator/SelectClauseBuilder.d.ts.map +0 -1
- package/dist/queryGenerator/SelectClauseBuilder.js +0 -346
- package/dist/queryGenerator/SelectClauseBuilder.js.map +0 -1
- package/dist/queryGenerator/SelectCombinationExpander.d.ts +0 -42
- package/dist/queryGenerator/SelectCombinationExpander.d.ts.map +0 -1
- package/dist/queryGenerator/SelectCombinationExpander.js +0 -95
- package/dist/queryGenerator/SelectCombinationExpander.js.map +0 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Walker for ColumnsOnly nodes — emits the projected columns for the
|
|
4
|
+
* select.column[] array using the current transpiler context.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.projectColumns = projectColumns;
|
|
8
|
+
exports.walkColumnsOnly = walkColumnsOnly;
|
|
9
|
+
/**
|
|
10
|
+
* Projects an array of ViewDefinition column descriptors into SQL expressions.
|
|
11
|
+
*
|
|
12
|
+
* Delegates expression generation to `ColumnExpressionGenerator`, which
|
|
13
|
+
* translates each column's FHIRPath expression into a T-SQL expression
|
|
14
|
+
* relative to the current transpiler context (iteration source, aliases, etc.).
|
|
15
|
+
*
|
|
16
|
+
* @param columns - The column descriptors from the ViewDefinition select node.
|
|
17
|
+
* @param ctx - The current walker context supplying the transpiler context
|
|
18
|
+
* used for FHIRPath-to-SQL translation.
|
|
19
|
+
* @param columnGenerator - The generator that converts each column descriptor
|
|
20
|
+
* into its SQL expression string.
|
|
21
|
+
* @returns An ordered array of `ProjectedColumn` objects, each pairing the
|
|
22
|
+
* column's logical name with its SQL expression.
|
|
23
|
+
*/
|
|
24
|
+
function projectColumns(columns, ctx, columnGenerator) {
|
|
25
|
+
return columns.map((column) => ({
|
|
26
|
+
name: column.name,
|
|
27
|
+
sqlExpr: columnGenerator.generateExpression(column, ctx.transpilerCtx),
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Walker for ColumnsOnly nodes — emits the projected columns for a leaf select node.
|
|
32
|
+
*
|
|
33
|
+
* Produces a Fragment with no CTEs, no FROM extensions, and columns derived
|
|
34
|
+
* from `node.column[]` via `projectColumns`. If `node.column` is absent or
|
|
35
|
+
* empty, the returned Fragment has an empty columns array.
|
|
36
|
+
*
|
|
37
|
+
* @param node - The leaf select node whose `column[]` array is projected.
|
|
38
|
+
* @param ctx - The current walker context supplying partition keys and the
|
|
39
|
+
* transpiler context for expression generation.
|
|
40
|
+
* @param columnGenerator - The generator that converts column descriptors into
|
|
41
|
+
* T-SQL expressions.
|
|
42
|
+
* @returns A Fragment carrying only projected columns; `ctes` and
|
|
43
|
+
* `fromExtensions` are always empty.
|
|
44
|
+
*/
|
|
45
|
+
function walkColumnsOnly(node, ctx, columnGenerator) {
|
|
46
|
+
const columns = node.column
|
|
47
|
+
? projectColumns(node.column, ctx, columnGenerator)
|
|
48
|
+
: [];
|
|
49
|
+
return {
|
|
50
|
+
ctes: [],
|
|
51
|
+
fromExtensions: "",
|
|
52
|
+
columns,
|
|
53
|
+
partitionKeys: ctx.partitionKeys,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=columnsOnly.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"columnsOnly.js","sourceRoot":"","sources":["../../../../src/queryGenerator/treeWalker/operators/columnsOnly.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAwBH,wCASC;AAiBD,0CAcC;AAvDD;;;;;;;;;;;;;;GAcG;AACH,SAAgB,cAAc,CAC5B,OAA+B,EAC/B,GAAY,EACZ,eAA0C;IAE1C,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC9B,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,OAAO,EAAE,eAAe,CAAC,kBAAkB,CAAC,MAAM,EAAE,GAAG,CAAC,aAAa,CAAC;KACvE,CAAC,CAAC,CAAC;AACN,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAgB,eAAe,CAC7B,IAA0B,EAC1B,GAAY,EACZ,eAA0C;IAE1C,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM;QACzB,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,eAAe,CAAC;QACnD,CAAC,CAAC,EAAE,CAAC;IACP,OAAO;QACL,IAAI,EAAE,EAAE;QACR,cAAc,EAAE,EAAE;QAClB,OAAO;QACP,aAAa,EAAE,GAAG,CAAC,aAAa;KACjC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Walker for ForEach / ForEachOrNull nodes.
|
|
3
|
+
*
|
|
4
|
+
* Emits a CROSS APPLY (or OUTER APPLY) clause that iterates over a JSON
|
|
5
|
+
* array. Threads `ctx.source` and `ctx.transpilerCtx` so child nodes
|
|
6
|
+
* project columns relative to the iteration value, and appends a
|
|
7
|
+
* `<alias>_key` partition key.
|
|
8
|
+
*
|
|
9
|
+
* Path-handling parity is delegated to PathParser (`.where()`, `.first()`,
|
|
10
|
+
* array indexing, multi-segment array flattening).
|
|
11
|
+
*/
|
|
12
|
+
import type { ViewDefinitionSelect } from "../../../types.js";
|
|
13
|
+
import type { PathParser } from "../../PathParser.js";
|
|
14
|
+
import { type Context, type Fragment } from "../types.js";
|
|
15
|
+
interface ForEachDeps {
|
|
16
|
+
pathParser: PathParser;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Walker for ForEach and ForEachOrNull nodes.
|
|
20
|
+
*
|
|
21
|
+
* Emits a `CROSS APPLY` (or `OUTER APPLY` for `forEachOrNull`) clause that
|
|
22
|
+
* iterates over a JSON array identified by the node's FHIRPath expression.
|
|
23
|
+
* Updates `ctx.source`, `ctx.transpilerCtx`, and `ctx.partitionKeys` so that
|
|
24
|
+
* child nodes project columns relative to each iteration value, then walks
|
|
25
|
+
* the child sub-tree (`column`, `select`, `unionAll`) in that inner context.
|
|
26
|
+
* The apply clause is prepended to the inner Fragment's `fromExtensions`.
|
|
27
|
+
*
|
|
28
|
+
* Path features handled via `PathParser`: `.where()` filters, `.first()`
|
|
29
|
+
* selectors, array indexing, and multi-segment array flattening (nested
|
|
30
|
+
* `CROSS APPLY OPENJSON` chains).
|
|
31
|
+
*
|
|
32
|
+
* @param node - The ForEach or ForEachOrNull select node. `node.forEach` or
|
|
33
|
+
* `node.forEachOrNull` supplies the FHIRPath expression to iterate.
|
|
34
|
+
* @param ctx - The current walker context; the inner context is derived from
|
|
35
|
+
* it by updating `source`, `partitionKeys`, `ancestorApplies`, `nullable`,
|
|
36
|
+
* and `transpilerCtx`.
|
|
37
|
+
* @param walk - The recursive walk function used to visit the inner sub-tree.
|
|
38
|
+
* @param deps - Dependencies containing the `PathParser` used to parse and
|
|
39
|
+
* decompose the FHIRPath expression.
|
|
40
|
+
* @returns A Fragment whose `fromExtensions` begins with the generated APPLY
|
|
41
|
+
* clause followed by any extensions produced by the inner walk.
|
|
42
|
+
*/
|
|
43
|
+
export declare function walkForEach(node: ViewDefinitionSelect, ctx: Context, walk: (n: ViewDefinitionSelect, c: Context) => Fragment, deps: ForEachDeps): Fragment;
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=forEach.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forEach.d.ts","sourceRoot":"","sources":["../../../../src/queryGenerator/treeWalker/operators/forEach.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtD,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,QAAQ,EAGd,MAAM,aAAa,CAAC;AAErB,UAAU,WAAW;IACnB,UAAU,EAAE,UAAU,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,oBAAoB,EAC1B,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,CAAC,CAAC,EAAE,oBAAoB,EAAE,CAAC,EAAE,OAAO,KAAK,QAAQ,EACvD,IAAI,EAAE,WAAW,GAChB,QAAQ,CA2BV"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Walker for ForEach / ForEachOrNull nodes.
|
|
4
|
+
*
|
|
5
|
+
* Emits a CROSS APPLY (or OUTER APPLY) clause that iterates over a JSON
|
|
6
|
+
* array. Threads `ctx.source` and `ctx.transpilerCtx` so child nodes
|
|
7
|
+
* project columns relative to the iteration value, and appends a
|
|
8
|
+
* `<alias>_key` partition key.
|
|
9
|
+
*
|
|
10
|
+
* Path-handling parity is delegated to PathParser (`.where()`, `.first()`,
|
|
11
|
+
* array indexing, multi-segment array flattening).
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.walkForEach = walkForEach;
|
|
15
|
+
const aliasGenerator_js_1 = require("../aliasGenerator.js");
|
|
16
|
+
const types_js_1 = require("../types.js");
|
|
17
|
+
/**
|
|
18
|
+
* Walker for ForEach and ForEachOrNull nodes.
|
|
19
|
+
*
|
|
20
|
+
* Emits a `CROSS APPLY` (or `OUTER APPLY` for `forEachOrNull`) clause that
|
|
21
|
+
* iterates over a JSON array identified by the node's FHIRPath expression.
|
|
22
|
+
* Updates `ctx.source`, `ctx.transpilerCtx`, and `ctx.partitionKeys` so that
|
|
23
|
+
* child nodes project columns relative to each iteration value, then walks
|
|
24
|
+
* the child sub-tree (`column`, `select`, `unionAll`) in that inner context.
|
|
25
|
+
* The apply clause is prepended to the inner Fragment's `fromExtensions`.
|
|
26
|
+
*
|
|
27
|
+
* Path features handled via `PathParser`: `.where()` filters, `.first()`
|
|
28
|
+
* selectors, array indexing, and multi-segment array flattening (nested
|
|
29
|
+
* `CROSS APPLY OPENJSON` chains).
|
|
30
|
+
*
|
|
31
|
+
* @param node - The ForEach or ForEachOrNull select node. `node.forEach` or
|
|
32
|
+
* `node.forEachOrNull` supplies the FHIRPath expression to iterate.
|
|
33
|
+
* @param ctx - The current walker context; the inner context is derived from
|
|
34
|
+
* it by updating `source`, `partitionKeys`, `ancestorApplies`, `nullable`,
|
|
35
|
+
* and `transpilerCtx`.
|
|
36
|
+
* @param walk - The recursive walk function used to visit the inner sub-tree.
|
|
37
|
+
* @param deps - Dependencies containing the `PathParser` used to parse and
|
|
38
|
+
* decompose the FHIRPath expression.
|
|
39
|
+
* @returns A Fragment whose `fromExtensions` begins with the generated APPLY
|
|
40
|
+
* clause followed by any extensions produced by the inner walk.
|
|
41
|
+
*/
|
|
42
|
+
function walkForEach(node, ctx, walk, deps) {
|
|
43
|
+
const isOrNull = node.forEachOrNull !== undefined;
|
|
44
|
+
const rawPath = node.forEach ?? node.forEachOrNull ?? "";
|
|
45
|
+
const applyType = isOrNull ? "OUTER APPLY" : "CROSS APPLY";
|
|
46
|
+
const alias = (0, aliasGenerator_js_1.freshAlias)(ctx, "forEach");
|
|
47
|
+
const applyClause = buildForEachApply(rawPath, ctx.source, alias, applyType, ctx.transpilerCtx, deps.pathParser);
|
|
48
|
+
const innerCtx = buildInnerCtx(ctx, alias, rawPath, applyClause, isOrNull);
|
|
49
|
+
const innerNode = {
|
|
50
|
+
column: node.column,
|
|
51
|
+
select: node.select,
|
|
52
|
+
unionAll: node.unionAll,
|
|
53
|
+
};
|
|
54
|
+
const inner = walk(innerNode, innerCtx);
|
|
55
|
+
return {
|
|
56
|
+
...inner,
|
|
57
|
+
fromExtensions: applyClause + inner.fromExtensions,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function buildInnerCtx(ctx, alias, rawPath, applyClause, isOrNull) {
|
|
61
|
+
const innerTranspilerCtx = {
|
|
62
|
+
...ctx.transpilerCtx,
|
|
63
|
+
iterationContext: `${alias}.value`,
|
|
64
|
+
currentForEachAlias: alias,
|
|
65
|
+
forEachSource: ctx.source,
|
|
66
|
+
forEachPath: `$.${rawPath}`,
|
|
67
|
+
};
|
|
68
|
+
const innerKey = {
|
|
69
|
+
name: `${alias}_key`,
|
|
70
|
+
sqlExpr: `${alias}.[key]`,
|
|
71
|
+
sqlType: types_js_1.SQL_NVARCHAR_4000,
|
|
72
|
+
};
|
|
73
|
+
return {
|
|
74
|
+
...ctx,
|
|
75
|
+
source: `${alias}.value`,
|
|
76
|
+
partitionKeys: [...ctx.partitionKeys, innerKey],
|
|
77
|
+
ancestorApplies: ctx.ancestorApplies + applyClause,
|
|
78
|
+
nullable: ctx.nullable || isOrNull,
|
|
79
|
+
transpilerCtx: innerTranspilerCtx,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Builds the CROSS/OUTER APPLY clause string for a forEach path, handling
|
|
84
|
+
* `.where()`, `.first()`, array indexing, and multi-segment array
|
|
85
|
+
* flattening.
|
|
86
|
+
*/
|
|
87
|
+
function buildForEachApply(rawPath, source, alias, applyType, transpilerCtx, pathParser) {
|
|
88
|
+
const { path: pathWithoutWhere, whereCondition, useFirst, } = pathParser.parseFhirPathWhere(rawPath, transpilerCtx);
|
|
89
|
+
const { path: forEachPath, arrayIndex } = pathParser.parseArrayIndexing(pathWithoutWhere);
|
|
90
|
+
const arrayPaths = pathParser.detectArrayFlatteningPaths(forEachPath);
|
|
91
|
+
if (arrayPaths.length > 1) {
|
|
92
|
+
return buildNestedApply(arrayPaths, source, alias, applyType, pathParser, arrayIndex, whereCondition);
|
|
93
|
+
}
|
|
94
|
+
return buildSimpleApply(applyType, source, forEachPath, alias, arrayIndex, whereCondition, useFirst);
|
|
95
|
+
}
|
|
96
|
+
function buildSimpleApply(applyType, source, path, alias, arrayIndex, whereCondition, useFirst) {
|
|
97
|
+
const whereClauses = [];
|
|
98
|
+
if (arrayIndex !== null)
|
|
99
|
+
whereClauses.push(`[key] = '${arrayIndex}'`);
|
|
100
|
+
if (whereCondition !== null)
|
|
101
|
+
whereClauses.push(whereCondition);
|
|
102
|
+
if (whereClauses.length > 0 || useFirst) {
|
|
103
|
+
const topClause = useFirst ? "TOP 1 " : "";
|
|
104
|
+
const orderBy = useFirst ? " ORDER BY [key]" : "";
|
|
105
|
+
const whereClause = whereClauses.length > 0 ? `WHERE ${whereClauses.join(" AND ")}` : "";
|
|
106
|
+
return `\n${applyType} (
|
|
107
|
+
SELECT ${topClause}* FROM OPENJSON(${source}, '$.${path}')
|
|
108
|
+
${whereClause}${orderBy}
|
|
109
|
+
) AS ${alias}`;
|
|
110
|
+
}
|
|
111
|
+
return `\n${applyType} OPENJSON(${source}, '$.${path}') AS ${alias}`;
|
|
112
|
+
}
|
|
113
|
+
function buildNestedApply(arrayPaths, source, finalAlias, applyType, pathParser, arrayIndex, whereCondition) {
|
|
114
|
+
let clauses = "";
|
|
115
|
+
let currentSource = source;
|
|
116
|
+
for (let i = 0; i < arrayPaths.length; i++) {
|
|
117
|
+
const isLast = i === arrayPaths.length - 1;
|
|
118
|
+
const alias = isLast ? finalAlias : `${finalAlias}_nest${i}`;
|
|
119
|
+
const segment = pathParser.extractPathSegment(arrayPaths, i);
|
|
120
|
+
const { cleanSegment, segmentIndex } = pathParser.parseSegmentIndexing(segment);
|
|
121
|
+
const jsonPath = `$.${cleanSegment}`;
|
|
122
|
+
const whereClauses = [];
|
|
123
|
+
if (segmentIndex !== null) {
|
|
124
|
+
whereClauses.push(`[key] = '${segmentIndex}'`);
|
|
125
|
+
}
|
|
126
|
+
else if (isLast && arrayIndex !== null) {
|
|
127
|
+
whereClauses.push(`[key] = '${arrayIndex}'`);
|
|
128
|
+
}
|
|
129
|
+
if (isLast && whereCondition !== null)
|
|
130
|
+
whereClauses.push(whereCondition);
|
|
131
|
+
if (whereClauses.length > 0) {
|
|
132
|
+
clauses += `\n${applyType} (
|
|
133
|
+
SELECT * FROM OPENJSON(${currentSource}, '${jsonPath}')
|
|
134
|
+
WHERE ${whereClauses.join(" AND ")}
|
|
135
|
+
) AS ${alias}`;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
clauses += `\n${applyType} OPENJSON(${currentSource}, '${jsonPath}') AS ${alias}`;
|
|
139
|
+
}
|
|
140
|
+
currentSource = `${alias}.value`;
|
|
141
|
+
}
|
|
142
|
+
return clauses;
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=forEach.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forEach.js","sourceRoot":"","sources":["../../../../src/queryGenerator/treeWalker/operators/forEach.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;AA0CH,kCAgCC;AArED,4DAAkD;AAClD,0CAKqB;AAMrB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,SAAgB,WAAW,CACzB,IAA0B,EAC1B,GAAY,EACZ,IAAuD,EACvD,IAAiB;IAEjB,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,KAAK,SAAS,CAAC;IAClD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC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AU,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAC3C,MAAM,QAAQ,GAAG,KAAK,YAAY,EAAE,CAAC;QAErC,MAAM,YAAY,GAAa,EAAE,CAAC;QAClC,IAAI,YAAY,KAAK,IAAI,EAAE,CAAC;YAC1B,YAAY,CAAC,IAAI,CAAC,YAAY,YAAY,GAAG,CAAC,CAAC;QACjD,CAAC;aAAM,IAAI,MAAM,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;YACzC,YAAY,CAAC,IAAI,CAAC,YAAY,UAAU,GAAG,CAAC,CAAC;QAC/C,CAAC;QACD,IAAI,MAAM,IAAI,cAAc,KAAK,IAAI;YAAE,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAEzE,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC5B,OAAO,IAAI,KAAK,SAAS;iCACE,aAAa,MAAM,QAAQ;gBAC5C,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC;aAC7B,KAAK,EAAE,CAAC;QACjB,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,KAAK,SAAS,aAAa,aAAa,MAAM,QAAQ,SAAS,KAAK,EAAE,CAAC;QACpF,CAAC;QAED,aAAa,GAAG,GAAG,KAAK,QAAQ,CAAC;IACnC,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Walker for Group nodes — visits each child and merges their fragments.
|
|
3
|
+
*
|
|
4
|
+
* If the node has both `column` and `select`, the columns are emitted as
|
|
5
|
+
* an implicit first ColumnsOnly child so they appear before the children's
|
|
6
|
+
* projections in lexical order.
|
|
7
|
+
*/
|
|
8
|
+
import type { ViewDefinitionSelect } from "../../../types.js";
|
|
9
|
+
import type { ColumnExpressionGenerator } from "../../ColumnExpressionGenerator.js";
|
|
10
|
+
import type { Context, Fragment } from "../types.js";
|
|
11
|
+
import { projectColumns } from "./columnsOnly.js";
|
|
12
|
+
/**
|
|
13
|
+
* Walker for Group nodes — visits each child select and merges their Fragments.
|
|
14
|
+
*
|
|
15
|
+
* If the node has both `column[]` and `select[]`, the columns are emitted as
|
|
16
|
+
* an implicit first ColumnsOnly child so they appear before the child select
|
|
17
|
+
* projections in lexical order. All children are walked with the same
|
|
18
|
+
* unmodified `ctx`; their Fragments are merged via `mergeSiblings`.
|
|
19
|
+
*
|
|
20
|
+
* Returns an empty Fragment when the node has neither `column[]` nor
|
|
21
|
+
* `select[]` children.
|
|
22
|
+
*
|
|
23
|
+
* @param node - The Group select node, which may carry `column[]`, `select[]`,
|
|
24
|
+
* or both.
|
|
25
|
+
* @param ctx - The current walker context passed unchanged to every child.
|
|
26
|
+
* @param walk - The recursive walk function used to visit each child select
|
|
27
|
+
* node.
|
|
28
|
+
* @param columnGenerator - The generator forwarded to `walkColumnsOnly` when
|
|
29
|
+
* the node also carries inline `column[]` entries.
|
|
30
|
+
* @returns A merged Fragment whose columns, CTEs, and FROM extensions are the
|
|
31
|
+
* ordered union of all child Fragments.
|
|
32
|
+
*/
|
|
33
|
+
export declare function walkGroup(node: ViewDefinitionSelect, ctx: Context, walk: (n: ViewDefinitionSelect, c: Context) => Fragment, columnGenerator: ColumnExpressionGenerator): Fragment;
|
|
34
|
+
export { projectColumns };
|
|
35
|
+
//# sourceMappingURL=group.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"group.d.ts","sourceRoot":"","sources":["../../../../src/queryGenerator/treeWalker/operators/group.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAEpF,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,cAAc,EAAmB,MAAM,kBAAkB,CAAC;AAEnE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,oBAAoB,EAC1B,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,CAAC,CAAC,EAAE,oBAAoB,EAAE,CAAC,EAAE,OAAO,KAAK,QAAQ,EACvD,eAAe,EAAE,yBAAyB,GACzC,QAAQ,CAuBV;AAGD,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Walker for Group nodes — visits each child and merges their fragments.
|
|
4
|
+
*
|
|
5
|
+
* If the node has both `column` and `select`, the columns are emitted as
|
|
6
|
+
* an implicit first ColumnsOnly child so they appear before the children's
|
|
7
|
+
* projections in lexical order.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.projectColumns = void 0;
|
|
11
|
+
exports.walkGroup = walkGroup;
|
|
12
|
+
const mergeSiblings_js_1 = require("../mergeSiblings.js");
|
|
13
|
+
const columnsOnly_js_1 = require("./columnsOnly.js");
|
|
14
|
+
Object.defineProperty(exports, "projectColumns", { enumerable: true, get: function () { return columnsOnly_js_1.projectColumns; } });
|
|
15
|
+
/**
|
|
16
|
+
* Walker for Group nodes — visits each child select and merges their Fragments.
|
|
17
|
+
*
|
|
18
|
+
* If the node has both `column[]` and `select[]`, the columns are emitted as
|
|
19
|
+
* an implicit first ColumnsOnly child so they appear before the child select
|
|
20
|
+
* projections in lexical order. All children are walked with the same
|
|
21
|
+
* unmodified `ctx`; their Fragments are merged via `mergeSiblings`.
|
|
22
|
+
*
|
|
23
|
+
* Returns an empty Fragment when the node has neither `column[]` nor
|
|
24
|
+
* `select[]` children.
|
|
25
|
+
*
|
|
26
|
+
* @param node - The Group select node, which may carry `column[]`, `select[]`,
|
|
27
|
+
* or both.
|
|
28
|
+
* @param ctx - The current walker context passed unchanged to every child.
|
|
29
|
+
* @param walk - The recursive walk function used to visit each child select
|
|
30
|
+
* node.
|
|
31
|
+
* @param columnGenerator - The generator forwarded to `walkColumnsOnly` when
|
|
32
|
+
* the node also carries inline `column[]` entries.
|
|
33
|
+
* @returns A merged Fragment whose columns, CTEs, and FROM extensions are the
|
|
34
|
+
* ordered union of all child Fragments.
|
|
35
|
+
*/
|
|
36
|
+
function walkGroup(node, ctx, walk, columnGenerator) {
|
|
37
|
+
const children = [];
|
|
38
|
+
if (node.column && node.column.length > 0) {
|
|
39
|
+
children.push((0, columnsOnly_js_1.walkColumnsOnly)(node, ctx, columnGenerator));
|
|
40
|
+
}
|
|
41
|
+
if (node.select) {
|
|
42
|
+
for (const child of node.select) {
|
|
43
|
+
children.push(walk(child, ctx));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (children.length === 0) {
|
|
47
|
+
return {
|
|
48
|
+
ctes: [],
|
|
49
|
+
fromExtensions: "",
|
|
50
|
+
columns: [],
|
|
51
|
+
partitionKeys: ctx.partitionKeys,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return (0, mergeSiblings_js_1.mergeSiblings)(children, ctx);
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=group.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"group.js","sourceRoot":"","sources":["../../../../src/queryGenerator/treeWalker/operators/group.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AA6BH,8BA4BC;AArDD,0DAAoD;AAEpD,qDAAmE;AAsD1D,+FAtDA,+BAAc,OAsDA;AApDvB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,SAAS,CACvB,IAA0B,EAC1B,GAAY,EACZ,IAAuD,EACvD,eAA0C;IAE1C,MAAM,QAAQ,GAAe,EAAE,CAAC;IAEhC,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1C,QAAQ,CAAC,IAAI,CAAC,IAAA,gCAAe,EAAC,IAAI,EAAE,GAAG,EAAE,eAAe,CAAC,CAAC,CAAC;IAC7D,CAAC;IAED,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QAChB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;IAED,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO;YACL,IAAI,EAAE,EAAE;YACR,cAAc,EAAE,EAAE;YAClB,OAAO,EAAE,EAAE;YACX,aAAa,EAAE,GAAG,CAAC,aAAa;SACjC,CAAC;IACJ,CAAC;IAED,OAAO,IAAA,gCAAa,EAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Walker for Repeat nodes — emits a recursive CTE and returns a set Fragment.
|
|
3
|
+
*
|
|
4
|
+
* The CTE projects the current partition keys and any baked scalar columns
|
|
5
|
+
* plus a content-derived `__path` for stable identity across re-evaluations.
|
|
6
|
+
* The Fragment's `fromExtensions` is an INNER JOIN to the CTE on the partition key
|
|
7
|
+
* `[id]`; sibling-level composite-key joins are added by `mergeSiblings`.
|
|
8
|
+
*/
|
|
9
|
+
import type { ViewDefinitionSelect } from "../../../types.js";
|
|
10
|
+
import { type Context, type Fragment } from "../types.js";
|
|
11
|
+
export interface RepeatDeps {
|
|
12
|
+
schemaName: string;
|
|
13
|
+
tableName: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Walker for Repeat nodes — emits a recursive CTE and returns a set Fragment.
|
|
17
|
+
*
|
|
18
|
+
* Generates a `WITH RECURSIVE`-style CTE (via `buildRepeatCte`) whose anchor
|
|
19
|
+
* member starts at the resource root and whose recursive members re-expand
|
|
20
|
+
* each element's `item_json` using the same path list. The CTE accumulates a
|
|
21
|
+
* `__path` string for stable per-element identity across recursion levels.
|
|
22
|
+
*
|
|
23
|
+
* The returned Fragment contains the CTE plus an `INNER JOIN` to it in
|
|
24
|
+
* `fromExtensions`; the join is keyed on all current partition keys so that
|
|
25
|
+
* only rows belonging to the enclosing resource (and any ancestor forEach)
|
|
26
|
+
* are included. The inner context updates `source` to `<cteAlias>.item_json`
|
|
27
|
+
* and appends a new `<cteAlias>_path` partition key so that nested operators
|
|
28
|
+
* can further partition the result set.
|
|
29
|
+
*
|
|
30
|
+
* @param node - The Repeat select node; `node.repeat` supplies the ordered
|
|
31
|
+
* list of FHIRPath strings used as the anchor and recursive paths.
|
|
32
|
+
* @param ctx - The current walker context; the inner context is derived from
|
|
33
|
+
* it by updating `source`, `partitionKeys`, `ancestorApplies`, and
|
|
34
|
+
* `transpilerCtx`.
|
|
35
|
+
* @param walk - The recursive walk function used to visit the inner sub-tree
|
|
36
|
+
* (`column`, `select`, `unionAll`) in the repeat-item context.
|
|
37
|
+
* @param deps - Schema and table name needed to construct the resource FROM
|
|
38
|
+
* clause inside the CTE anchor.
|
|
39
|
+
* @returns A Fragment whose `ctes` list begins with the recursive CTE,
|
|
40
|
+
* `fromExtensions` begins with the INNER JOIN to that CTE, and `columns`
|
|
41
|
+
* are those produced by the inner walk.
|
|
42
|
+
* @throws {Error} When `node.repeat` is absent or empty.
|
|
43
|
+
*/
|
|
44
|
+
export declare function walkRepeat(node: ViewDefinitionSelect, ctx: Context, walk: (n: ViewDefinitionSelect, c: Context) => Fragment, deps: RepeatDeps): Fragment;
|
|
45
|
+
//# sourceMappingURL=repeat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repeat.d.ts","sourceRoot":"","sources":["../../../../src/queryGenerator/treeWalker/operators/repeat.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAG9D,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,QAAQ,EAGd,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,oBAAoB,EAC1B,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,CAAC,CAAC,EAAE,oBAAoB,EAAE,CAAC,EAAE,OAAO,KAAK,QAAQ,EACvD,IAAI,EAAE,UAAU,GACf,QAAQ,CAmCV"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Walker for Repeat nodes — emits a recursive CTE and returns a set Fragment.
|
|
4
|
+
*
|
|
5
|
+
* The CTE projects the current partition keys and any baked scalar columns
|
|
6
|
+
* plus a content-derived `__path` for stable identity across re-evaluations.
|
|
7
|
+
* The Fragment's `fromExtensions` is an INNER JOIN to the CTE on the partition key
|
|
8
|
+
* `[id]`; sibling-level composite-key joins are added by `mergeSiblings`.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.walkRepeat = walkRepeat;
|
|
12
|
+
const aliasGenerator_js_1 = require("../aliasGenerator.js");
|
|
13
|
+
const cteTemplates_js_1 = require("../cteTemplates.js");
|
|
14
|
+
const types_js_1 = require("../types.js");
|
|
15
|
+
/**
|
|
16
|
+
* Walker for Repeat nodes — emits a recursive CTE and returns a set Fragment.
|
|
17
|
+
*
|
|
18
|
+
* Generates a `WITH RECURSIVE`-style CTE (via `buildRepeatCte`) whose anchor
|
|
19
|
+
* member starts at the resource root and whose recursive members re-expand
|
|
20
|
+
* each element's `item_json` using the same path list. The CTE accumulates a
|
|
21
|
+
* `__path` string for stable per-element identity across recursion levels.
|
|
22
|
+
*
|
|
23
|
+
* The returned Fragment contains the CTE plus an `INNER JOIN` to it in
|
|
24
|
+
* `fromExtensions`; the join is keyed on all current partition keys so that
|
|
25
|
+
* only rows belonging to the enclosing resource (and any ancestor forEach)
|
|
26
|
+
* are included. The inner context updates `source` to `<cteAlias>.item_json`
|
|
27
|
+
* and appends a new `<cteAlias>_path` partition key so that nested operators
|
|
28
|
+
* can further partition the result set.
|
|
29
|
+
*
|
|
30
|
+
* @param node - The Repeat select node; `node.repeat` supplies the ordered
|
|
31
|
+
* list of FHIRPath strings used as the anchor and recursive paths.
|
|
32
|
+
* @param ctx - The current walker context; the inner context is derived from
|
|
33
|
+
* it by updating `source`, `partitionKeys`, `ancestorApplies`, and
|
|
34
|
+
* `transpilerCtx`.
|
|
35
|
+
* @param walk - The recursive walk function used to visit the inner sub-tree
|
|
36
|
+
* (`column`, `select`, `unionAll`) in the repeat-item context.
|
|
37
|
+
* @param deps - Schema and table name needed to construct the resource FROM
|
|
38
|
+
* clause inside the CTE anchor.
|
|
39
|
+
* @returns A Fragment whose `ctes` list begins with the recursive CTE,
|
|
40
|
+
* `fromExtensions` begins with the INNER JOIN to that CTE, and `columns`
|
|
41
|
+
* are those produced by the inner walk.
|
|
42
|
+
* @throws {Error} When `node.repeat` is absent or empty.
|
|
43
|
+
*/
|
|
44
|
+
function walkRepeat(node, ctx, walk, deps) {
|
|
45
|
+
const cteAlias = (0, aliasGenerator_js_1.freshAlias)(ctx, "repeat");
|
|
46
|
+
const paths = node.repeat ?? [];
|
|
47
|
+
if (paths.length === 0) {
|
|
48
|
+
throw new Error("walkRepeat: repeat node has empty paths array");
|
|
49
|
+
}
|
|
50
|
+
const tableRef = `[${deps.schemaName}].[${deps.tableName}]`;
|
|
51
|
+
const cte = (0, cteTemplates_js_1.buildRepeatCte)({
|
|
52
|
+
cteAlias,
|
|
53
|
+
paths,
|
|
54
|
+
source: ctx.source,
|
|
55
|
+
fromClause: `FROM ${tableRef} AS [${ctx.resourceAlias}]`,
|
|
56
|
+
ancestorApplies: ctx.ancestorApplies,
|
|
57
|
+
partitionKeys: ctx.partitionKeys,
|
|
58
|
+
resourcePredicate: null, // Resource-level WHERE goes in the outer SELECT.
|
|
59
|
+
});
|
|
60
|
+
const joinClause = buildJoinClause(cteAlias, ctx);
|
|
61
|
+
const innerCtx = buildRepeatInnerCtx(ctx, cteAlias, paths, joinClause);
|
|
62
|
+
const innerNode = {
|
|
63
|
+
column: node.column,
|
|
64
|
+
select: node.select,
|
|
65
|
+
unionAll: node.unionAll,
|
|
66
|
+
};
|
|
67
|
+
const inner = walk(innerNode, innerCtx);
|
|
68
|
+
return {
|
|
69
|
+
ctes: [cte, ...inner.ctes],
|
|
70
|
+
// Join the CTE FIRST so subsequent applies/joins inside the repeat
|
|
71
|
+
// (which reference `<cteAlias>.item_json`) have the alias in scope.
|
|
72
|
+
fromExtensions: joinClause + inner.fromExtensions,
|
|
73
|
+
columns: inner.columns,
|
|
74
|
+
partitionKeys: innerCtx.partitionKeys,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Outer-SELECT join condition aligning this CTE's rows with the enclosing
|
|
79
|
+
* partition (resource id plus any forEach/repeat keys above this scope).
|
|
80
|
+
*/
|
|
81
|
+
function buildJoinClause(cteAlias, ctx) {
|
|
82
|
+
const joinConditions = ctx.partitionKeys
|
|
83
|
+
.map((k) => `${cteAlias}.[${k.name}] = ${k.sqlExpr}`)
|
|
84
|
+
.join(" AND ");
|
|
85
|
+
return `\nINNER JOIN ${cteAlias} ON ${joinConditions}`;
|
|
86
|
+
}
|
|
87
|
+
function buildRepeatInnerCtx(ctx, cteAlias, paths, joinClause) {
|
|
88
|
+
const newKey = {
|
|
89
|
+
name: `${cteAlias}_path`,
|
|
90
|
+
sqlExpr: `${cteAlias}.__path`,
|
|
91
|
+
sqlType: types_js_1.SQL_NVARCHAR_MAX,
|
|
92
|
+
};
|
|
93
|
+
const innerTranspilerCtx = {
|
|
94
|
+
...ctx.transpilerCtx,
|
|
95
|
+
iterationContext: `${cteAlias}.item_json`,
|
|
96
|
+
currentForEachAlias: cteAlias,
|
|
97
|
+
forEachSource: ctx.source,
|
|
98
|
+
forEachPath: paths.map((p) => `$.${p}`).join(", "),
|
|
99
|
+
};
|
|
100
|
+
// Propagate the join into ancestorApplies so any *nested* Repeat builds
|
|
101
|
+
// its CTE anchor with this CTE in scope.
|
|
102
|
+
return {
|
|
103
|
+
...ctx,
|
|
104
|
+
source: `${cteAlias}.item_json`,
|
|
105
|
+
partitionKeys: [...ctx.partitionKeys, newKey],
|
|
106
|
+
ancestorApplies: ctx.ancestorApplies + joinClause,
|
|
107
|
+
transpilerCtx: innerTranspilerCtx,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=repeat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repeat.js","sourceRoot":"","sources":["../../../../src/queryGenerator/treeWalker/operators/repeat.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;AA+CH,gCAwCC;AAnFD,4DAAkD;AAClD,wDAAoD;AACpD,0CAKqB;AAOrB;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,SAAgB,UAAU,CACxB,IAA0B,EAC1B,GAAY,EACZ,IAAuD,EACvD,IAAgB;IAEhB,MAAM,QAAQ,GAAG,IAAA,8BAAU,EAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAC3C,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC;IAChC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;IACnE,CAAC;IAED,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC,UAAU,MAAM,IAAI,CAAC,SAAS,GAAG,CAAC;IAC5D,MAAM,GAAG,GAAG,IAAA,gCAAc,EAAC;QACzB,QAAQ;QACR,KAAK;QACL,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,UAA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C3B,IAAI,EAAE,GAAG,QAAQ,OAAO;QACxB,OAAO,EAAE,GAAG,QAAQ,SAAS;QAC7B,OAAO,EAAE,2BAAgB;KAC1B,CAAC;IACF,MAAM,kBAAkB,GAAsB;QAC5C,GAAG,GAAG,CAAC,aAAa;QACpB,gBAAgB,EAAE,GAAG,QAAQ,YAAY;QACzC,mBAAmB,EAAE,QAAQ;QAC7B,aAAa,EAAE,GAAG,CAAC,MAAM;QACzB,WAAW,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;KACnD,CAAC;IACF,wEAAwE;IACxE,yCAAyC;IACzC,OAAO;QACL,GAAG,GAAG;QACN,MAAM,EAAE,GAAG,QAAQ,YAAY;QAC/B,aAAa,EAAE,CAAC,GAAG,GAAG,CAAC,aAAa,EAAE,MAAM,CAAC;QAC7C,eAAe,EAAE,GAAG,CAAC,eAAe,GAAG,UAAU;QACjD,aAAa,EAAE,kBAAkB;KAClC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Walker for UnionAll nodes.
|
|
3
|
+
*
|
|
4
|
+
* Emits a local derived table with one SELECT per branch, joined by
|
|
5
|
+
* `UNION ALL`, wrapped as `CROSS APPLY (...) AS ua_<n>`. CTEs from any
|
|
6
|
+
* branch (e.g. enclosed Repeats) bubble up to the top-level WITH clause.
|
|
7
|
+
*
|
|
8
|
+
* Branches must produce the same column names and types (SoF spec
|
|
9
|
+
* requirement). The walker aligns them positionally — branch[0]'s names
|
|
10
|
+
* become the outer projection.
|
|
11
|
+
*
|
|
12
|
+
* If the same node also has `column[]` or `select[]` alongside `unionAll`,
|
|
13
|
+
* those are emitted as outer siblings (they live in the SELECT list at the
|
|
14
|
+
* same level as the ua_<n> projection, evaluated in the parent scope).
|
|
15
|
+
*/
|
|
16
|
+
import type { ViewDefinitionSelect } from "../../../types.js";
|
|
17
|
+
import type { ColumnExpressionGenerator } from "../../ColumnExpressionGenerator.js";
|
|
18
|
+
import type { Context, Fragment } from "../types.js";
|
|
19
|
+
export interface UnionAllDeps {
|
|
20
|
+
columnGenerator: ColumnExpressionGenerator;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Walker for UnionAll nodes.
|
|
24
|
+
*
|
|
25
|
+
* Walks each branch of `node.unionAll` in the current context and assembles
|
|
26
|
+
* them into a `CROSS APPLY (...) AS ua_<n>` derived table where each branch
|
|
27
|
+
* contributes a `SELECT … FROM (SELECT 1 AS _) AS _seed …` statement joined
|
|
28
|
+
* by `UNION ALL`. Branch columns are aligned positionally to branch[0]'s
|
|
29
|
+
* names, satisfying the SoF spec requirement that all branches produce the
|
|
30
|
+
* same column names and types.
|
|
31
|
+
*
|
|
32
|
+
* CTEs from any branch (e.g. produced by enclosed Repeat nodes) bubble up
|
|
33
|
+
* into the returned Fragment's `ctes` list so they appear in the top-level
|
|
34
|
+
* `WITH` clause.
|
|
35
|
+
*
|
|
36
|
+
* If the same node also carries `column[]` or `select[]` alongside
|
|
37
|
+
* `unionAll`, those are emitted as outer siblings in the enclosing SELECT
|
|
38
|
+
* scope and merged with the union fragment via `mergeSiblings`.
|
|
39
|
+
*
|
|
40
|
+
* @param node - The UnionAll select node; `node.unionAll` must be a non-empty
|
|
41
|
+
* array of branch select nodes.
|
|
42
|
+
* @param ctx - The current walker context, passed unchanged to every branch
|
|
43
|
+
* and to any sibling column/select processing.
|
|
44
|
+
* @param walk - The recursive walk function used to visit each branch and any
|
|
45
|
+
* outer sibling select nodes.
|
|
46
|
+
* @param deps - Dependencies containing the `ColumnExpressionGenerator` used
|
|
47
|
+
* to project any outer sibling `column[]` entries.
|
|
48
|
+
* @returns A Fragment whose `fromExtensions` contains the `CROSS APPLY`
|
|
49
|
+
* derived-table clause, `ctes` aggregates all branch CTEs, and `columns`
|
|
50
|
+
* contains the outer projection (plus any sibling columns).
|
|
51
|
+
* @throws {Error} When `node.unionAll` is empty.
|
|
52
|
+
*/
|
|
53
|
+
export declare function walkUnionAll(node: ViewDefinitionSelect, ctx: Context, walk: (n: ViewDefinitionSelect, c: Context) => Fragment, deps: UnionAllDeps): Fragment;
|
|
54
|
+
//# sourceMappingURL=unionAll.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unionAll.d.ts","sourceRoot":"","sources":["../../../../src/queryGenerator/treeWalker/operators/unionAll.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAGpF,OAAO,KAAK,EACV,OAAO,EAEP,QAAQ,EAET,MAAM,aAAa,CAAC;AAGrB,MAAM,WAAW,YAAY;IAC3B,eAAe,EAAE,yBAAyB,CAAC;CAC5C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,oBAAoB,EAC1B,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,CAAC,CAAC,EAAE,oBAAoB,EAAE,CAAC,EAAE,OAAO,KAAK,QAAQ,EACvD,IAAI,EAAE,YAAY,GACjB,QAAQ,CAWV"}
|