rawsql-ts 0.11.25-beta → 0.11.26-beta
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/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +14 -14
- package/dist/esm/index.min.js.map +3 -3
- package/dist/esm/src/index.d.ts +1 -0
- package/dist/esm/src/index.js +1 -0
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/transformers/JoinAggregationDecomposer.d.ts +188 -0
- package/dist/esm/src/transformers/JoinAggregationDecomposer.js +490 -0
- package/dist/esm/src/transformers/JoinAggregationDecomposer.js.map +1 -0
- package/dist/esm/src/transformers/QueryBuilder.d.ts +22 -0
- package/dist/esm/src/transformers/QueryBuilder.js +49 -3
- package/dist/esm/src/transformers/QueryBuilder.js.map +1 -1
- package/dist/esm/tsconfig.browser.tsbuildinfo +1 -1
- package/dist/index.min.js +12 -12
- package/dist/index.min.js.map +3 -3
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/transformers/JoinAggregationDecomposer.d.ts +188 -0
- package/dist/src/transformers/JoinAggregationDecomposer.js +497 -0
- package/dist/src/transformers/JoinAggregationDecomposer.js.map +1 -0
- package/dist/src/transformers/QueryBuilder.d.ts +22 -0
- package/dist/src/transformers/QueryBuilder.js +49 -3
- package/dist/src/transformers/QueryBuilder.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JoinAggregationDecomposer = exports.DecompositionError = void 0;
|
|
4
|
+
exports.analyzeJoinAggregation = analyzeJoinAggregation;
|
|
5
|
+
exports.decomposeJoinAggregation = decomposeJoinAggregation;
|
|
6
|
+
const SimpleSelectQuery_1 = require("../models/SimpleSelectQuery");
|
|
7
|
+
const Clause_1 = require("../models/Clause");
|
|
8
|
+
const ValueComponent_1 = require("../models/ValueComponent");
|
|
9
|
+
const SqlFormatter_1 = require("./SqlFormatter");
|
|
10
|
+
/**
|
|
11
|
+
* Error thrown when query decomposition fails
|
|
12
|
+
*/
|
|
13
|
+
class DecompositionError extends Error {
|
|
14
|
+
constructor(message, originalQuery, cause) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.originalQuery = originalQuery;
|
|
17
|
+
this.cause = cause;
|
|
18
|
+
this.name = 'DecompositionError';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.DecompositionError = DecompositionError;
|
|
22
|
+
/**
|
|
23
|
+
* Decomposes queries that combine table joins with aggregations into separate detail and aggregation queries using CTEs
|
|
24
|
+
*
|
|
25
|
+
* This transformer separates JOIN operations from aggregation operations to make queries easier to debug:
|
|
26
|
+
* - Detail query: Contains JOINs and column selection
|
|
27
|
+
* - Aggregation query: Contains GROUP BY and aggregation functions, referencing the CTE
|
|
28
|
+
*
|
|
29
|
+
* Provides two patterns following existing codebase conventions:
|
|
30
|
+
* - analyze(): Safe analysis (Result pattern like SelectQueryParser.analyze)
|
|
31
|
+
* - decompose(): Direct decomposition with exceptions (Exception pattern like SelectQueryParser.parse)
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const decomposer = new JoinAggregationDecomposer();
|
|
36
|
+
*
|
|
37
|
+
* // Safe analysis (Result pattern)
|
|
38
|
+
* const analysis = decomposer.analyze(query);
|
|
39
|
+
* if (analysis.success) {
|
|
40
|
+
* console.log('Can decompose with', analysis.metadata.joinCount, 'joins');
|
|
41
|
+
* if (analysis.limitations) {
|
|
42
|
+
* console.log('Known limitations:', analysis.limitations);
|
|
43
|
+
* }
|
|
44
|
+
* } else {
|
|
45
|
+
* console.log('Cannot decompose:', analysis.error);
|
|
46
|
+
* }
|
|
47
|
+
*
|
|
48
|
+
* // Direct decomposition (Exception pattern)
|
|
49
|
+
* try {
|
|
50
|
+
* const decomposed = decomposer.decompose(query);
|
|
51
|
+
* // Success: decomposed query ready to use
|
|
52
|
+
* } catch (error) {
|
|
53
|
+
* if (error instanceof DecompositionError) {
|
|
54
|
+
* console.log('Decomposition failed:', error.message);
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
class JoinAggregationDecomposer {
|
|
60
|
+
constructor(options = {}) {
|
|
61
|
+
this.options = {
|
|
62
|
+
detailCTEName: options.detailCTEName || "detail_data"
|
|
63
|
+
};
|
|
64
|
+
this.formatter = new SqlFormatter_1.SqlFormatter({ identifierEscape: { start: "", end: "" } });
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Analyzes a query for decomposition without throwing errors (safe analysis)
|
|
68
|
+
* Follows the same pattern as SelectQueryParser.analyze()
|
|
69
|
+
*
|
|
70
|
+
* @param query The query to analyze
|
|
71
|
+
* @returns Analysis result with success status, error information, and metadata
|
|
72
|
+
*/
|
|
73
|
+
analyze(query) {
|
|
74
|
+
const metadata = this.extractMetadata(query);
|
|
75
|
+
try {
|
|
76
|
+
// Phase 1: Validate query structure
|
|
77
|
+
const validationError = this.getValidationError(query, metadata);
|
|
78
|
+
if (validationError) {
|
|
79
|
+
return {
|
|
80
|
+
success: false,
|
|
81
|
+
error: validationError,
|
|
82
|
+
metadata
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
// Phase 2: Attempt decomposition
|
|
86
|
+
const decomposed = this.performDecomposition(query);
|
|
87
|
+
// Phase 3: Check for formatting issues (critical validation)
|
|
88
|
+
try {
|
|
89
|
+
this.formatter.format(decomposed);
|
|
90
|
+
}
|
|
91
|
+
catch (formatError) {
|
|
92
|
+
return {
|
|
93
|
+
success: false,
|
|
94
|
+
error: `Decomposed query cannot be formatted: ${formatError instanceof Error ? formatError.message : String(formatError)}. This usually indicates complex expressions in aggregations that are not supported.`,
|
|
95
|
+
metadata
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
// Check for known limitations
|
|
99
|
+
const limitations = this.detectLimitations(metadata);
|
|
100
|
+
return {
|
|
101
|
+
success: true,
|
|
102
|
+
decomposedQuery: decomposed,
|
|
103
|
+
limitations: limitations.length > 0 ? limitations : undefined,
|
|
104
|
+
metadata
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
return {
|
|
109
|
+
success: false,
|
|
110
|
+
error: `Analysis failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
111
|
+
metadata
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Decomposes a JOIN + aggregation query into separate detail and aggregation queries
|
|
117
|
+
* Follows the same pattern as SelectQueryParser.parse() - throws on error
|
|
118
|
+
*
|
|
119
|
+
* @param query The query to decompose
|
|
120
|
+
* @returns The decomposed query with CTE structure
|
|
121
|
+
* @throws DecompositionError if the query cannot be decomposed or formatted
|
|
122
|
+
*/
|
|
123
|
+
decompose(query) {
|
|
124
|
+
try {
|
|
125
|
+
// Phase 1: Validate query structure
|
|
126
|
+
const metadata = this.extractMetadata(query);
|
|
127
|
+
const validationError = this.getValidationError(query, metadata);
|
|
128
|
+
if (validationError) {
|
|
129
|
+
throw new DecompositionError(validationError, query);
|
|
130
|
+
}
|
|
131
|
+
// Phase 2: Perform decomposition
|
|
132
|
+
const decomposed = this.performDecomposition(query);
|
|
133
|
+
// Phase 3: Critical validation - ensure the result can be formatted
|
|
134
|
+
try {
|
|
135
|
+
this.formatter.format(decomposed);
|
|
136
|
+
}
|
|
137
|
+
catch (formatError) {
|
|
138
|
+
throw new DecompositionError(`Decomposed query cannot be formatted: ${formatError instanceof Error ? formatError.message : String(formatError)}. ` +
|
|
139
|
+
`This usually indicates complex expressions in aggregations that are not supported.`, query, formatError instanceof Error ? formatError : undefined);
|
|
140
|
+
}
|
|
141
|
+
return decomposed;
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
if (error instanceof DecompositionError) {
|
|
145
|
+
throw error;
|
|
146
|
+
}
|
|
147
|
+
throw new DecompositionError(`Decomposition failed: ${error instanceof Error ? error.message : String(error)}`, query, error instanceof Error ? error : undefined);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Gets validation error message without throwing (for analyze method)
|
|
152
|
+
*/
|
|
153
|
+
getValidationError(query, metadata) {
|
|
154
|
+
if (!query.fromClause) {
|
|
155
|
+
return "Query does not contain FROM clause";
|
|
156
|
+
}
|
|
157
|
+
if (metadata.joinCount === 0) {
|
|
158
|
+
return "Query does not contain JOINs";
|
|
159
|
+
}
|
|
160
|
+
if (metadata.aggregationCount === 0 && !query.groupByClause) {
|
|
161
|
+
return "Query does not contain GROUP BY or aggregation functions";
|
|
162
|
+
}
|
|
163
|
+
if (metadata.hasWindowFunctions) {
|
|
164
|
+
return "Window functions are not fully supported - column references in window functions are not converted to CTE references";
|
|
165
|
+
}
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Performs the actual decomposition
|
|
170
|
+
*/
|
|
171
|
+
performDecomposition(query) {
|
|
172
|
+
// Extract columns needed for detail CTE
|
|
173
|
+
const detailColumns = this.extractDetailColumns(query);
|
|
174
|
+
// Build detail query (CTE)
|
|
175
|
+
const detailQuery = this.buildDetailQuery(query, detailColumns);
|
|
176
|
+
// Build aggregation query
|
|
177
|
+
const aggregationQuery = this.buildAggregationQuery(query);
|
|
178
|
+
// Create WITH clause
|
|
179
|
+
const withClause = new Clause_1.WithClause(false, // not recursive
|
|
180
|
+
[
|
|
181
|
+
new Clause_1.CommonTable(detailQuery, this.options.detailCTEName, null // not materialized
|
|
182
|
+
)
|
|
183
|
+
]);
|
|
184
|
+
// Combine into final query
|
|
185
|
+
aggregationQuery.withClause = withClause;
|
|
186
|
+
return aggregationQuery;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Extracts metadata about the query
|
|
190
|
+
*/
|
|
191
|
+
extractMetadata(query) {
|
|
192
|
+
const joinCount = this.countJoins(query);
|
|
193
|
+
const aggregationCount = this.countAggregationFunctions(query);
|
|
194
|
+
const hasHaving = !!query.havingClause;
|
|
195
|
+
const hasOrderBy = !!query.orderByClause;
|
|
196
|
+
const hasWindowFunctions = this.hasWindowFunctions(query);
|
|
197
|
+
const detailColumns = this.extractDetailColumnNames(query);
|
|
198
|
+
return {
|
|
199
|
+
joinCount,
|
|
200
|
+
aggregationCount,
|
|
201
|
+
detailColumns,
|
|
202
|
+
hasHaving,
|
|
203
|
+
hasOrderBy,
|
|
204
|
+
hasWindowFunctions
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Detects known limitations based on metadata
|
|
209
|
+
*/
|
|
210
|
+
detectLimitations(metadata) {
|
|
211
|
+
const limitations = [];
|
|
212
|
+
if (metadata.hasWindowFunctions && metadata.aggregationCount > 0) {
|
|
213
|
+
limitations.push("Window functions may reference original table columns instead of CTE columns");
|
|
214
|
+
}
|
|
215
|
+
if (metadata.hasHaving) {
|
|
216
|
+
limitations.push("HAVING clause column references are not converted to CTE references");
|
|
217
|
+
}
|
|
218
|
+
if (metadata.hasOrderBy) {
|
|
219
|
+
limitations.push("ORDER BY clause column references are not converted to CTE references");
|
|
220
|
+
}
|
|
221
|
+
return limitations;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Counts the number of JOINs in the query
|
|
225
|
+
*/
|
|
226
|
+
countJoins(query) {
|
|
227
|
+
var _a, _b;
|
|
228
|
+
return ((_b = (_a = query.fromClause) === null || _a === void 0 ? void 0 : _a.joins) === null || _b === void 0 ? void 0 : _b.length) || 0;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Counts aggregation functions in the query
|
|
232
|
+
*/
|
|
233
|
+
countAggregationFunctions(query) {
|
|
234
|
+
var _a;
|
|
235
|
+
let count = 0;
|
|
236
|
+
if ((_a = query.selectClause) === null || _a === void 0 ? void 0 : _a.items) {
|
|
237
|
+
for (const item of query.selectClause.items) {
|
|
238
|
+
if (this.containsAggregationFunction(item.value)) {
|
|
239
|
+
count++;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return count;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Checks if query contains window functions
|
|
247
|
+
*/
|
|
248
|
+
hasWindowFunctions(query) {
|
|
249
|
+
var _a;
|
|
250
|
+
if ((_a = query.selectClause) === null || _a === void 0 ? void 0 : _a.items) {
|
|
251
|
+
for (const item of query.selectClause.items) {
|
|
252
|
+
if (this.containsWindowFunction(item.value)) {
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Checks if an expression contains aggregation functions
|
|
261
|
+
*/
|
|
262
|
+
containsAggregationFunction(expression) {
|
|
263
|
+
if (expression instanceof ValueComponent_1.FunctionCall) {
|
|
264
|
+
const funcName = this.getFunctionName(expression).toLowerCase();
|
|
265
|
+
return ['count', 'sum', 'avg', 'min', 'max'].includes(funcName);
|
|
266
|
+
}
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Checks if an expression contains window functions
|
|
271
|
+
*/
|
|
272
|
+
containsWindowFunction(expression) {
|
|
273
|
+
if (expression instanceof ValueComponent_1.FunctionCall && expression.over) {
|
|
274
|
+
return true;
|
|
275
|
+
}
|
|
276
|
+
// Fallback: check for common window function names
|
|
277
|
+
if (expression instanceof ValueComponent_1.FunctionCall) {
|
|
278
|
+
const funcName = this.getFunctionName(expression).toLowerCase();
|
|
279
|
+
return ['row_number', 'rank', 'dense_rank', 'lead', 'lag'].includes(funcName);
|
|
280
|
+
}
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Gets function name from FunctionCall
|
|
285
|
+
*/
|
|
286
|
+
getFunctionName(func) {
|
|
287
|
+
const name = func.qualifiedName.name;
|
|
288
|
+
if (name instanceof ValueComponent_1.IdentifierString) {
|
|
289
|
+
return name.name;
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
return name.value;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Extracts detail column names for metadata
|
|
297
|
+
*/
|
|
298
|
+
extractDetailColumnNames(query) {
|
|
299
|
+
var _a, _b;
|
|
300
|
+
const columns = [];
|
|
301
|
+
// Add GROUP BY columns
|
|
302
|
+
if ((_a = query.groupByClause) === null || _a === void 0 ? void 0 : _a.grouping) {
|
|
303
|
+
for (const expr of query.groupByClause.grouping) {
|
|
304
|
+
columns.push(expr.toString());
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
// Add columns from aggregation functions
|
|
308
|
+
if ((_b = query.selectClause) === null || _b === void 0 ? void 0 : _b.items) {
|
|
309
|
+
for (const item of query.selectClause.items) {
|
|
310
|
+
if (this.containsAggregationFunction(item.value) && item.value instanceof ValueComponent_1.FunctionCall) {
|
|
311
|
+
if (item.value.argument) {
|
|
312
|
+
columns.push(item.value.argument.toString());
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return [...new Set(columns)]; // Remove duplicates
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Extracts columns needed for the detail CTE
|
|
321
|
+
*/
|
|
322
|
+
extractDetailColumns(query) {
|
|
323
|
+
var _a, _b;
|
|
324
|
+
const columns = [];
|
|
325
|
+
const columnSet = new Set();
|
|
326
|
+
// Add GROUP BY columns
|
|
327
|
+
if ((_a = query.groupByClause) === null || _a === void 0 ? void 0 : _a.grouping) {
|
|
328
|
+
for (const expr of query.groupByClause.grouping) {
|
|
329
|
+
if (expr instanceof ValueComponent_1.ColumnReference) {
|
|
330
|
+
const key = this.getColumnKey(expr);
|
|
331
|
+
if (!columnSet.has(key)) {
|
|
332
|
+
columns.push(expr);
|
|
333
|
+
columnSet.add(key);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
// Add columns from aggregation function arguments
|
|
339
|
+
if ((_b = query.selectClause) === null || _b === void 0 ? void 0 : _b.items) {
|
|
340
|
+
for (const item of query.selectClause.items) {
|
|
341
|
+
this.extractColumnsFromExpression(item.value, columns, columnSet);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
return columns;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Extracts column references from an expression
|
|
348
|
+
*/
|
|
349
|
+
extractColumnsFromExpression(expression, columns, columnSet) {
|
|
350
|
+
if (expression instanceof ValueComponent_1.FunctionCall) {
|
|
351
|
+
if (expression.argument) {
|
|
352
|
+
if (expression.argument instanceof ValueComponent_1.ColumnReference) {
|
|
353
|
+
const key = this.getColumnKey(expression.argument);
|
|
354
|
+
if (!columnSet.has(key)) {
|
|
355
|
+
columns.push(expression.argument);
|
|
356
|
+
columnSet.add(key);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
else if (expression.argument.toString() === '*') {
|
|
360
|
+
// Handle COUNT(*) by adding special marker
|
|
361
|
+
const starColumn = new ValueComponent_1.ColumnReference(null, '*');
|
|
362
|
+
const key = this.getColumnKey(starColumn);
|
|
363
|
+
if (!columnSet.has(key)) {
|
|
364
|
+
columns.push(starColumn);
|
|
365
|
+
columnSet.add(key);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
else if (expression instanceof ValueComponent_1.ColumnReference) {
|
|
371
|
+
const key = this.getColumnKey(expression);
|
|
372
|
+
if (!columnSet.has(key)) {
|
|
373
|
+
columns.push(expression);
|
|
374
|
+
columnSet.add(key);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Gets a unique key for a column reference
|
|
380
|
+
*/
|
|
381
|
+
getColumnKey(column) {
|
|
382
|
+
var _a;
|
|
383
|
+
const namespace = ((_a = column.namespaces) === null || _a === void 0 ? void 0 : _a.map(ns => ns.name).join('.')) || '';
|
|
384
|
+
const columnName = column.column.name;
|
|
385
|
+
return namespace ? `${namespace}.${columnName}` : columnName;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Builds the detail query (CTE content)
|
|
389
|
+
*/
|
|
390
|
+
buildDetailQuery(originalQuery, detailColumns) {
|
|
391
|
+
const selectItems = detailColumns.map(col => new Clause_1.SelectItem(col));
|
|
392
|
+
return new SimpleSelectQuery_1.SimpleSelectQuery({
|
|
393
|
+
selectClause: new Clause_1.SelectClause(selectItems),
|
|
394
|
+
fromClause: originalQuery.fromClause,
|
|
395
|
+
whereClause: originalQuery.whereClause
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Builds the aggregation query that references the CTE
|
|
400
|
+
*/
|
|
401
|
+
buildAggregationQuery(originalQuery) {
|
|
402
|
+
var _a, _b, _c, _d;
|
|
403
|
+
// Transform SELECT items to reference CTE columns
|
|
404
|
+
const transformedSelectItems = ((_b = (_a = originalQuery.selectClause) === null || _a === void 0 ? void 0 : _a.items) === null || _b === void 0 ? void 0 : _b.map(item => {
|
|
405
|
+
var _a;
|
|
406
|
+
const transformedExpression = this.transformExpressionForCTE(item.value);
|
|
407
|
+
return new Clause_1.SelectItem(transformedExpression, ((_a = item.identifier) === null || _a === void 0 ? void 0 : _a.name) || null);
|
|
408
|
+
})) || [];
|
|
409
|
+
// Transform GROUP BY to reference CTE columns
|
|
410
|
+
const transformedGroupBy = (_d = (_c = originalQuery.groupByClause) === null || _c === void 0 ? void 0 : _c.grouping) === null || _d === void 0 ? void 0 : _d.map(expr => {
|
|
411
|
+
return this.transformExpressionForCTE(expr);
|
|
412
|
+
});
|
|
413
|
+
// Create FROM clause that references the CTE
|
|
414
|
+
const cteFromClause = new Clause_1.FromClause(new Clause_1.SourceExpression(new Clause_1.TableSource(null, new ValueComponent_1.IdentifierString(this.options.detailCTEName)), null), null);
|
|
415
|
+
return new SimpleSelectQuery_1.SimpleSelectQuery({
|
|
416
|
+
selectClause: new Clause_1.SelectClause(transformedSelectItems),
|
|
417
|
+
fromClause: cteFromClause,
|
|
418
|
+
groupByClause: transformedGroupBy ? new Clause_1.GroupByClause(transformedGroupBy) : undefined,
|
|
419
|
+
havingClause: originalQuery.havingClause, // TODO: Transform references if needed
|
|
420
|
+
orderByClause: originalQuery.orderByClause // TODO: Transform references if needed
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Transforms an expression to reference CTE columns instead of original table columns
|
|
425
|
+
*/
|
|
426
|
+
transformExpressionForCTE(expression) {
|
|
427
|
+
if (expression instanceof ValueComponent_1.FunctionCall) {
|
|
428
|
+
// Transform aggregation function arguments
|
|
429
|
+
const transformedArg = expression.argument ?
|
|
430
|
+
(expression.argument instanceof ValueComponent_1.ColumnReference ?
|
|
431
|
+
// Convert table.column to just column for CTE reference
|
|
432
|
+
new ValueComponent_1.ColumnReference(null, expression.argument.column.name) :
|
|
433
|
+
expression.argument) : null;
|
|
434
|
+
return new ValueComponent_1.FunctionCall(expression.qualifiedName.namespaces, expression.qualifiedName.name, transformedArg, expression.over, expression.withinGroup);
|
|
435
|
+
}
|
|
436
|
+
else if (expression instanceof ValueComponent_1.ColumnReference) {
|
|
437
|
+
// Convert table.column to just column for CTE reference
|
|
438
|
+
return new ValueComponent_1.ColumnReference(null, expression.column.name);
|
|
439
|
+
}
|
|
440
|
+
return expression;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
exports.JoinAggregationDecomposer = JoinAggregationDecomposer;
|
|
444
|
+
/**
|
|
445
|
+
* Utility function to analyze a JOIN + aggregation query from SQL string (safe, no exceptions)
|
|
446
|
+
*
|
|
447
|
+
* @param sql The SQL string to parse and analyze
|
|
448
|
+
* @param options Decomposer options
|
|
449
|
+
* @returns Analysis result with success status, error information, and metadata
|
|
450
|
+
*/
|
|
451
|
+
function analyzeJoinAggregation(sql, options) {
|
|
452
|
+
try {
|
|
453
|
+
// Import using ES module syntax to avoid require issues
|
|
454
|
+
const { SelectQueryParser } = eval('require("../parsers/SelectQueryParser")');
|
|
455
|
+
const query = SelectQueryParser.parse(sql);
|
|
456
|
+
const decomposer = new JoinAggregationDecomposer(options);
|
|
457
|
+
return decomposer.analyze(query);
|
|
458
|
+
}
|
|
459
|
+
catch (error) {
|
|
460
|
+
return {
|
|
461
|
+
success: false,
|
|
462
|
+
error: `Failed to parse SQL: ${error instanceof Error ? error.message : String(error)}`,
|
|
463
|
+
metadata: {
|
|
464
|
+
joinCount: 0,
|
|
465
|
+
aggregationCount: 0,
|
|
466
|
+
detailColumns: [],
|
|
467
|
+
hasHaving: false,
|
|
468
|
+
hasOrderBy: false,
|
|
469
|
+
hasWindowFunctions: false
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Utility function to decompose a JOIN + aggregation query from SQL string
|
|
476
|
+
*
|
|
477
|
+
* @param sql The SQL string to parse and decompose
|
|
478
|
+
* @param options Decomposer options
|
|
479
|
+
* @returns The decomposed query
|
|
480
|
+
* @throws DecompositionError if parsing or decomposition fails
|
|
481
|
+
*/
|
|
482
|
+
function decomposeJoinAggregation(sql, options) {
|
|
483
|
+
try {
|
|
484
|
+
// Import using ES module syntax to avoid require issues
|
|
485
|
+
const { SelectQueryParser } = eval('require("../parsers/SelectQueryParser")');
|
|
486
|
+
const query = SelectQueryParser.parse(sql);
|
|
487
|
+
const decomposer = new JoinAggregationDecomposer(options);
|
|
488
|
+
return decomposer.decompose(query);
|
|
489
|
+
}
|
|
490
|
+
catch (error) {
|
|
491
|
+
if (error instanceof DecompositionError) {
|
|
492
|
+
throw error;
|
|
493
|
+
}
|
|
494
|
+
throw new DecompositionError(`Failed to parse SQL: ${error instanceof Error ? error.message : String(error)}`, new SimpleSelectQuery_1.SimpleSelectQuery({ selectClause: new Clause_1.SelectClause([]) }), error instanceof Error ? error : undefined);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
//# sourceMappingURL=JoinAggregationDecomposer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JoinAggregationDecomposer.js","sourceRoot":"","sources":["../../../src/transformers/JoinAggregationDecomposer.ts"],"names":[],"mappings":";;;AA6iBA,wDAwBC;AAUD,4DAoBC;AAnmBD,mEAAgE;AAChE,6CAAsK;AACtK,6DAA2G;AAC3G,iDAA8C;AAuC9C;;GAEG;AACH,MAAa,kBAAmB,SAAQ,KAAK;IACzC,YACI,OAAe,EACC,aAAgC,EAChC,KAAa;QAE7B,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,kBAAa,GAAb,aAAa,CAAmB;QAChC,UAAK,GAAL,KAAK,CAAQ;QAG7B,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACrC,CAAC;CACJ;AATD,gDASC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAa,yBAAyB;IAIlC,YAAY,UAAiC,EAAE;QAC3C,IAAI,CAAC,OAAO,GAAG;YACX,aAAa,EAAE,OAAO,CAAC,aAAa,IAAI,aAAa;SACxD,CAAC;QACF,IAAI,CAAC,SAAS,GAAG,IAAI,2BAAY,CAAC,EAAE,gBAAgB,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IACpF,CAAC;IAED;;;;;;OAMG;IACH,OAAO,CAAC,KAAwB;QAC5B,MAAM,QAAQ,GAAG,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QAE7C,IAAI,CAAC;YACD,oCAAoC;YACpC,MAAM,eAAe,GAAG,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YACjE,IAAI,eAA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N,CAAC;AACL,CAAC"}
|
|
@@ -22,6 +22,28 @@ export declare class QueryBuilder {
|
|
|
22
22
|
*/
|
|
23
23
|
static buildSimpleQuery(query: SelectQuery): SimpleSelectQuery;
|
|
24
24
|
private static buildSimpleBinaryQuery;
|
|
25
|
+
/**
|
|
26
|
+
* Extracts ORDER BY clause from the rightmost query in a binary query tree and removes it.
|
|
27
|
+
* This clarifies the semantics by moving the ORDER BY from the ambiguous position
|
|
28
|
+
* in the UNION to the explicit outer SimpleSelectQuery level.
|
|
29
|
+
*
|
|
30
|
+
* NOTE: ORDER BY in UNION context applies to the entire result set, not individual subqueries.
|
|
31
|
+
* Therefore, table prefixes (e.g., "a.column") in ORDER BY are invalid SQL and would cause
|
|
32
|
+
* syntax errors. Valid ORDER BY clauses should only reference column names without prefixes
|
|
33
|
+
* or use positional notation (ORDER BY 1, 2). Since we only process valid SQL, the current
|
|
34
|
+
* implementation correctly handles legitimate cases without additional prefix processing.
|
|
35
|
+
*
|
|
36
|
+
* @param query BinarySelectQuery to process
|
|
37
|
+
* @returns Extracted OrderByClause or null if none found
|
|
38
|
+
*/
|
|
39
|
+
private static extractAndRemoveOrderByFromBinaryQuery;
|
|
40
|
+
/**
|
|
41
|
+
* Recursively finds and removes ORDER BY from the rightmost query in a binary tree.
|
|
42
|
+
*
|
|
43
|
+
* @param query Current query being processed
|
|
44
|
+
* @returns Extracted OrderByClause or null
|
|
45
|
+
*/
|
|
46
|
+
private static findAndRemoveRightmostOrderBy;
|
|
25
47
|
/**
|
|
26
48
|
* Converts a ValuesQuery to a SimpleSelectQuery with sequentially numbered columns or user-specified columns
|
|
27
49
|
*
|
|
@@ -62,7 +62,9 @@ class QueryBuilder {
|
|
|
62
62
|
throw new Error("Unsupported query type for buildSimpleQuery");
|
|
63
63
|
}
|
|
64
64
|
static buildSimpleBinaryQuery(query) {
|
|
65
|
-
//
|
|
65
|
+
// Extract ORDER BY from the rightmost query in the binary tree and remove it
|
|
66
|
+
const extractedOrderBy = QueryBuilder.extractAndRemoveOrderByFromBinaryQuery(query);
|
|
67
|
+
// Create a subquery source from the binary query (now without ORDER BY)
|
|
66
68
|
const subQuerySource = new Clause_1.SubQuerySource(query);
|
|
67
69
|
// Create a source expression with alias
|
|
68
70
|
const sourceExpr = new Clause_1.SourceExpression(subQuerySource, new Clause_1.SourceAliasExpression("bq", null));
|
|
@@ -70,13 +72,57 @@ class QueryBuilder {
|
|
|
70
72
|
const fromClause = new Clause_1.FromClause(sourceExpr, null);
|
|
71
73
|
// Create SELECT clause with * (all columns)
|
|
72
74
|
const selectClause = QueryBuilder.createSelectAllClause();
|
|
73
|
-
// Create the final simple select query
|
|
75
|
+
// Create the final simple select query with extracted ORDER BY
|
|
74
76
|
const q = new SelectQuery_1.SimpleSelectQuery({
|
|
75
77
|
selectClause,
|
|
76
|
-
fromClause
|
|
78
|
+
fromClause,
|
|
79
|
+
orderByClause: extractedOrderBy
|
|
77
80
|
});
|
|
78
81
|
return CTENormalizer_1.CTENormalizer.normalize(q);
|
|
79
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Extracts ORDER BY clause from the rightmost query in a binary query tree and removes it.
|
|
85
|
+
* This clarifies the semantics by moving the ORDER BY from the ambiguous position
|
|
86
|
+
* in the UNION to the explicit outer SimpleSelectQuery level.
|
|
87
|
+
*
|
|
88
|
+
* NOTE: ORDER BY in UNION context applies to the entire result set, not individual subqueries.
|
|
89
|
+
* Therefore, table prefixes (e.g., "a.column") in ORDER BY are invalid SQL and would cause
|
|
90
|
+
* syntax errors. Valid ORDER BY clauses should only reference column names without prefixes
|
|
91
|
+
* or use positional notation (ORDER BY 1, 2). Since we only process valid SQL, the current
|
|
92
|
+
* implementation correctly handles legitimate cases without additional prefix processing.
|
|
93
|
+
*
|
|
94
|
+
* @param query BinarySelectQuery to process
|
|
95
|
+
* @returns Extracted OrderByClause or null if none found
|
|
96
|
+
*/
|
|
97
|
+
static extractAndRemoveOrderByFromBinaryQuery(query) {
|
|
98
|
+
return QueryBuilder.findAndRemoveRightmostOrderBy(query);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Recursively finds and removes ORDER BY from the rightmost query in a binary tree.
|
|
102
|
+
*
|
|
103
|
+
* @param query Current query being processed
|
|
104
|
+
* @returns Extracted OrderByClause or null
|
|
105
|
+
*/
|
|
106
|
+
static findAndRemoveRightmostOrderBy(query) {
|
|
107
|
+
if (query instanceof SelectQuery_1.BinarySelectQuery) {
|
|
108
|
+
// For binary queries, check right side first (rightmost takes precedence)
|
|
109
|
+
const rightOrderBy = QueryBuilder.findAndRemoveRightmostOrderBy(query.right);
|
|
110
|
+
if (rightOrderBy) {
|
|
111
|
+
return rightOrderBy;
|
|
112
|
+
}
|
|
113
|
+
// If no ORDER BY on right side, check left side
|
|
114
|
+
return QueryBuilder.findAndRemoveRightmostOrderBy(query.left);
|
|
115
|
+
}
|
|
116
|
+
else if (query instanceof SelectQuery_1.SimpleSelectQuery) {
|
|
117
|
+
// Extract ORDER BY from SimpleSelectQuery and remove it
|
|
118
|
+
const orderBy = query.orderByClause;
|
|
119
|
+
if (orderBy) {
|
|
120
|
+
query.orderByClause = null;
|
|
121
|
+
return orderBy;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
80
126
|
/**
|
|
81
127
|
* Converts a ValuesQuery to a SimpleSelectQuery with sequentially numbered columns or user-specified columns
|
|
82
128
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryBuilder.js","sourceRoot":"","sources":["../../../src/transformers/QueryBuilder.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"QueryBuilder.js","sourceRoot":"","sources":["../../../src/transformers/QueryBuilder.ts"],"names":[],"mappings":";;;AAAA,6CAA4O;AAC5O,uDAAoD;AACpD,6DAA6E;AAC7E,iEAA8D;AAC9D,uDAAuG;AACvG,iDAA8C;AAC9C,mDAAgD;AAChD,iEAA8D;AAC9D,uDAAoD;A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