rawsql-ts 0.11.19-beta → 0.11.21-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/README.md +62 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +23 -23
- package/dist/esm/index.min.js.map +3 -3
- package/dist/esm/src/index.d.ts +2 -0
- package/dist/esm/src/index.js +2 -0
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/parsers/WithClauseParser.d.ts +51 -0
- package/dist/esm/src/parsers/WithClauseParser.js +51 -2
- package/dist/esm/src/parsers/WithClauseParser.js.map +1 -1
- package/dist/esm/src/transformers/SelectableColumnCollector.d.ts +94 -9
- package/dist/esm/src/transformers/SelectableColumnCollector.js +227 -40
- package/dist/esm/src/transformers/SelectableColumnCollector.js.map +1 -1
- package/dist/esm/tsconfig.browser.tsbuildinfo +1 -1
- package/dist/index.min.js +23 -23
- package/dist/index.min.js.map +3 -3
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +4 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/parsers/WithClauseParser.d.ts +51 -0
- package/dist/src/parsers/WithClauseParser.js +51 -2
- package/dist/src/parsers/WithClauseParser.js.map +1 -1
- package/dist/src/transformers/SelectableColumnCollector.d.ts +94 -9
- package/dist/src/transformers/SelectableColumnCollector.js +225 -38
- package/dist/src/transformers/SelectableColumnCollector.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/esm/src/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './parsers/SelectQueryParser';
|
|
2
2
|
export * from './parsers/InsertQueryParser';
|
|
3
|
+
export * from './parsers/WithClauseParser';
|
|
3
4
|
export * from './models/BinarySelectQuery';
|
|
4
5
|
export * from './models/SelectQuery';
|
|
5
6
|
export * from './models/ValueComponent';
|
|
@@ -20,6 +21,7 @@ export * from './transformers/PostgresJsonQueryBuilder';
|
|
|
20
21
|
export * from './transformers/QueryBuilder';
|
|
21
22
|
export * from './transformers/SelectValueCollector';
|
|
22
23
|
export * from './transformers/SelectableColumnCollector';
|
|
24
|
+
export { DuplicateDetectionMode } from './transformers/SelectableColumnCollector';
|
|
23
25
|
export * from './transformers/TableColumnResolver';
|
|
24
26
|
export * from './transformers/TableSourceCollector';
|
|
25
27
|
export * from './transformers/JsonMappingConverter';
|
package/dist/esm/src/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Entry point for rawsql-ts package
|
|
2
2
|
export * from './parsers/SelectQueryParser';
|
|
3
3
|
export * from './parsers/InsertQueryParser';
|
|
4
|
+
export * from './parsers/WithClauseParser';
|
|
4
5
|
export * from './models/BinarySelectQuery';
|
|
5
6
|
export * from './models/SelectQuery';
|
|
6
7
|
export * from './models/ValueComponent';
|
|
@@ -21,6 +22,7 @@ export * from './transformers/PostgresJsonQueryBuilder';
|
|
|
21
22
|
export * from './transformers/QueryBuilder'; // old name:QueryConverter
|
|
22
23
|
export * from './transformers/SelectValueCollector';
|
|
23
24
|
export * from './transformers/SelectableColumnCollector';
|
|
25
|
+
export { DuplicateDetectionMode } from './transformers/SelectableColumnCollector';
|
|
24
26
|
export * from './transformers/TableColumnResolver';
|
|
25
27
|
export * from './transformers/TableSourceCollector';
|
|
26
28
|
export * from './transformers/JsonMappingConverter';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAE3C,cAAc,4BAA4B,CAAC;AAC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Ac,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AAGrC,oEAAoE"}
|
|
@@ -1,7 +1,58 @@
|
|
|
1
1
|
import { WithClause } from "../models/Clause";
|
|
2
2
|
import { Lexeme } from "../models/Lexeme";
|
|
3
|
+
/**
|
|
4
|
+
* Parser for SQL WITH clauses (Common Table Expressions - CTEs).
|
|
5
|
+
* Parses only the WITH clause portion of SQL, not the entire query.
|
|
6
|
+
*
|
|
7
|
+
* **Note**: For most use cases, use `SelectQueryParser` which provides more comprehensive SQL parsing.
|
|
8
|
+
* This parser should only be used for the special case where you need to analyze only the WITH clause portion.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Parses only the WITH clause, not the following SELECT
|
|
13
|
+
* const sql = "WITH recursive_cte AS (SELECT 1 as n UNION SELECT n+1 FROM recursive_cte WHERE n < 10)";
|
|
14
|
+
* const withClause = WithClauseParser.parse(sql);
|
|
15
|
+
* console.log(withClause.recursive); // true
|
|
16
|
+
* console.log(withClause.tables.length); // 1
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
3
19
|
export declare class WithClauseParser {
|
|
20
|
+
/**
|
|
21
|
+
* Parses a SQL string containing only a WITH clause into a WithClause AST.
|
|
22
|
+
* The input should contain only the WITH clause, not the subsequent main query.
|
|
23
|
+
*
|
|
24
|
+
* @param query - The SQL string containing only the WITH clause
|
|
25
|
+
* @returns The parsed WithClause object
|
|
26
|
+
* @throws Error if the syntax is invalid or there are unexpected tokens after the WITH clause
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* // Correct: Only the WITH clause
|
|
31
|
+
* const sql = "WITH users_data AS (SELECT id, name FROM users)";
|
|
32
|
+
* const withClause = WithClauseParser.parse(sql);
|
|
33
|
+
*
|
|
34
|
+
* // Error: Contains SELECT after WITH clause
|
|
35
|
+
* // const badSql = "WITH users_data AS (SELECT id, name FROM users) SELECT * FROM users_data";
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
4
38
|
static parse(query: string): WithClause;
|
|
39
|
+
/**
|
|
40
|
+
* Parses a WITH clause from an array of lexemes starting at the specified index.
|
|
41
|
+
*
|
|
42
|
+
* @param lexemes - Array of lexemes to parse from
|
|
43
|
+
* @param index - Starting index in the lexemes array
|
|
44
|
+
* @returns Object containing the parsed WithClause and the new index position
|
|
45
|
+
* @throws Error if the syntax is invalid or WITH keyword is not found
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const tokenizer = new SqlTokenizer("WITH cte AS (SELECT 1)");
|
|
50
|
+
* const lexemes = tokenizer.readLexmes();
|
|
51
|
+
* const result = WithClauseParser.parseFromLexeme(lexemes, 0);
|
|
52
|
+
* console.log(result.value.tables.length); // 1
|
|
53
|
+
* console.log(result.newIndex); // position after the WITH clause
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
5
56
|
static parseFromLexeme(lexemes: Lexeme[], index: number): {
|
|
6
57
|
value: WithClause;
|
|
7
58
|
newIndex: number;
|
|
@@ -2,8 +2,41 @@ import { WithClause } from "../models/Clause";
|
|
|
2
2
|
import { TokenType } from "../models/Lexeme";
|
|
3
3
|
import { SqlTokenizer } from "./SqlTokenizer";
|
|
4
4
|
import { CommonTableParser } from "./CommonTableParser";
|
|
5
|
+
/**
|
|
6
|
+
* Parser for SQL WITH clauses (Common Table Expressions - CTEs).
|
|
7
|
+
* Parses only the WITH clause portion of SQL, not the entire query.
|
|
8
|
+
*
|
|
9
|
+
* **Note**: For most use cases, use `SelectQueryParser` which provides more comprehensive SQL parsing.
|
|
10
|
+
* This parser should only be used for the special case where you need to analyze only the WITH clause portion.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // Parses only the WITH clause, not the following SELECT
|
|
15
|
+
* const sql = "WITH recursive_cte AS (SELECT 1 as n UNION SELECT n+1 FROM recursive_cte WHERE n < 10)";
|
|
16
|
+
* const withClause = WithClauseParser.parse(sql);
|
|
17
|
+
* console.log(withClause.recursive); // true
|
|
18
|
+
* console.log(withClause.tables.length); // 1
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
5
21
|
export class WithClauseParser {
|
|
6
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Parses a SQL string containing only a WITH clause into a WithClause AST.
|
|
24
|
+
* The input should contain only the WITH clause, not the subsequent main query.
|
|
25
|
+
*
|
|
26
|
+
* @param query - The SQL string containing only the WITH clause
|
|
27
|
+
* @returns The parsed WithClause object
|
|
28
|
+
* @throws Error if the syntax is invalid or there are unexpected tokens after the WITH clause
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* // Correct: Only the WITH clause
|
|
33
|
+
* const sql = "WITH users_data AS (SELECT id, name FROM users)";
|
|
34
|
+
* const withClause = WithClauseParser.parse(sql);
|
|
35
|
+
*
|
|
36
|
+
* // Error: Contains SELECT after WITH clause
|
|
37
|
+
* // const badSql = "WITH users_data AS (SELECT id, name FROM users) SELECT * FROM users_data";
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
7
40
|
static parse(query) {
|
|
8
41
|
const tokenizer = new SqlTokenizer(query); // Initialize tokenizer
|
|
9
42
|
const lexemes = tokenizer.readLexmes(); // Get tokens
|
|
@@ -15,7 +48,23 @@ export class WithClauseParser {
|
|
|
15
48
|
}
|
|
16
49
|
return result.value;
|
|
17
50
|
}
|
|
18
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Parses a WITH clause from an array of lexemes starting at the specified index.
|
|
53
|
+
*
|
|
54
|
+
* @param lexemes - Array of lexemes to parse from
|
|
55
|
+
* @param index - Starting index in the lexemes array
|
|
56
|
+
* @returns Object containing the parsed WithClause and the new index position
|
|
57
|
+
* @throws Error if the syntax is invalid or WITH keyword is not found
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const tokenizer = new SqlTokenizer("WITH cte AS (SELECT 1)");
|
|
62
|
+
* const lexemes = tokenizer.readLexmes();
|
|
63
|
+
* const result = WithClauseParser.parseFromLexeme(lexemes, 0);
|
|
64
|
+
* console.log(result.value.tables.length); // 1
|
|
65
|
+
* console.log(result.newIndex); // position after the WITH clause
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
19
68
|
static parseFromLexeme(lexemes, index) {
|
|
20
69
|
let idx = index;
|
|
21
70
|
// Capture comments from the WITH keyword
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WithClauseParser.js","sourceRoot":"","sources":["../../../../src/parsers/WithClauseParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAU,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,MAAM,OAAO,gBAAgB;IACzB
|
|
1
|
+
{"version":3,"file":"WithClauseParser.js","sourceRoot":"","sources":["../../../../src/parsers/WithClauseParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAU,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,gBAAgB;IACzB;;;;;;;;;;;;;;;;;OAiBG;IACI,MAAM,CAAC,KAAK,CAAC,KAAa;QAC7B,MAAM,SAAS,GAAG,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,uBAAuB;QAClE,MAAM,OAAO,GAAG,SAAS,CAAC,UAAU,EAAE,CAAC,CAAC,aAAa;QAErD,QAAQ;QACR,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AAG,CAAC,CAAC;QACjE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAC5B,GAAG,GAAG,QAAQ,CAAC,QAAQ,CAAC;QAExB,mCAAmC;QACnC,OAAO,GAAG,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YACnE,GAAG,EAAE,CAAC,CAAC,aAAa;YAEpB,wDAAwD;YACxD,yEAAyE;YACzE,MAAM,SAAS,GAAG,iBAAiB,CAAC,eAAe,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;YAClE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;YAC7B,GAAG,GAAG,SAAS,CAAC,QAAQ,CAAC;QAC7B,CAAC;QAED,mCAAmC;QACnC,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QACrD,UAAU,CAAC,QAAQ,GAAG,iBAAiB,CAAC;QAExC,OAAO;YACH,KAAK,EAAE,UAAU;YACjB,QAAQ,EAAE,GAAG;SAChB,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -20,28 +20,58 @@ import { SqlComponent, SqlComponentVisitor } from "../models/SqlComponent";
|
|
|
20
20
|
import { ValueComponent } from "../models/ValueComponent";
|
|
21
21
|
import { TableColumnResolver } from "./TableColumnResolver";
|
|
22
22
|
/**
|
|
23
|
-
* A visitor that collects all ColumnReference instances from
|
|
23
|
+
* A visitor that collects all ColumnReference instances from SQL query structures.
|
|
24
24
|
* This visitor scans through all clauses and collects all unique ColumnReference objects.
|
|
25
|
-
* It
|
|
25
|
+
* It supports both regular column collection and upstream column collection for maximum
|
|
26
|
+
* search conditions in DynamicQuery scenarios.
|
|
26
27
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
28
|
+
* Supported query types:
|
|
29
|
+
* - SimpleSelectQuery: Basic SELECT queries with all standard clauses
|
|
30
|
+
* - BinarySelectQuery: UNION, INTERSECT, EXCEPT queries (collects from both sides)
|
|
31
|
+
* - Common Table Expressions (CTEs) within queries
|
|
32
|
+
* - Subqueries and nested queries
|
|
30
33
|
*
|
|
31
34
|
* Behavioral notes:
|
|
32
|
-
* -
|
|
35
|
+
* - Collects column references to tables defined in the root FROM/JOIN clauses
|
|
33
36
|
* - For aliased columns (e.g., 'title as name'), collects both the original column
|
|
34
37
|
* reference ('title') AND the alias ('name') to enable complete dependency tracking
|
|
38
|
+
* - When upstream option is enabled, collects all available columns from upstream sources
|
|
39
|
+
* (CTEs, subqueries, and tables) for maximum search conditions in DynamicQuery
|
|
40
|
+
* - Automatically removes duplicates based on the specified duplicate detection mode
|
|
35
41
|
*
|
|
36
42
|
* Use cases:
|
|
37
43
|
* - Dependency analysis and schema migration tools
|
|
38
|
-
* - Column usage tracking
|
|
44
|
+
* - Column usage tracking across complex queries including unions and CTEs
|
|
39
45
|
* - Security analysis for column-level access control
|
|
46
|
+
* - DynamicQuery maximum search condition column discovery
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* // Basic usage - collect only referenced columns
|
|
51
|
+
* const collector = new SelectableColumnCollector();
|
|
52
|
+
* const columns = collector.collect(query);
|
|
53
|
+
*
|
|
54
|
+
* // With upstream collection for DynamicQuery
|
|
55
|
+
* const upstreamCollector = new SelectableColumnCollector(
|
|
56
|
+
* null, false, DuplicateDetectionMode.ColumnNameOnly,
|
|
57
|
+
* { upstream: true }
|
|
58
|
+
* );
|
|
59
|
+
* const allColumns = upstreamCollector.collect(query);
|
|
60
|
+
*
|
|
61
|
+
* // Works with union queries and CTEs
|
|
62
|
+
* const unionQuery = SelectQueryParser.parse(`
|
|
63
|
+
* SELECT name, email FROM users
|
|
64
|
+
* UNION
|
|
65
|
+
* SELECT name, email FROM customers
|
|
66
|
+
* `);
|
|
67
|
+
* const unionColumns = collector.collect(unionQuery);
|
|
68
|
+
* ```
|
|
40
69
|
*/
|
|
41
70
|
export declare class SelectableColumnCollector implements SqlComponentVisitor<void> {
|
|
42
71
|
private handlers;
|
|
43
72
|
private selectValues;
|
|
44
73
|
private visitedNodes;
|
|
74
|
+
private uniqueKeys;
|
|
45
75
|
private isRootVisit;
|
|
46
76
|
private tableColumnResolver;
|
|
47
77
|
private commonTableCollector;
|
|
@@ -57,10 +87,28 @@ export declare class SelectableColumnCollector implements SqlComponentVisitor<vo
|
|
|
57
87
|
* @param {DuplicateDetectionMode} [duplicateDetection=DuplicateDetectionMode.ColumnNameOnly] - Specifies the duplicate detection mode: 'columnNameOnly' (default, only column name is used), or 'fullName' (table name + column name).
|
|
58
88
|
* @param {Object} [options={}] - Additional options for the collector.
|
|
59
89
|
* @param {boolean} [options.ignoreCaseAndUnderscore=false] - If true, column names are compared without considering case and underscores.
|
|
90
|
+
* @param {boolean} [options.upstream=false] - If true, collect all columns available from upstream sources for maximum search conditions in DynamicQuery.
|
|
60
91
|
*/
|
|
61
92
|
constructor(tableColumnResolver?: TableColumnResolver | null, includeWildCard?: boolean, duplicateDetection?: DuplicateDetectionMode, options?: {
|
|
62
93
|
ignoreCaseAndUnderscore?: boolean;
|
|
94
|
+
upstream?: boolean;
|
|
63
95
|
});
|
|
96
|
+
/**
|
|
97
|
+
* Initialize instance properties.
|
|
98
|
+
*/
|
|
99
|
+
private initializeProperties;
|
|
100
|
+
/**
|
|
101
|
+
* Initialize the handler map for different SQL component types.
|
|
102
|
+
*/
|
|
103
|
+
private initializeHandlers;
|
|
104
|
+
/**
|
|
105
|
+
* Initialize handlers for SQL clause types.
|
|
106
|
+
*/
|
|
107
|
+
private initializeClauseHandlers;
|
|
108
|
+
/**
|
|
109
|
+
* Initialize handlers for value component types.
|
|
110
|
+
*/
|
|
111
|
+
private initializeValueComponentHandlers;
|
|
64
112
|
getValues(): {
|
|
65
113
|
name: string;
|
|
66
114
|
value: ValueComponent;
|
|
@@ -75,10 +123,18 @@ export declare class SelectableColumnCollector implements SqlComponentVisitor<vo
|
|
|
75
123
|
private reset;
|
|
76
124
|
/**
|
|
77
125
|
* Add a select value as unique, according to the duplicate detection option.
|
|
78
|
-
*
|
|
79
|
-
* If duplicateDetection is 'fullName', both table and column name are checked.
|
|
126
|
+
* Uses efficient Set-based duplicate detection for better performance.
|
|
80
127
|
*/
|
|
81
128
|
private addSelectValueAsUnique;
|
|
129
|
+
/**
|
|
130
|
+
* Generate a unique key based on the duplicate detection mode.
|
|
131
|
+
*/
|
|
132
|
+
private generateUniqueKey;
|
|
133
|
+
/**
|
|
134
|
+
* Normalize column name based on options.
|
|
135
|
+
* Ensures safe string handling to prevent injection attacks.
|
|
136
|
+
*/
|
|
137
|
+
private normalizeColumnName;
|
|
82
138
|
/**
|
|
83
139
|
* Main entry point for the visitor pattern.
|
|
84
140
|
* Implements the shallow visit pattern to distinguish between root and recursive visits.
|
|
@@ -93,6 +149,10 @@ export declare class SelectableColumnCollector implements SqlComponentVisitor<vo
|
|
|
93
149
|
* Process a SimpleSelectQuery to collect ColumnReferences from all its clauses
|
|
94
150
|
*/
|
|
95
151
|
private visitSimpleSelectQuery;
|
|
152
|
+
/**
|
|
153
|
+
* Process a BinarySelectQuery (UNION, INTERSECT, EXCEPT) to collect ColumnReferences from both sides
|
|
154
|
+
*/
|
|
155
|
+
private visitBinarySelectQuery;
|
|
96
156
|
private visitSelectClause;
|
|
97
157
|
private visitFromClause;
|
|
98
158
|
private visitWhereClause;
|
|
@@ -118,4 +178,29 @@ export declare class SelectableColumnCollector implements SqlComponentVisitor<vo
|
|
|
118
178
|
private visitArrayQueryExpression;
|
|
119
179
|
private visitValueList;
|
|
120
180
|
private visitPartitionByClause;
|
|
181
|
+
/**
|
|
182
|
+
* Collect all upstream columns available for DynamicQuery maximum search conditions.
|
|
183
|
+
* This includes columns from CTEs, subqueries, and tables that can be used for filtering.
|
|
184
|
+
*/
|
|
185
|
+
private collectUpstreamColumns;
|
|
186
|
+
/**
|
|
187
|
+
* Collect upstream columns from a specific source (table, subquery, or CTE).
|
|
188
|
+
*/
|
|
189
|
+
private collectUpstreamColumnsFromSource;
|
|
190
|
+
/**
|
|
191
|
+
* Collect upstream columns from a table source using table column resolver.
|
|
192
|
+
*/
|
|
193
|
+
private collectUpstreamColumnsFromTable;
|
|
194
|
+
/**
|
|
195
|
+
* Collect upstream columns from a subquery source.
|
|
196
|
+
*/
|
|
197
|
+
private collectUpstreamColumnsFromSubquery;
|
|
198
|
+
/**
|
|
199
|
+
* Collect upstream columns from a CTE.
|
|
200
|
+
*/
|
|
201
|
+
private collectUpstreamColumnsFromCTE;
|
|
202
|
+
/**
|
|
203
|
+
* Find a CTE by name in the common tables.
|
|
204
|
+
*/
|
|
205
|
+
private findCTEByName;
|
|
121
206
|
}
|