rawsql-ts 0.27.0 → 0.29.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/esm/index.min.js +1 -1
- package/dist/esm/index.min.js.map +4 -4
- package/dist/esm/transformers/ConditionDeduplicationOptimizer.d.ts +22 -0
- package/dist/esm/transformers/ConditionDeduplicationOptimizer.js +198 -0
- package/dist/esm/transformers/ConditionDeduplicationOptimizer.js.map +1 -0
- package/dist/esm/transformers/ConditionOptimization.d.ts +35 -1
- package/dist/esm/transformers/ConditionOptimization.js +359 -24
- package/dist/esm/transformers/ConditionOptimization.js.map +1 -1
- package/dist/esm/transformers/ParameterConditionPlacementOptimizer.d.ts +13 -0
- package/dist/esm/transformers/ParameterConditionPlacementOptimizer.js +246 -27
- package/dist/esm/transformers/ParameterConditionPlacementOptimizer.js.map +1 -1
- package/dist/esm/transformers/StaticPredicatePlacementOptimizer.d.ts +12 -0
- package/dist/esm/transformers/StaticPredicatePlacementOptimizer.js +211 -18
- package/dist/esm/transformers/StaticPredicatePlacementOptimizer.js.map +1 -1
- package/dist/esm/transformers/TopLevelAndConditionDeduper.d.ts +10 -0
- package/dist/esm/transformers/TopLevelAndConditionDeduper.js +66 -0
- package/dist/esm/transformers/TopLevelAndConditionDeduper.js.map +1 -0
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/transformers/ConditionDeduplicationOptimizer.d.ts +22 -0
- package/dist/src/transformers/ConditionOptimization.d.ts +35 -1
- package/dist/src/transformers/ParameterConditionPlacementOptimizer.d.ts +13 -0
- package/dist/src/transformers/StaticPredicatePlacementOptimizer.d.ts +12 -0
- package/dist/src/transformers/TopLevelAndConditionDeduper.d.ts +10 -0
- package/dist/transformers/ConditionDeduplicationOptimizer.js +202 -0
- package/dist/transformers/ConditionDeduplicationOptimizer.js.map +1 -0
- package/dist/transformers/ConditionOptimization.js +362 -22
- package/dist/transformers/ConditionOptimization.js.map +1 -1
- package/dist/transformers/ParameterConditionPlacementOptimizer.js +245 -26
- package/dist/transformers/ParameterConditionPlacementOptimizer.js.map +1 -1
- package/dist/transformers/StaticPredicatePlacementOptimizer.js +210 -17
- package/dist/transformers/StaticPredicatePlacementOptimizer.js.map +1 -1
- package/dist/transformers/TopLevelAndConditionDeduper.js +72 -0
- package/dist/transformers/TopLevelAndConditionDeduper.js.map +1 -0
- package/dist/tsconfig.browser.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SelectQuery } from "../models/SelectQuery";
|
|
2
|
+
import { SqlComponentFormatOptions } from "./SqlComponentFormatter";
|
|
3
|
+
export interface ConditionDeduplicationApplied {
|
|
4
|
+
kind: "dedupe_condition";
|
|
5
|
+
conditionSql: string;
|
|
6
|
+
scopeId: string;
|
|
7
|
+
reason: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ConditionDeduplicationResult {
|
|
10
|
+
/** API output shape review: this phase mutates and returns the model only; ConditionOptimization remains responsible for compatibility sql output. */
|
|
11
|
+
query: SelectQuery | null;
|
|
12
|
+
applied: readonly ConditionDeduplicationApplied[];
|
|
13
|
+
}
|
|
14
|
+
export declare class ConditionDeduplicationOptimizer {
|
|
15
|
+
private visited;
|
|
16
|
+
private applied;
|
|
17
|
+
optimize(query: SelectQuery | null, options: SqlComponentFormatOptions): ConditionDeduplicationResult;
|
|
18
|
+
private visitSelectQuery;
|
|
19
|
+
private visitSourceExpression;
|
|
20
|
+
private visitValueComponent;
|
|
21
|
+
private dedupeCondition;
|
|
22
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { SelectQuery, SimpleSelectQuery } from "../models/SelectQuery";
|
|
2
2
|
import { ParameterConditionMove, ParameterConditionOptimizationError, ParameterConditionOptimizationOptions, ParameterConditionOptimizationWarning, ParameterConditionSkipped } from "./ParameterConditionPlacementOptimizer";
|
|
3
3
|
import { StaticPredicateMove, StaticPredicatePlacementError, StaticPredicatePlacementWarning, StaticPredicateSkipped } from "./StaticPredicatePlacementOptimizer";
|
|
4
|
+
import { ConditionDeduplicationApplied } from "./ConditionDeduplicationOptimizer";
|
|
4
5
|
import { OptionalConditionPruningParameters } from "./PruneOptionalConditionBranches";
|
|
5
6
|
export type ConditionOptimizationInput = string | SelectQuery | SimpleSelectQuery;
|
|
6
|
-
export type ConditionOptimizationPhaseKind = "sssql_optional_condition" | "parameter_condition_placement" | "static_predicate_placement";
|
|
7
|
+
export type ConditionOptimizationPhaseKind = "sssql_optional_condition" | "parameter_condition_placement" | "static_predicate_placement" | "condition_deduplication";
|
|
7
8
|
export interface ConditionOptimizationOptions extends ParameterConditionOptimizationOptions {
|
|
8
9
|
/**
|
|
9
10
|
* Explicit opt-in values for SSSQL optional branch pruning.
|
|
@@ -19,6 +20,7 @@ export interface ConditionOptimizationPhaseSummary {
|
|
|
19
20
|
warningCount: number;
|
|
20
21
|
errorCount: number;
|
|
21
22
|
}
|
|
23
|
+
export type ConditionOptimizationSkipDisposition = "blocked" | "unchanged" | "ignored";
|
|
22
24
|
export interface SssqlOptionalConditionApplied {
|
|
23
25
|
phaseKind: "sssql_optional_condition";
|
|
24
26
|
kind: "prune_optional_branch" | "refresh_optional_branch";
|
|
@@ -34,16 +36,21 @@ export interface SssqlOptionalConditionSkipped {
|
|
|
34
36
|
parameterName: string;
|
|
35
37
|
code: string;
|
|
36
38
|
reason: string;
|
|
39
|
+
skipDisposition: ConditionOptimizationSkipDisposition;
|
|
37
40
|
}
|
|
38
41
|
export type ConditionOptimizationApplied = SssqlOptionalConditionApplied | (ParameterConditionMove & {
|
|
39
42
|
phaseKind: "parameter_condition_placement";
|
|
40
43
|
}) | (StaticPredicateMove & {
|
|
41
44
|
phaseKind: "static_predicate_placement";
|
|
45
|
+
}) | (ConditionDeduplicationApplied & {
|
|
46
|
+
phaseKind: "condition_deduplication";
|
|
42
47
|
});
|
|
43
48
|
export type ConditionOptimizationSkipped = SssqlOptionalConditionSkipped | (ParameterConditionSkipped & {
|
|
44
49
|
phaseKind: "parameter_condition_placement";
|
|
50
|
+
skipDisposition: ConditionOptimizationSkipDisposition;
|
|
45
51
|
}) | (StaticPredicateSkipped & {
|
|
46
52
|
phaseKind: "static_predicate_placement";
|
|
53
|
+
skipDisposition: ConditionOptimizationSkipDisposition;
|
|
47
54
|
});
|
|
48
55
|
export type ConditionOptimizationWarning = (ParameterConditionOptimizationWarning & {
|
|
49
56
|
phaseKind: ConditionOptimizationPhaseKind;
|
|
@@ -61,6 +68,31 @@ export interface ConditionOptimizationSafety {
|
|
|
61
68
|
dryRun: boolean;
|
|
62
69
|
formatterGeneratedSource: boolean;
|
|
63
70
|
}
|
|
71
|
+
export interface ConditionOptimizationSourceFilterProbe {
|
|
72
|
+
kind: "source_filter_probe";
|
|
73
|
+
source: string;
|
|
74
|
+
sourceAlias: string;
|
|
75
|
+
predicate: string;
|
|
76
|
+
suggestedSql: string;
|
|
77
|
+
reason: string;
|
|
78
|
+
}
|
|
79
|
+
export interface ConditionOptimizationSkippedProbe {
|
|
80
|
+
kind: "source_filter_probe_skipped";
|
|
81
|
+
source?: string;
|
|
82
|
+
sourceAlias?: string;
|
|
83
|
+
predicate: string;
|
|
84
|
+
code: string;
|
|
85
|
+
reason: string;
|
|
86
|
+
}
|
|
87
|
+
export interface ConditionOptimizationDiagnostics {
|
|
88
|
+
/**
|
|
89
|
+
* Probe diagnostics are collected after SSSQL optional pruning/refresh and
|
|
90
|
+
* before parameter/static placement phases, so they describe the pre-placement
|
|
91
|
+
* source-filter debugging snapshot rather than the final rewritten query.
|
|
92
|
+
*/
|
|
93
|
+
probes: readonly ConditionOptimizationSourceFilterProbe[];
|
|
94
|
+
skippedProbes: readonly ConditionOptimizationSkippedProbe[];
|
|
95
|
+
}
|
|
64
96
|
export interface ConditionOptimizationResult {
|
|
65
97
|
ok: boolean;
|
|
66
98
|
sql: string;
|
|
@@ -71,6 +103,8 @@ export interface ConditionOptimizationResult {
|
|
|
71
103
|
warnings: readonly ConditionOptimizationWarning[];
|
|
72
104
|
errors: readonly ConditionOptimizationError[];
|
|
73
105
|
safety: ConditionOptimizationSafety;
|
|
106
|
+
/** API output shape review: diagnostics is additive; sql/query keep their existing output shape for callers. */
|
|
107
|
+
diagnostics?: ConditionOptimizationDiagnostics;
|
|
74
108
|
}
|
|
75
109
|
export declare const planConditionOptimization: (input: ConditionOptimizationInput, options?: ConditionOptimizationOptions) => ConditionOptimizationResult;
|
|
76
110
|
export declare const optimizeConditions: (input: ConditionOptimizationInput, options?: ConditionOptimizationOptions) => ConditionOptimizationResult;
|
|
@@ -75,6 +75,8 @@ export declare class ParameterConditionPlacementOptimizer {
|
|
|
75
75
|
private resolveUpstreamQuery;
|
|
76
76
|
private resolveUnionTarget;
|
|
77
77
|
private resolveTargetColumns;
|
|
78
|
+
private resolveBaseTableJoinOnTarget;
|
|
79
|
+
private appendJoinOnCondition;
|
|
78
80
|
private resolveTargetColumnByOutputIndex;
|
|
79
81
|
private resolveDeepestBranchTarget;
|
|
80
82
|
private verifyColumnResolvableInQuery;
|
|
@@ -83,7 +85,10 @@ export declare class ParameterConditionPlacementOptimizer {
|
|
|
83
85
|
private resolveColumnSourceAlias;
|
|
84
86
|
private rebaseCondition;
|
|
85
87
|
private getSourceBindings;
|
|
88
|
+
private isBaseTableBinding;
|
|
89
|
+
private isInnerJoin;
|
|
86
90
|
private findNullableSideBoundary;
|
|
91
|
+
private hasLaterJoinThatNullsPriorSources;
|
|
87
92
|
private hasOuterJoin;
|
|
88
93
|
private hasDistinctOnBoundary;
|
|
89
94
|
private hasOrdinaryDistinct;
|
|
@@ -91,6 +96,14 @@ export declare class ParameterConditionPlacementOptimizer {
|
|
|
91
96
|
private collectUnionBranches;
|
|
92
97
|
private resolveUnionOutputIndex;
|
|
93
98
|
private collectSelectOutputs;
|
|
99
|
+
private collectDirectOutputMatches;
|
|
100
|
+
private hasExplicitOutputMatch;
|
|
101
|
+
private inferWildcardOutputMatches;
|
|
102
|
+
private inferWildcardTargetColumn;
|
|
103
|
+
private resolveWildcardColumnFromBinding;
|
|
104
|
+
private collectSourceOutputMatches;
|
|
105
|
+
private createColumnForBinding;
|
|
106
|
+
private createInferredOutputColumn;
|
|
94
107
|
private resolveSourceQueryForColumns;
|
|
95
108
|
private findCte;
|
|
96
109
|
private countTableSourceReferences;
|
|
@@ -72,6 +72,8 @@ export declare class StaticPredicatePlacementOptimizer {
|
|
|
72
72
|
private resolveUpstreamQuery;
|
|
73
73
|
private resolveUnionTarget;
|
|
74
74
|
private resolveTargetColumns;
|
|
75
|
+
private resolveBaseTableJoinOnTarget;
|
|
76
|
+
private appendJoinOnPredicate;
|
|
75
77
|
private resolveDeepestBranchTarget;
|
|
76
78
|
private verifyColumnResolvableInQuery;
|
|
77
79
|
private isGroupKeyColumn;
|
|
@@ -79,6 +81,8 @@ export declare class StaticPredicatePlacementOptimizer {
|
|
|
79
81
|
private resolveColumnSourceAlias;
|
|
80
82
|
private rebasePredicate;
|
|
81
83
|
private getSourceBindings;
|
|
84
|
+
private isBaseTableBinding;
|
|
85
|
+
private isInnerJoin;
|
|
82
86
|
private findNullableSideBoundary;
|
|
83
87
|
private hasLaterJoinThatNullsPriorSources;
|
|
84
88
|
private hasOuterJoin;
|
|
@@ -89,6 +93,14 @@ export declare class StaticPredicatePlacementOptimizer {
|
|
|
89
93
|
private resolveUnionOutputIndex;
|
|
90
94
|
private resolveTargetColumnByOutputIndex;
|
|
91
95
|
private collectSelectOutputs;
|
|
96
|
+
private collectDirectOutputMatches;
|
|
97
|
+
private hasExplicitOutputMatch;
|
|
98
|
+
private inferWildcardOutputMatches;
|
|
99
|
+
private inferWildcardTargetColumn;
|
|
100
|
+
private resolveWildcardColumnFromBinding;
|
|
101
|
+
private collectSourceOutputMatches;
|
|
102
|
+
private createColumnForBinding;
|
|
103
|
+
private createInferredOutputColumn;
|
|
92
104
|
private resolveSourceQueryForColumns;
|
|
93
105
|
private findCte;
|
|
94
106
|
private countTableSourceReferences;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SimpleSelectQuery } from "../models/SelectQuery";
|
|
2
|
+
import { ValueComponent } from "../models/ValueComponent";
|
|
3
|
+
import { SqlComponentFormatOptions } from "./SqlComponentFormatter";
|
|
4
|
+
export interface TopLevelAndConditionDeduplicationResult {
|
|
5
|
+
expression: ValueComponent;
|
|
6
|
+
removedConditionSql: readonly string[];
|
|
7
|
+
}
|
|
8
|
+
export declare const dedupeTopLevelAndConditionsWithMetadata: (expression: ValueComponent, options: SqlComponentFormatOptions) => TopLevelAndConditionDeduplicationResult;
|
|
9
|
+
export declare const dedupeTopLevelAndConditions: (expression: ValueComponent, options: SqlComponentFormatOptions) => ValueComponent;
|
|
10
|
+
export declare const dedupeWhereTopLevelAndConditions: (query: SimpleSelectQuery, options: SqlComponentFormatOptions) => void;
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConditionDeduplicationOptimizer = void 0;
|
|
4
|
+
const Clause_1 = require("../models/Clause");
|
|
5
|
+
const SelectQuery_1 = require("../models/SelectQuery");
|
|
6
|
+
const ValueComponent_1 = require("../models/ValueComponent");
|
|
7
|
+
const TopLevelAndConditionDeduper_1 = require("./TopLevelAndConditionDeduper");
|
|
8
|
+
class ConditionDeduplicationOptimizer {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.visited = new WeakSet();
|
|
11
|
+
this.applied = [];
|
|
12
|
+
}
|
|
13
|
+
optimize(query, options) {
|
|
14
|
+
this.visited = new WeakSet();
|
|
15
|
+
this.applied = [];
|
|
16
|
+
if (!query) {
|
|
17
|
+
return { query: null, applied: [] };
|
|
18
|
+
}
|
|
19
|
+
this.visitSelectQuery(query, "root", options);
|
|
20
|
+
return {
|
|
21
|
+
query,
|
|
22
|
+
applied: [...this.applied]
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
visitSelectQuery(query, scopeId, options) {
|
|
26
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
27
|
+
if (this.visited.has(query)) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
this.visited.add(query);
|
|
31
|
+
if (query instanceof SelectQuery_1.BinarySelectQuery) {
|
|
32
|
+
this.visitSelectQuery(query.left, `${scopeId}.left`, options);
|
|
33
|
+
this.visitSelectQuery(query.right, `${scopeId}.right`, options);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (!(query instanceof SelectQuery_1.SimpleSelectQuery)) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
for (const cte of (_b = (_a = query.withClause) === null || _a === void 0 ? void 0 : _a.tables) !== null && _b !== void 0 ? _b : []) {
|
|
40
|
+
const cteQuery = cte.query;
|
|
41
|
+
if (cteQuery instanceof SelectQuery_1.SimpleSelectQuery || cteQuery instanceof SelectQuery_1.BinarySelectQuery) {
|
|
42
|
+
this.visitSelectQuery(cteQuery, `${scopeId}.cte:${cte.getSourceAliasName()}`, options);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
for (const item of query.selectClause.items) {
|
|
46
|
+
this.visitValueComponent(item.value, `${scopeId}.select`, options);
|
|
47
|
+
}
|
|
48
|
+
if (query.fromClause) {
|
|
49
|
+
this.visitSourceExpression(query.fromClause.source, `${scopeId}.from`, options);
|
|
50
|
+
for (const join of (_c = query.fromClause.joins) !== null && _c !== void 0 ? _c : []) {
|
|
51
|
+
const joinScope = `${scopeId}.join:${(_d = join.source.getAliasName()) !== null && _d !== void 0 ? _d : "unknown"}`;
|
|
52
|
+
this.visitSourceExpression(join.source, joinScope, options);
|
|
53
|
+
if (join.condition instanceof Clause_1.JoinOnClause) {
|
|
54
|
+
join.condition.condition = this.dedupeCondition(join.condition.condition, `${joinScope}.on`, "Removed a duplicate top-level AND condition from a JOIN ON clause.", options);
|
|
55
|
+
this.visitValueComponent(join.condition.condition, `${joinScope}.on`, options);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (query.whereClause) {
|
|
60
|
+
query.whereClause = new Clause_1.WhereClause(this.dedupeCondition(query.whereClause.condition, `${scopeId}.where`, "Removed a duplicate top-level AND condition from a WHERE clause.", options));
|
|
61
|
+
this.visitValueComponent(query.whereClause.condition, `${scopeId}.where`, options);
|
|
62
|
+
}
|
|
63
|
+
if (query.havingClause) {
|
|
64
|
+
query.havingClause = new Clause_1.HavingClause(this.dedupeCondition(query.havingClause.condition, `${scopeId}.having`, "Removed a duplicate top-level AND condition from a HAVING clause.", options));
|
|
65
|
+
this.visitValueComponent(query.havingClause.condition, `${scopeId}.having`, options);
|
|
66
|
+
}
|
|
67
|
+
for (const item of (_f = (_e = query.groupByClause) === null || _e === void 0 ? void 0 : _e.grouping) !== null && _f !== void 0 ? _f : []) {
|
|
68
|
+
this.visitValueComponent(item, `${scopeId}.group_by`, options);
|
|
69
|
+
}
|
|
70
|
+
for (const item of (_h = (_g = query.orderByClause) === null || _g === void 0 ? void 0 : _g.order) !== null && _h !== void 0 ? _h : []) {
|
|
71
|
+
if (item instanceof Clause_1.OrderByItem) {
|
|
72
|
+
this.visitValueComponent(item.value, `${scopeId}.order_by`, options);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
this.visitValueComponent(item, `${scopeId}.order_by`, options);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
visitSourceExpression(source, scopeId, options) {
|
|
80
|
+
const datasource = source.datasource;
|
|
81
|
+
if (datasource instanceof Clause_1.SubQuerySource) {
|
|
82
|
+
this.visitSelectQuery(datasource.query, `${scopeId}.subquery`, options);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (datasource instanceof Clause_1.ParenSource) {
|
|
86
|
+
const nested = datasource.source;
|
|
87
|
+
if (nested instanceof Clause_1.SubQuerySource) {
|
|
88
|
+
this.visitSelectQuery(nested.query, `${scopeId}.subquery`, options);
|
|
89
|
+
}
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (datasource instanceof Clause_1.FunctionSource && datasource.argument) {
|
|
93
|
+
this.visitValueComponent(datasource.argument, `${scopeId}.function`, options);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
visitValueComponent(value, scopeId, options) {
|
|
97
|
+
if (this.visited.has(value)) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
this.visited.add(value);
|
|
101
|
+
if (value instanceof ValueComponent_1.InlineQuery) {
|
|
102
|
+
this.visitSelectQuery(value.selectQuery, `${scopeId}.inline_query`, options);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (value instanceof ValueComponent_1.ArrayQueryExpression) {
|
|
106
|
+
this.visitSelectQuery(value.query, `${scopeId}.array_query`, options);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (value instanceof ValueComponent_1.ParenExpression) {
|
|
110
|
+
this.visitValueComponent(value.expression, scopeId, options);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (value instanceof ValueComponent_1.BinaryExpression) {
|
|
114
|
+
this.visitValueComponent(value.left, scopeId, options);
|
|
115
|
+
this.visitValueComponent(value.right, scopeId, options);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (value instanceof ValueComponent_1.UnaryExpression) {
|
|
119
|
+
this.visitValueComponent(value.expression, scopeId, options);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (value instanceof ValueComponent_1.FunctionCall) {
|
|
123
|
+
if (value.argument) {
|
|
124
|
+
this.visitValueComponent(value.argument, scopeId, options);
|
|
125
|
+
}
|
|
126
|
+
if (value.filterCondition) {
|
|
127
|
+
this.visitValueComponent(value.filterCondition, `${scopeId}.filter`, options);
|
|
128
|
+
}
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (value instanceof ValueComponent_1.CastExpression) {
|
|
132
|
+
this.visitValueComponent(value.input, scopeId, options);
|
|
133
|
+
if (value.castType.argument) {
|
|
134
|
+
this.visitValueComponent(value.castType.argument, scopeId, options);
|
|
135
|
+
}
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (value instanceof ValueComponent_1.CaseExpression) {
|
|
139
|
+
if (value.condition) {
|
|
140
|
+
this.visitValueComponent(value.condition, scopeId, options);
|
|
141
|
+
}
|
|
142
|
+
for (const item of value.switchCase.cases) {
|
|
143
|
+
this.visitValueComponent(item.key, scopeId, options);
|
|
144
|
+
this.visitValueComponent(item.value, scopeId, options);
|
|
145
|
+
}
|
|
146
|
+
if (value.switchCase.elseValue) {
|
|
147
|
+
this.visitValueComponent(value.switchCase.elseValue, scopeId, options);
|
|
148
|
+
}
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (value instanceof ValueComponent_1.BetweenExpression) {
|
|
152
|
+
this.visitValueComponent(value.expression, scopeId, options);
|
|
153
|
+
this.visitValueComponent(value.lower, scopeId, options);
|
|
154
|
+
this.visitValueComponent(value.upper, scopeId, options);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (value instanceof ValueComponent_1.JsonPredicateExpression) {
|
|
158
|
+
this.visitValueComponent(value.expression, scopeId, options);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (value instanceof ValueComponent_1.ArrayExpression) {
|
|
162
|
+
this.visitValueComponent(value.expression, scopeId, options);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (value instanceof ValueComponent_1.ArrayIndexExpression) {
|
|
166
|
+
this.visitValueComponent(value.array, scopeId, options);
|
|
167
|
+
this.visitValueComponent(value.index, scopeId, options);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (value instanceof ValueComponent_1.ArraySliceExpression) {
|
|
171
|
+
this.visitValueComponent(value.array, scopeId, options);
|
|
172
|
+
if (value.startIndex) {
|
|
173
|
+
this.visitValueComponent(value.startIndex, scopeId, options);
|
|
174
|
+
}
|
|
175
|
+
if (value.endIndex) {
|
|
176
|
+
this.visitValueComponent(value.endIndex, scopeId, options);
|
|
177
|
+
}
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (value instanceof ValueComponent_1.ValueList || value instanceof ValueComponent_1.TupleExpression) {
|
|
181
|
+
value.values.forEach(item => this.visitValueComponent(item, scopeId, options));
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (value instanceof ValueComponent_1.TypeValue && value.argument) {
|
|
185
|
+
this.visitValueComponent(value.argument, scopeId, options);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
dedupeCondition(condition, scopeId, reason, options) {
|
|
189
|
+
const result = (0, TopLevelAndConditionDeduper_1.dedupeTopLevelAndConditionsWithMetadata)(condition, options);
|
|
190
|
+
for (const conditionSql of result.removedConditionSql) {
|
|
191
|
+
this.applied.push({
|
|
192
|
+
kind: "dedupe_condition",
|
|
193
|
+
conditionSql,
|
|
194
|
+
scopeId,
|
|
195
|
+
reason
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
return result.expression;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
exports.ConditionDeduplicationOptimizer = ConditionDeduplicationOptimizer;
|
|
202
|
+
//# sourceMappingURL=ConditionDeduplicationOptimizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConditionDeduplicationOptimizer.js","sourceRoot":"","sources":["../../src/transformers/ConditionDeduplicationOptimizer.ts"],"names":[],"mappings":";;;AAAA,6CAS0B;AAC1B,uDAA0F;AAC1F,6DAkBkC;AAElC,+EAAwF;AAexF,MAAa,+BAA+B;IAA5C;QACY,YAAO,GAAG,IAAI,OAAO,EAAU,CAAC;QAChC,YAAO,GAAoC,EAAE,CAAC;IA6O1D,CAAC;IA3OU,QAAQ,CACX,KAAyB,EACzB,OAAkC;QAElC,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,EAAU,CAAC;QACrC,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAElB,IAAI,C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