@devrev/meerkat-core 0.0.112 → 0.0.116
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/package.json +1 -1
- package/src/ast-builder/ast-builder.d.ts +3 -1
- package/src/ast-builder/ast-builder.js +18 -15
- package/src/ast-builder/ast-builder.js.map +1 -1
- package/src/cube-filter-transformer/base-condition-builder/base-condition-builder.d.ts +37 -15
- package/src/cube-filter-transformer/base-condition-builder/base-condition-builder.js +48 -15
- package/src/cube-filter-transformer/base-condition-builder/base-condition-builder.js.map +1 -1
- package/src/cube-filter-transformer/contains/contains.d.ts +3 -9
- package/src/cube-filter-transformer/contains/contains.js +8 -12
- package/src/cube-filter-transformer/contains/contains.js.map +1 -1
- package/src/cube-filter-transformer/equals/equals-array.js +7 -11
- package/src/cube-filter-transformer/equals/equals-array.js.map +1 -1
- package/src/cube-filter-transformer/equals/equals.js +5 -5
- package/src/cube-filter-transformer/equals/equals.js.map +1 -1
- package/src/cube-filter-transformer/factory.d.ts +3 -2
- package/src/cube-filter-transformer/factory.js +23 -23
- package/src/cube-filter-transformer/factory.js.map +1 -1
- package/src/cube-filter-transformer/gt/gt.js +4 -4
- package/src/cube-filter-transformer/gt/gt.js.map +1 -1
- package/src/cube-filter-transformer/gte/gte.js +4 -4
- package/src/cube-filter-transformer/gte/gte.js.map +1 -1
- package/src/cube-filter-transformer/in/in.js +7 -11
- package/src/cube-filter-transformer/in/in.js.map +1 -1
- package/src/cube-filter-transformer/in-date-range/in-date-range.js +4 -4
- package/src/cube-filter-transformer/in-date-range/in-date-range.js.map +1 -1
- package/src/cube-filter-transformer/lt/lt.js +4 -4
- package/src/cube-filter-transformer/lt/lt.js.map +1 -1
- package/src/cube-filter-transformer/lte/lte.js +4 -4
- package/src/cube-filter-transformer/lte/lte.js.map +1 -1
- package/src/cube-filter-transformer/not-In-date-range/not-In-date-range.js +3 -3
- package/src/cube-filter-transformer/not-In-date-range/not-In-date-range.js.map +1 -1
- package/src/cube-filter-transformer/not-contains/not-contains.d.ts +3 -9
- package/src/cube-filter-transformer/not-contains/not-contains.js +8 -12
- package/src/cube-filter-transformer/not-contains/not-contains.js.map +1 -1
- package/src/cube-filter-transformer/not-equals/not-equals-array.js +2 -2
- package/src/cube-filter-transformer/not-equals/not-equals-array.js.map +1 -1
- package/src/cube-filter-transformer/not-equals/not-equals.js +5 -5
- package/src/cube-filter-transformer/not-equals/not-equals.js.map +1 -1
- package/src/cube-filter-transformer/not-in/not-in.js +32 -11
- package/src/cube-filter-transformer/not-in/not-in.js.map +1 -1
- package/src/cube-filter-transformer/not-set/not-set.js +5 -8
- package/src/cube-filter-transformer/not-set/not-set.js.map +1 -1
- package/src/cube-filter-transformer/set/set.js +5 -8
- package/src/cube-filter-transformer/set/set.js.map +1 -1
- package/src/cube-filter-transformer/sql-expression/sql-expression-parser.d.ts +2 -1
- package/src/cube-filter-transformer/sql-expression/sql-expression-parser.js +10 -18
- package/src/cube-filter-transformer/sql-expression/sql-expression-parser.js.map +1 -1
- package/src/cube-group-by-transformer/cube-group-by-transformer.d.ts +2 -1
- package/src/cube-group-by-transformer/cube-group-by-transformer.js +2 -8
- package/src/cube-group-by-transformer/cube-group-by-transformer.js.map +1 -1
- package/src/cube-measure-transformer/cube-measure-transformer.d.ts +4 -2
- package/src/cube-measure-transformer/cube-measure-transformer.js +16 -30
- package/src/cube-measure-transformer/cube-measure-transformer.js.map +1 -1
- package/src/cube-order-by-transformer/cube-order-by-transformer.d.ts +3 -2
- package/src/cube-order-by-transformer/cube-order-by-transformer.js +3 -9
- package/src/cube-order-by-transformer/cube-order-by-transformer.js.map +1 -1
- package/src/filter-params/filter-params-ast.d.ts +2 -1
- package/src/filter-params/filter-params-ast.js +2 -1
- package/src/filter-params/filter-params-ast.js.map +1 -1
- package/src/get-filter-params-sql/get-filter-params-sql.d.ts +5 -3
- package/src/get-filter-params-sql/get-filter-params-sql.js +2 -2
- package/src/get-filter-params-sql/get-filter-params-sql.js.map +1 -1
- package/src/get-final-base-sql/get-final-base-sql.d.ts +3 -1
- package/src/get-final-base-sql/get-final-base-sql.js +3 -1
- package/src/get-final-base-sql/get-final-base-sql.js.map +1 -1
- package/src/get-wrapped-base-query-with-projections/get-aliased-columns-from-filters.d.ts +7 -3
- package/src/get-wrapped-base-query-with-projections/get-aliased-columns-from-filters.js +11 -14
- package/src/get-wrapped-base-query-with-projections/get-aliased-columns-from-filters.js.map +1 -1
- package/src/get-wrapped-base-query-with-projections/get-projection-clause.d.ts +2 -1
- package/src/get-wrapped-base-query-with-projections/get-projection-clause.js +5 -11
- package/src/get-wrapped-base-query-with-projections/get-projection-clause.js.map +1 -1
- package/src/get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections.d.ts +3 -1
- package/src/get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections.js +3 -2
- package/src/get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections.js.map +1 -1
- package/src/joins/joins.d.ts +22 -0
- package/src/joins/joins.js +60 -8
- package/src/joins/joins.js.map +1 -1
- package/src/member-formatters/get-alias.d.ts +97 -7
- package/src/member-formatters/get-alias.js +131 -17
- package/src/member-formatters/get-alias.js.map +1 -1
- package/src/member-formatters/index.d.ts +2 -2
- package/src/member-formatters/index.js +5 -1
- package/src/member-formatters/index.js.map +1 -1
- package/src/member-formatters/member-key-to-safe-key.d.ts +17 -1
- package/src/member-formatters/member-key-to-safe-key.js +15 -1
- package/src/member-formatters/member-key-to-safe-key.js.map +1 -1
- package/src/resolution/generators/generate-resolution-join-paths.js +7 -7
- package/src/resolution/generators/generate-resolution-join-paths.js.map +1 -1
- package/src/resolution/generators/generate-resolution-schemas.d.ts +1 -1
- package/src/resolution/generators/generate-resolution-schemas.js +5 -10
- package/src/resolution/generators/generate-resolution-schemas.js.map +1 -1
- package/src/resolution/generators/generate-resolved-dimensions.js +3 -2
- package/src/resolution/generators/generate-resolved-dimensions.js.map +1 -1
- package/src/resolution/generators/generate-row-number-sql.js +2 -1
- package/src/resolution/generators/generate-row-number-sql.js.map +1 -1
- package/src/resolution/resolution.d.ts +1 -1
- package/src/resolution/resolution.js +20 -21
- package/src/resolution/resolution.js.map +1 -1
- package/src/resolution/steps/apply-aliases-step.js +9 -5
- package/src/resolution/steps/apply-aliases-step.js.map +1 -1
- package/src/resolution/steps/apply-sql-overrides.d.ts +2 -3
- package/src/resolution/steps/apply-sql-overrides.js +6 -5
- package/src/resolution/steps/apply-sql-overrides.js.map +1 -1
- package/src/resolution/steps/resolution-step.js +6 -7
- package/src/resolution/steps/resolution-step.js.map +1 -1
- package/src/utils/meerkat-placeholder-replacer.d.ts +2 -1
- package/src/utils/meerkat-placeholder-replacer.js +4 -9
- package/src/utils/meerkat-placeholder-replacer.js.map +1 -1
|
@@ -5,7 +5,7 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const filter_params_ast_1 = require("../filter-params/filter-params-ast");
|
|
6
6
|
const get_filter_params_sql_1 = require("../get-filter-params-sql/get-filter-params-sql");
|
|
7
7
|
const get_wrapped_base_query_with_projections_1 = require("../get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections");
|
|
8
|
-
const getFinalBaseSQL = ({ query, getQueryOutput, tableSchema, }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
8
|
+
const getFinalBaseSQL = ({ query, getQueryOutput, tableSchema, config, }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
9
9
|
/**
|
|
10
10
|
* Apply transformation to the supplied base query.
|
|
11
11
|
* This involves updating the filter placeholder with the actual filter values.
|
|
@@ -15,12 +15,14 @@ const getFinalBaseSQL = ({ query, getQueryOutput, tableSchema, }) => tslib_1.__a
|
|
|
15
15
|
tableSchema,
|
|
16
16
|
filterType: 'BASE_FILTER',
|
|
17
17
|
getQueryOutput,
|
|
18
|
+
config,
|
|
18
19
|
});
|
|
19
20
|
const baseSQL = (0, filter_params_ast_1.applyFilterParamsToBaseSQL)(tableSchema.sql, baseFilterParamsSQL);
|
|
20
21
|
const baseSQLWithFilterProjection = (0, get_wrapped_base_query_with_projections_1.getWrappedBaseQueryWithProjections)({
|
|
21
22
|
baseQuery: baseSQL,
|
|
22
23
|
tableSchema,
|
|
23
24
|
query: query,
|
|
25
|
+
config,
|
|
24
26
|
});
|
|
25
27
|
return baseSQLWithFilterProjection;
|
|
26
28
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-final-base-sql.js","sourceRoot":"","sources":["../../../../meerkat-core/src/get-final-base-sql/get-final-base-sql.ts"],"names":[],"mappings":";;;;AAAA,0EAAgF;AAChF,0FAAoF;AACpF,gJAAwI;
|
|
1
|
+
{"version":3,"file":"get-final-base-sql.js","sourceRoot":"","sources":["../../../../meerkat-core/src/get-final-base-sql/get-final-base-sql.ts"],"names":[],"mappings":";;;;AAAA,0EAAgF;AAChF,0FAAoF;AACpF,gJAAwI;AAKjI,MAAM,eAAe,GAAG,CAAO,EACpC,KAAK,EACL,cAAc,EACd,WAAW,EACX,MAAM,GAMP,EAAE,EAAE;IACH;;;OAGG;IACH,MAAM,mBAAmB,GAAG,MAAM,IAAA,0CAAkB,EAAC;QACnD,KAAK,EAAE,KAAK;QACZ,WAAW;QACX,UAAU,EAAE,aAAa;QACzB,cAAc;QACd,MAAM;KACP,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,IAAA,8CAA0B,EACxC,WAAW,CAAC,GAAG,EACf,mBAAmB,CACpB,CAAC;IACF,MAAM,2BAA2B,GAAG,IAAA,4EAAkC,EAAC;QACrE,SAAS,EAAE,OAAO;QAClB,WAAW;QACX,KAAK,EAAE,KAAK;QACZ,MAAM;KACP,CAAC,CAAC;IACH,OAAO,2BAA2B,CAAC;AACrC,CAAC,CAAA,CAAC;AAjCW,QAAA,eAAe,mBAiC1B"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { QueryOptions } from '../member-formatters/get-alias';
|
|
1
2
|
import { MeerkatQueryFilter, Query, TableSchema } from '../types/cube-types';
|
|
2
3
|
import { Modifier } from './types';
|
|
3
|
-
export declare const getDimensionProjection: ({ key, tableSchema, modifiers, query, }: {
|
|
4
|
+
export declare const getDimensionProjection: ({ key, tableSchema, modifiers, query, config, }: {
|
|
4
5
|
key: string;
|
|
5
6
|
tableSchema: TableSchema;
|
|
6
7
|
modifiers: Modifier[];
|
|
7
8
|
query: Query;
|
|
9
|
+
config: QueryOptions;
|
|
8
10
|
}) => {
|
|
9
11
|
sql: undefined;
|
|
10
12
|
foundMember: undefined;
|
|
@@ -14,10 +16,11 @@ export declare const getDimensionProjection: ({ key, tableSchema, modifiers, que
|
|
|
14
16
|
foundMember: import("../types/cube-types").Dimension;
|
|
15
17
|
aliasKey: string;
|
|
16
18
|
};
|
|
17
|
-
export declare const getFilterMeasureProjection: ({ key, tableSchema, measures, }: {
|
|
19
|
+
export declare const getFilterMeasureProjection: ({ key, tableSchema, measures, config, }: {
|
|
18
20
|
key: string;
|
|
19
21
|
tableSchema: TableSchema;
|
|
20
22
|
measures: string[];
|
|
23
|
+
config: QueryOptions;
|
|
21
24
|
}) => {
|
|
22
25
|
sql: undefined;
|
|
23
26
|
foundMember: undefined;
|
|
@@ -27,9 +30,10 @@ export declare const getFilterMeasureProjection: ({ key, tableSchema, measures,
|
|
|
27
30
|
foundMember: import("../types/cube-types").Measure;
|
|
28
31
|
aliasKey: string;
|
|
29
32
|
};
|
|
30
|
-
export declare const getAliasedColumnsFromFilters: ({ meerkatFilters, tableSchema, aliasedColumnSet, query, }: {
|
|
33
|
+
export declare const getAliasedColumnsFromFilters: ({ meerkatFilters, tableSchema, aliasedColumnSet, query, config, }: {
|
|
31
34
|
meerkatFilters?: MeerkatQueryFilter[] | undefined;
|
|
32
35
|
tableSchema: TableSchema;
|
|
33
36
|
aliasedColumnSet: Set<string>;
|
|
34
37
|
query: Query;
|
|
38
|
+
config: QueryOptions;
|
|
35
39
|
}) => string;
|
|
@@ -5,7 +5,7 @@ const get_alias_1 = require("../member-formatters/get-alias");
|
|
|
5
5
|
const split_into_data_source_and_fields_1 = require("../member-formatters/split-into-data-source-and-fields");
|
|
6
6
|
const find_in_table_schema_1 = require("../utils/find-in-table-schema");
|
|
7
7
|
const sql_expression_modifiers_1 = require("./sql-expression-modifiers");
|
|
8
|
-
const getDimensionProjection = ({ key, tableSchema, modifiers, query, }) => {
|
|
8
|
+
const getDimensionProjection = ({ key, tableSchema, modifiers, query, config, }) => {
|
|
9
9
|
// Find the table access key
|
|
10
10
|
const [tableName, measureWithoutTable] = (0, split_into_data_source_and_fields_1.splitIntoDataSourceAndFields)(key);
|
|
11
11
|
const foundMember = (0, find_in_table_schema_1.findInDimensionSchema)(measureWithoutTable, tableSchema);
|
|
@@ -25,16 +25,12 @@ const getDimensionProjection = ({ key, tableSchema, modifiers, query, }) => {
|
|
|
25
25
|
sqlExpression: foundMember.sql,
|
|
26
26
|
query,
|
|
27
27
|
});
|
|
28
|
-
const aliasKey = (0, get_alias_1.
|
|
29
|
-
name: key,
|
|
30
|
-
tableSchema,
|
|
31
|
-
aliasContext: { isAstIdentifier: false },
|
|
32
|
-
});
|
|
28
|
+
const aliasKey = (0, get_alias_1.getAliasForSQL)(key, tableSchema, config);
|
|
33
29
|
// Add the alias key to the set. So we have a reference to all the previously selected members.
|
|
34
30
|
return { sql: `${modifiedSql} AS ${aliasKey}`, foundMember, aliasKey };
|
|
35
31
|
};
|
|
36
32
|
exports.getDimensionProjection = getDimensionProjection;
|
|
37
|
-
const getFilterMeasureProjection = ({ key, tableSchema, measures, }) => {
|
|
33
|
+
const getFilterMeasureProjection = ({ key, tableSchema, measures, config, }) => {
|
|
38
34
|
const [tableName, measureWithoutTable] = (0, split_into_data_source_and_fields_1.splitIntoDataSourceAndFields)(key);
|
|
39
35
|
const foundMember = (0, find_in_table_schema_1.findInMeasureSchema)(measureWithoutTable, tableSchema);
|
|
40
36
|
const isMeasure = measures.includes(key);
|
|
@@ -48,15 +44,11 @@ const getFilterMeasureProjection = ({ key, tableSchema, measures, }) => {
|
|
|
48
44
|
aliasKey: undefined,
|
|
49
45
|
};
|
|
50
46
|
}
|
|
51
|
-
const aliasKey = (0, get_alias_1.
|
|
52
|
-
name: key,
|
|
53
|
-
tableSchema,
|
|
54
|
-
aliasContext: { isAstIdentifier: false },
|
|
55
|
-
});
|
|
47
|
+
const aliasKey = (0, get_alias_1.getAliasForSQL)(key, tableSchema, config);
|
|
56
48
|
return { sql: `${key} AS ${aliasKey}`, foundMember, aliasKey };
|
|
57
49
|
};
|
|
58
50
|
exports.getFilterMeasureProjection = getFilterMeasureProjection;
|
|
59
|
-
const getFilterProjections = ({ member, tableSchema, measures, query, }) => {
|
|
51
|
+
const getFilterProjections = ({ member, tableSchema, measures, query, config, }) => {
|
|
60
52
|
const [, memberWithoutTable] = (0, split_into_data_source_and_fields_1.splitIntoDataSourceAndFields)(member);
|
|
61
53
|
const isDimension = (0, find_in_table_schema_1.findInDimensionSchema)(memberWithoutTable, tableSchema);
|
|
62
54
|
if (isDimension) {
|
|
@@ -65,6 +57,7 @@ const getFilterProjections = ({ member, tableSchema, measures, query, }) => {
|
|
|
65
57
|
tableSchema,
|
|
66
58
|
modifiers: [],
|
|
67
59
|
query,
|
|
60
|
+
config,
|
|
68
61
|
});
|
|
69
62
|
}
|
|
70
63
|
const isMeasure = (0, find_in_table_schema_1.findInMeasureSchema)(memberWithoutTable, tableSchema);
|
|
@@ -73,6 +66,7 @@ const getFilterProjections = ({ member, tableSchema, measures, query, }) => {
|
|
|
73
66
|
key: member,
|
|
74
67
|
tableSchema,
|
|
75
68
|
measures,
|
|
69
|
+
config,
|
|
76
70
|
});
|
|
77
71
|
}
|
|
78
72
|
return {
|
|
@@ -81,7 +75,7 @@ const getFilterProjections = ({ member, tableSchema, measures, query, }) => {
|
|
|
81
75
|
aliasKey: undefined,
|
|
82
76
|
};
|
|
83
77
|
};
|
|
84
|
-
const getAliasedColumnsFromFilters = ({ meerkatFilters, tableSchema, aliasedColumnSet, query, }) => {
|
|
78
|
+
const getAliasedColumnsFromFilters = ({ meerkatFilters, tableSchema, aliasedColumnSet, query, config, }) => {
|
|
85
79
|
const parts = [];
|
|
86
80
|
const { measures } = query;
|
|
87
81
|
meerkatFilters === null || meerkatFilters === void 0 ? void 0 : meerkatFilters.forEach((filter) => {
|
|
@@ -92,6 +86,7 @@ const getAliasedColumnsFromFilters = ({ meerkatFilters, tableSchema, aliasedColu
|
|
|
92
86
|
tableSchema,
|
|
93
87
|
aliasedColumnSet,
|
|
94
88
|
query,
|
|
89
|
+
config,
|
|
95
90
|
});
|
|
96
91
|
if (sql) {
|
|
97
92
|
parts.push(sql);
|
|
@@ -104,6 +99,7 @@ const getAliasedColumnsFromFilters = ({ meerkatFilters, tableSchema, aliasedColu
|
|
|
104
99
|
meerkatFilters: filter.or,
|
|
105
100
|
aliasedColumnSet,
|
|
106
101
|
query,
|
|
102
|
+
config,
|
|
107
103
|
});
|
|
108
104
|
if (sql) {
|
|
109
105
|
parts.push(sql);
|
|
@@ -115,6 +111,7 @@ const getAliasedColumnsFromFilters = ({ meerkatFilters, tableSchema, aliasedColu
|
|
|
115
111
|
tableSchema,
|
|
116
112
|
measures,
|
|
117
113
|
query,
|
|
114
|
+
config,
|
|
118
115
|
});
|
|
119
116
|
if (!foundMember || aliasedColumnSet.has(aliasKey)) {
|
|
120
117
|
// If the selected member is not found in the table schema or if it is already selected, continue.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-aliased-columns-from-filters.js","sourceRoot":"","sources":["../../../../meerkat-core/src/get-wrapped-base-query-with-projections/get-aliased-columns-from-filters.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"get-aliased-columns-from-filters.js","sourceRoot":"","sources":["../../../../meerkat-core/src/get-wrapped-base-query-with-projections/get-aliased-columns-from-filters.ts"],"names":[],"mappings":";;;AAAA,8DAGwC;AACxC,8GAAsG;AAEtG,wEAGuC;AACvC,yEAAsE;AAG/D,MAAM,sBAAsB,GAAG,CAAC,EACrC,GAAG,EACH,WA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,GAAG,GAAG,SAAS,CAAC;YACtB,IAAI,GAAG,EAAE;gBACP,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;aACjB;SACF;IACH,CAAC,CAAC,CAAC;IACH,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC,CAAC;AArEW,QAAA,4BAA4B,gCAqEvC"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
import { QueryOptions } from '../member-formatters/get-alias';
|
|
1
2
|
import { Query, TableSchema } from '../types/cube-types';
|
|
2
|
-
export declare const getProjectionClause: (query: Query, tableSchema: TableSchema, aliasedColumnSet: Set<string
|
|
3
|
+
export declare const getProjectionClause: (query: Query, tableSchema: TableSchema, aliasedColumnSet: Set<string>, config: QueryOptions) => string;
|
|
@@ -14,7 +14,7 @@ const memberClauseAggregator = ({ member, aliasedColumnSet, acc, sql, }) => {
|
|
|
14
14
|
acc.push(sql);
|
|
15
15
|
return acc;
|
|
16
16
|
};
|
|
17
|
-
const getProjectionClause = (query, tableSchema, aliasedColumnSet) => {
|
|
17
|
+
const getProjectionClause = (query, tableSchema, aliasedColumnSet, config) => {
|
|
18
18
|
const { measures, dimensions = [] } = query;
|
|
19
19
|
const filteredDimensions = dimensions.filter((dimension) => {
|
|
20
20
|
const [dimensionDataSource] = (0, split_into_data_source_and_fields_1.splitIntoDataSourceAndFields)(dimension);
|
|
@@ -30,13 +30,10 @@ const getProjectionClause = (query, tableSchema, aliasedColumnSet) => {
|
|
|
30
30
|
tableSchema,
|
|
31
31
|
modifiers: sql_expression_modifiers_1.MODIFIERS,
|
|
32
32
|
query,
|
|
33
|
+
config,
|
|
33
34
|
});
|
|
34
35
|
return memberClauseAggregator({
|
|
35
|
-
member: (0, get_alias_1.
|
|
36
|
-
name: member,
|
|
37
|
-
tableSchema,
|
|
38
|
-
aliasContext: { isAstIdentifier: false },
|
|
39
|
-
}),
|
|
36
|
+
member: (0, get_alias_1.getAliasForSQL)(member, tableSchema, config),
|
|
40
37
|
aliasedColumnSet,
|
|
41
38
|
acc,
|
|
42
39
|
currentIndex,
|
|
@@ -50,6 +47,7 @@ const getProjectionClause = (query, tableSchema, aliasedColumnSet) => {
|
|
|
50
47
|
key: member,
|
|
51
48
|
tableSchema,
|
|
52
49
|
measures,
|
|
50
|
+
config,
|
|
53
51
|
});
|
|
54
52
|
return memberClauseAggregator({
|
|
55
53
|
member,
|
|
@@ -70,11 +68,7 @@ const getProjectionClause = (query, tableSchema, aliasedColumnSet) => {
|
|
|
70
68
|
const columnsUsedInMeasures = (0, cube_measure_transformer_1.getAllColumnUsedInMeasures)(usedMeasureObjects, tableSchema);
|
|
71
69
|
let columnsUsedInMeasuresInProjection = '';
|
|
72
70
|
columnsUsedInMeasures.forEach((column, index) => {
|
|
73
|
-
const safeKey = (0, get_alias_1.
|
|
74
|
-
name: column,
|
|
75
|
-
tableSchema,
|
|
76
|
-
aliasContext: { isAstIdentifier: false },
|
|
77
|
-
});
|
|
71
|
+
const safeKey = (0, get_alias_1.getAliasForSQL)(column, tableSchema, config);
|
|
78
72
|
columnsUsedInMeasuresInProjection += `${column} AS ${safeKey}`;
|
|
79
73
|
if (index !== columnsUsedInMeasures.length - 1) {
|
|
80
74
|
columnsUsedInMeasuresInProjection += ', ';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-projection-clause.js","sourceRoot":"","sources":["../../../../meerkat-core/src/get-wrapped-base-query-with-projections/get-projection-clause.ts"],"names":[],"mappings":";;;AAAA,mGAAkG;AAClG,
|
|
1
|
+
{"version":3,"file":"get-projection-clause.js","sourceRoot":"","sources":["../../../../meerkat-core/src/get-wrapped-base-query-with-projections/get-projection-clause.ts"],"names":[],"mappings":";;;AAAA,mGAAkG;AAClG,8DAGwC;AACxC,8GAAsG;AAEtG,yFAG4C;AAC5C,yEAAuD;AAEvD,MAAM,sBAAsB,GAAG,CAAC,EAC9B,MAAM,EACN,gBAAgB,EAChB,GAAG,EACH,GAAG,GAQJ,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E,EAAE;QAC9C,MAAM,OAAO,GAAG,IAAA,0BAAc,EAAC,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;QAC5D,iCAAiC,IAAI,GAAG,MAAM,OAAO,OAAO,EAAE,CAAC;QAC/D,IAAI,KAAK,KAAK,qBAAqB,CAAC,MAAM,GAAG,CAAC,EAAE;YAC9C,iCAAiC,IAAI,IAAI,CAAC;SAC3C;IACH,CAAC,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG;QAClB,qBAAqB;QACrB,kBAAkB;QAClB,iCAAiC;KAClC,CAAC;IAEF,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAChE,CAAC,CAAC;AAxFW,QAAA,mBAAmB,uBAwF9B"}
|
package/src/get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { QueryOptions } from '../member-formatters/get-alias';
|
|
1
2
|
import { Query, TableSchema } from '../types/cube-types';
|
|
2
3
|
interface GetWrappedBaseQueryWithProjectionsParams {
|
|
3
4
|
baseQuery: string;
|
|
4
5
|
tableSchema: TableSchema;
|
|
5
6
|
query: Query;
|
|
7
|
+
config: QueryOptions;
|
|
6
8
|
}
|
|
7
|
-
export declare const getWrappedBaseQueryWithProjections: ({ baseQuery, tableSchema, query, }: GetWrappedBaseQueryWithProjectionsParams) => string;
|
|
9
|
+
export declare const getWrappedBaseQueryWithProjections: ({ baseQuery, tableSchema, query, config, }: GetWrappedBaseQueryWithProjectionsParams) => string;
|
|
8
10
|
export {};
|
package/src/get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.getWrappedBaseQueryWithProjections = void 0;
|
|
|
4
4
|
const cube_measure_transformer_1 = require("../cube-measure-transformer/cube-measure-transformer");
|
|
5
5
|
const get_aliased_columns_from_filters_1 = require("./get-aliased-columns-from-filters");
|
|
6
6
|
const get_projection_clause_1 = require("./get-projection-clause");
|
|
7
|
-
const getWrappedBaseQueryWithProjections = ({ baseQuery, tableSchema, query, }) => {
|
|
7
|
+
const getWrappedBaseQueryWithProjections = ({ baseQuery, tableSchema, query, config, }) => {
|
|
8
8
|
/*
|
|
9
9
|
* Im order to be able to filter on computed metric from a query, we need to project the computed metric in the base query.
|
|
10
10
|
* If theres filters supplied, we can safely return the original base query. Since nothing need to be projected and filtered in this case
|
|
@@ -12,13 +12,14 @@ const getWrappedBaseQueryWithProjections = ({ baseQuery, tableSchema, query, })
|
|
|
12
12
|
// Wrap the query into another 'SELECT * FROM (baseQuery) AS baseTable'' in order to project everything in the base query, and other computed metrics to be able to filter on them
|
|
13
13
|
const newBaseSql = `SELECT * FROM (${baseQuery}) AS ${tableSchema.name}`;
|
|
14
14
|
const aliasedColumnSet = new Set();
|
|
15
|
-
const memberProjections = (0, get_projection_clause_1.getProjectionClause)(query, tableSchema, aliasedColumnSet);
|
|
15
|
+
const memberProjections = (0, get_projection_clause_1.getProjectionClause)(query, tableSchema, aliasedColumnSet, config);
|
|
16
16
|
const aliasFromFilters = (0, get_aliased_columns_from_filters_1.getAliasedColumnsFromFilters)({
|
|
17
17
|
aliasedColumnSet,
|
|
18
18
|
// setting measures to empty array, since we don't want to project measures present in the filters in the base query
|
|
19
19
|
tableSchema: tableSchema,
|
|
20
20
|
query,
|
|
21
21
|
meerkatFilters: query.filters,
|
|
22
|
+
config,
|
|
22
23
|
});
|
|
23
24
|
const parts = [aliasFromFilters, memberProjections].filter((part) => part !== '');
|
|
24
25
|
parts.push('*');
|
package/src/get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-wrapped-base-query-with-projections.js","sourceRoot":"","sources":["../../../../meerkat-core/src/get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections.ts"],"names":[],"mappings":";;;AAAA,mGAA4F;
|
|
1
|
+
{"version":3,"file":"get-wrapped-base-query-with-projections.js","sourceRoot":"","sources":["../../../../meerkat-core/src/get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections.ts"],"names":[],"mappings":";;;AAAA,mGAA4F;AAG5F,yFAAkF;AAClF,mEAA8D;AASvD,MAAM,kCAAkC,GAAG,CAAC,EACjD,SAAS,EACT,WAAW,EACX,KAAK,EACL,MAAM,GACmC,EAAE,EAAE;IAC7C;;;OAGG;IACH,kLAAkL;IAClL,MAAM,UAAU,GAAG,kBAAkB,SAAS,QAAQ,WAAW,CAAC,IAAI,EAAE,CAAC;IACzE,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;IAE3C,MAAM,iBAAiB,GAAG,IAAA,2CAAmB,EAC3C,KAAK,EACL,WAAW,EACX,gBAAgB,EAChB,MAAM,CACP,CAAC;IAEF,MAAM,gBAAgB,GAAG,IAAA,+DAA4B,EAAC;QACpD,gBAAgB;QAChB,oHAAoH;QACpH,WAAW,EAAE,WAAW;QACxB,KAAK;QACL,cAAc,EAAE,KAAK,CAAC,OAAO;QAC7B,MAAM;KACP,CAAC,CAAC;IAEH,MAAM,KAAK,GAAG,CAAC,gBAAgB,EAAE,iBAAiB,CAAC,CAAC,MAAM,CACxD,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,CACtB,CAAC;IACF,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChB,MAAM,yBAAyB,GAAG,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE/D,MAAM,qBAAqB,GAAG,IAAA,+CAAoB,EAChD,UAAU,EACV,yBAAyB,CAC1B,CAAC;IACF,OAAO,qBAAqB,CAAC;AAC/B,CAAC,CAAC;AAzCW,QAAA,kCAAkC,sCAyC7C"}
|
package/src/joins/joins.d.ts
CHANGED
|
@@ -6,6 +6,28 @@ export type Graph = {
|
|
|
6
6
|
};
|
|
7
7
|
};
|
|
8
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* Quotes an identifier if it contains dots or other special characters.
|
|
11
|
+
* Used for table aliases in SQL that may contain dots when useDotNotation is true.
|
|
12
|
+
*
|
|
13
|
+
* @param identifier - The identifier to potentially quote
|
|
14
|
+
* @returns The identifier, quoted if it contains dots
|
|
15
|
+
*/
|
|
16
|
+
export declare function quoteIdentifierIfNeeded(identifier: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Parses a table.column reference that may include quoted identifiers.
|
|
19
|
+
* Handles formats like:
|
|
20
|
+
* - `tableName.columnName` (simple)
|
|
21
|
+
* - `"tableName".columnName` (quoted table)
|
|
22
|
+
* - `"table.name".columnName` (quoted table with dots)
|
|
23
|
+
*
|
|
24
|
+
* @param reference - The full table.column reference string
|
|
25
|
+
* @returns An object with the table name and column name
|
|
26
|
+
*/
|
|
27
|
+
export declare function parseTableColumnReference(reference: string): {
|
|
28
|
+
tableName: string;
|
|
29
|
+
columnName: string;
|
|
30
|
+
};
|
|
9
31
|
export declare function generateSqlQuery(path: JoinPath[], tableSchemaSqlMap: {
|
|
10
32
|
[key: string]: string;
|
|
11
33
|
}, directedGraph: Graph): string;
|
package/src/joins/joins.js
CHANGED
|
@@ -1,8 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCombinedTableSchema = exports.checkLoopInJoinPath = exports.createDirectedGraph = exports.generateSqlQuery = void 0;
|
|
3
|
+
exports.getCombinedTableSchema = exports.checkLoopInJoinPath = exports.createDirectedGraph = exports.generateSqlQuery = exports.parseTableColumnReference = exports.quoteIdentifierIfNeeded = void 0;
|
|
4
4
|
const get_used_table_schema_1 = require("../get-used-table-schema/get-used-table-schema");
|
|
5
5
|
const cube_types_1 = require("../types/cube-types");
|
|
6
|
+
/**
|
|
7
|
+
* Quotes an identifier if it contains dots or other special characters.
|
|
8
|
+
* Used for table aliases in SQL that may contain dots when useDotNotation is true.
|
|
9
|
+
*
|
|
10
|
+
* @param identifier - The identifier to potentially quote
|
|
11
|
+
* @returns The identifier, quoted if it contains dots
|
|
12
|
+
*/
|
|
13
|
+
function quoteIdentifierIfNeeded(identifier) {
|
|
14
|
+
return identifier.includes('.') ? `"${identifier}"` : identifier;
|
|
15
|
+
}
|
|
16
|
+
exports.quoteIdentifierIfNeeded = quoteIdentifierIfNeeded;
|
|
17
|
+
/**
|
|
18
|
+
* Parses a table.column reference that may include quoted identifiers.
|
|
19
|
+
* Handles formats like:
|
|
20
|
+
* - `tableName.columnName` (simple)
|
|
21
|
+
* - `"tableName".columnName` (quoted table)
|
|
22
|
+
* - `"table.name".columnName` (quoted table with dots)
|
|
23
|
+
*
|
|
24
|
+
* @param reference - The full table.column reference string
|
|
25
|
+
* @returns An object with the table name and column name
|
|
26
|
+
*/
|
|
27
|
+
function parseTableColumnReference(reference) {
|
|
28
|
+
const trimmed = reference.trim();
|
|
29
|
+
// Check if the table name is quoted (starts with ")
|
|
30
|
+
if (trimmed.startsWith('"')) {
|
|
31
|
+
// Find the closing quote
|
|
32
|
+
const closeQuoteIndex = trimmed.indexOf('"', 1);
|
|
33
|
+
if (closeQuoteIndex === -1) {
|
|
34
|
+
throw new Error(`Invalid quoted identifier: ${reference}`);
|
|
35
|
+
}
|
|
36
|
+
// Extract the table name (without quotes)
|
|
37
|
+
const tableName = trimmed.substring(1, closeQuoteIndex);
|
|
38
|
+
// The column name comes after the closing quote and a dot
|
|
39
|
+
const columnName = trimmed.substring(closeQuoteIndex + 2);
|
|
40
|
+
return { tableName, columnName };
|
|
41
|
+
}
|
|
42
|
+
// Simple case: no quotes, just split by first dot
|
|
43
|
+
const dotIndex = trimmed.indexOf('.');
|
|
44
|
+
if (dotIndex === -1) {
|
|
45
|
+
throw new Error(`Invalid table.column reference: ${reference}`);
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
tableName: trimmed.substring(0, dotIndex),
|
|
49
|
+
columnName: trimmed.substring(dotIndex + 1),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
exports.parseTableColumnReference = parseTableColumnReference;
|
|
6
53
|
function generateSqlQuery(path, tableSchemaSqlMap, directedGraph) {
|
|
7
54
|
if (path.length === 0) {
|
|
8
55
|
throw new Error('Invalid path, multiple data sources are present without a join path.');
|
|
@@ -37,7 +84,9 @@ function generateSqlQuery(path, tableSchemaSqlMap, directedGraph) {
|
|
|
37
84
|
}
|
|
38
85
|
// If visitedFrom is undefined, this is the first visit to the node
|
|
39
86
|
visitedNodes.set(currentEdge.right, currentEdge);
|
|
40
|
-
|
|
87
|
+
// Quote the alias if it contains dots (useDotNotation mode)
|
|
88
|
+
const quotedAlias = quoteIdentifierIfNeeded(currentEdge.right);
|
|
89
|
+
query += ` LEFT JOIN (${tableSchemaSqlMap[currentEdge.right]}) AS ${quotedAlias} ON ${directedGraph[currentEdge.left][currentEdge.right][currentEdge.on]}`;
|
|
41
90
|
}
|
|
42
91
|
}
|
|
43
92
|
return query;
|
|
@@ -63,20 +112,23 @@ const createDirectedGraph = (tableSchema, tableSchemaSqlMap) => {
|
|
|
63
112
|
* The edges are added based on the join conditions provided in the table schema.
|
|
64
113
|
* The SQL is split by the '=' sign and the tables columns involved in the joins are extracted.
|
|
65
114
|
* The tables are then added as edges to the directed graph.
|
|
115
|
+
* Supports quoted identifiers for table names that contain dots (e.g., "table.name".column).
|
|
66
116
|
*/
|
|
67
117
|
tableSchema.forEach((schema) => {
|
|
68
118
|
var _a;
|
|
69
119
|
(_a = schema === null || schema === void 0 ? void 0 : schema.joins) === null || _a === void 0 ? void 0 : _a.forEach((join) => {
|
|
70
|
-
const
|
|
71
|
-
const conditions = join.sql
|
|
72
|
-
.split('=')
|
|
73
|
-
.map((str) => str.split('.')[1].trim());
|
|
120
|
+
const parts = join.sql.split('=');
|
|
74
121
|
/**
|
|
75
|
-
* If the join SQL does not contain exactly 2
|
|
122
|
+
* If the join SQL does not contain exactly 2 parts (left = right), then the join is invalid.
|
|
76
123
|
*/
|
|
77
|
-
if (
|
|
124
|
+
if (parts.length !== 2) {
|
|
78
125
|
throw new Error(`Invalid join SQL: ${join.sql}`);
|
|
79
126
|
}
|
|
127
|
+
// Parse the table and column from each side of the join condition
|
|
128
|
+
const leftRef = parseTableColumnReference(parts[0]);
|
|
129
|
+
const rightRef = parseTableColumnReference(parts[1]);
|
|
130
|
+
const tables = [leftRef.tableName, rightRef.tableName];
|
|
131
|
+
const conditions = [leftRef.columnName, rightRef.columnName];
|
|
80
132
|
/**
|
|
81
133
|
* If the tables are the same, then the join is invalid.
|
|
82
134
|
*/
|
package/src/joins/joins.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"joins.js","sourceRoot":"","sources":["../../../../meerkat-core/src/joins/joins.ts"],"names":[],"mappings":";;;AAAA,0FAAoF;AACpF,oDAA+E;AAM/E,SAAgB,gBAAgB,CAC9B,IAAgB,EAChB,iBAA4C,EAC5C,aAAoB;IAEpB,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;QACrB,MAAM,IAAI,KAAK,CACb,sEAAsE,CACvE,CAAC;KACH;IAED,MAAM,YAAY,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACrC,IAAI,KAAK,GAAG,GAAG,iBAAiB,CAAC,YAAY,CAAC,EAAE,CAAC;IAEjD;;;OAGG;IACH,IAAI,CAAC,IAAA,uBAAU,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;QAC3B,OAAO,KAAK,CAAC;KACd;IAED,MAAM,YAAY,GAAG,IAAI,GAAG,EAAE,CAAC;IAE/B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACpC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC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,EAAE,EAAE;KACV,CACF,CAAC;IACF,OAAO,mBAAmB,CAAC;AAC7B,CAAC,CAAC;AA5DW,QAAA,sBAAsB,0BA4DjC"}
|
|
@@ -1,17 +1,107 @@
|
|
|
1
1
|
import { TableSchema } from '../types/cube-types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Configuration for query options.
|
|
4
|
+
*/
|
|
5
|
+
export interface QueryOptions {
|
|
6
|
+
/**
|
|
7
|
+
* When true, uses dot notation for aliases: "orders.customer_id"
|
|
8
|
+
* When false, uses underscore notation: orders__customer_id
|
|
9
|
+
*/
|
|
10
|
+
useDotNotation: boolean;
|
|
5
11
|
}
|
|
6
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Get alias for SQL string contexts (SELECT projections, etc.).
|
|
14
|
+
* Always returns a properly quoted alias when needed.
|
|
15
|
+
*
|
|
16
|
+
* @param name - The member key (e.g., "orders.total_amount")
|
|
17
|
+
* @param tableSchema - The table schema to look up custom aliases from
|
|
18
|
+
* @param config - Configuration with useDotNotation flag
|
|
19
|
+
* @returns The alias string, quoted when necessary
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* // With useDotNotation: false
|
|
24
|
+
* getAliasForSQL("orders.total", schema, { useDotNotation: false }) // "orders__total"
|
|
25
|
+
*
|
|
26
|
+
* // With useDotNotation: true
|
|
27
|
+
* getAliasForSQL("orders.total", schema, { useDotNotation: true }) // "\"orders.total\""
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare const getAliasForSQL: (name: string, tableSchema: TableSchema, config: QueryOptions) => string;
|
|
31
|
+
/**
|
|
32
|
+
* Get alias for AST contexts (DuckDB AST nodes, column references).
|
|
33
|
+
* Returns unquoted alias - DuckDB handles quoting automatically.
|
|
34
|
+
*
|
|
35
|
+
* @param name - The member key (e.g., "orders.total_amount")
|
|
36
|
+
* @param tableSchema - The table schema to look up custom aliases from
|
|
37
|
+
* @param config - Configuration with useDotNotation flag
|
|
38
|
+
* @returns The alias string, unquoted
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* // With useDotNotation: false
|
|
43
|
+
* getAliasForAST("orders.total", schema, { useDotNotation: false }) // "orders__total"
|
|
44
|
+
*
|
|
45
|
+
* // With useDotNotation: true
|
|
46
|
+
* getAliasForAST("orders.total", schema, { useDotNotation: true }) // "orders.total"
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare const getAliasForAST: (name: string, tableSchema: TableSchema, config: QueryOptions) => string;
|
|
50
|
+
/**
|
|
51
|
+
* Construct alias for SQL string contexts directly from name and optional custom alias.
|
|
52
|
+
* Always returns a properly quoted alias when needed.
|
|
53
|
+
*
|
|
54
|
+
* @param name - The member key (e.g., "orders.total_amount")
|
|
55
|
+
* @param alias - Optional custom alias override
|
|
56
|
+
* @param config - Configuration with useDotNotation flag
|
|
57
|
+
* @returns The alias string, quoted when necessary
|
|
58
|
+
*/
|
|
59
|
+
export declare const constructAliasForSQL: (name: string, alias: string | undefined, config: QueryOptions) => string;
|
|
60
|
+
/**
|
|
61
|
+
* Construct alias for AST contexts directly from name and optional custom alias.
|
|
62
|
+
* Returns unquoted alias - DuckDB handles quoting automatically.
|
|
63
|
+
*
|
|
64
|
+
* @param name - The member key (e.g., "orders.total_amount")
|
|
65
|
+
* @param alias - Optional custom alias override
|
|
66
|
+
* @param config - Configuration with useDotNotation flag
|
|
67
|
+
* @returns The alias string, unquoted
|
|
68
|
+
*/
|
|
69
|
+
export declare const constructAliasForAST: (name: string, alias: string | undefined, config: QueryOptions) => string;
|
|
70
|
+
/**
|
|
71
|
+
* Get alias for a schema field.
|
|
72
|
+
*
|
|
73
|
+
* @param name - The member key (e.g., "orders.total_amount")
|
|
74
|
+
* @param tableSchema - The table schema to look up custom aliases from
|
|
75
|
+
* @param shouldWrapAliasWithQuotes - When true, wraps alias in quotes for SQL validity.
|
|
76
|
+
* Use `true` for SELECT projections where special characters need quoting.
|
|
77
|
+
* Use `false` for AST nodes (DuckDB auto-quotes) and internal schema references.
|
|
78
|
+
* @param config - Configuration with useDotNotation flag
|
|
79
|
+
*
|
|
80
|
+
* @deprecated Use `getAliasForSQL` or `getAliasForAST` instead for clearer intent.
|
|
81
|
+
*/
|
|
82
|
+
export declare const getAliasFromSchema: ({ name, tableSchema, shouldWrapAliasWithQuotes, config, }: {
|
|
7
83
|
name: string;
|
|
8
84
|
tableSchema: TableSchema;
|
|
9
|
-
|
|
85
|
+
shouldWrapAliasWithQuotes: boolean;
|
|
86
|
+
config: QueryOptions;
|
|
10
87
|
}) => string;
|
|
11
|
-
|
|
88
|
+
/**
|
|
89
|
+
* Construct alias directly from name and optional custom alias.
|
|
90
|
+
*
|
|
91
|
+
* @param name - The member key (e.g., "orders.total_amount")
|
|
92
|
+
* @param alias - Optional custom alias override
|
|
93
|
+
* @param shouldWrapAliasWithQuotes - When true, wraps alias in quotes for SQL validity.
|
|
94
|
+
* Use `true` for SELECT projections where special characters need quoting.
|
|
95
|
+
* Use `false` for AST nodes (DuckDB auto-quotes) and internal schema references.
|
|
96
|
+
* @param config - Configuration with useDotNotation flag
|
|
97
|
+
*
|
|
98
|
+
* @deprecated Use `constructAliasForSQL` or `constructAliasForAST` instead for clearer intent.
|
|
99
|
+
*/
|
|
100
|
+
export declare const constructAlias: ({ name, alias, shouldWrapAliasWithQuotes, config, }: {
|
|
12
101
|
name: string;
|
|
13
102
|
alias?: string | undefined;
|
|
14
|
-
|
|
103
|
+
shouldWrapAliasWithQuotes: boolean;
|
|
104
|
+
config: QueryOptions;
|
|
15
105
|
}) => string;
|
|
16
106
|
/**
|
|
17
107
|
* Creates a compound alias by joining two alias strings with " - ".
|