@devrev/meerkat-core 0.0.104 → 0.0.106
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/constants/exports/index.d.ts +1 -0
- package/src/constants/exports/index.js +5 -0
- package/src/constants/exports/index.js.map +1 -0
- package/src/cube-filter-transformer/in/in.js +182 -11
- package/src/cube-filter-transformer/in/in.js.map +1 -1
- package/src/cube-filter-transformer/not-in/not-in.js +190 -12
- package/src/cube-filter-transformer/not-in/not-in.js.map +1 -1
- package/src/get-wrapped-base-query-with-projections/get-aliased-columns-from-filters.d.ts +1 -1
- 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/index.d.ts +3 -0
- package/src/get-wrapped-base-query-with-projections/index.js +9 -0
- package/src/get-wrapped-base-query-with-projections/index.js.map +1 -0
- package/src/get-wrapped-base-query-with-projections/modifiers/array-flatten-modifier.d.ts +4 -0
- package/src/get-wrapped-base-query-with-projections/modifiers/array-flatten-modifier.js +24 -0
- package/src/get-wrapped-base-query-with-projections/modifiers/array-flatten-modifier.js.map +1 -0
- package/src/get-wrapped-base-query-with-projections/modifiers/array-unnest-modifier.d.ts +4 -0
- package/src/get-wrapped-base-query-with-projections/modifiers/array-unnest-modifier.js +21 -0
- package/src/get-wrapped-base-query-with-projections/modifiers/array-unnest-modifier.js.map +1 -0
- package/src/get-wrapped-base-query-with-projections/sql-expression-modifiers.d.ts +2 -15
- package/src/get-wrapped-base-query-with-projections/sql-expression-modifiers.js +17 -21
- package/src/get-wrapped-base-query-with-projections/sql-expression-modifiers.js.map +1 -1
- package/src/get-wrapped-base-query-with-projections/types.d.ts +12 -0
- package/src/get-wrapped-base-query-with-projections/types.js +3 -0
- package/src/get-wrapped-base-query-with-projections/types.js.map +1 -0
- package/src/index.d.ts +6 -1
- package/src/index.js +7 -3
- package/src/index.js.map +1 -1
- package/src/member-formatters/constants.d.ts +1 -0
- package/src/member-formatters/constants.js +4 -1
- package/src/member-formatters/constants.js.map +1 -1
- package/src/member-formatters/index.d.ts +1 -1
- package/src/member-formatters/index.js +2 -1
- package/src/member-formatters/index.js.map +1 -1
- package/src/resolution/generators/generate-resolution-join-paths.d.ts +4 -0
- package/src/resolution/generators/generate-resolution-join-paths.js +23 -0
- package/src/resolution/generators/generate-resolution-join-paths.js.map +1 -0
- package/src/resolution/generators/generate-resolution-schemas.d.ts +3 -0
- package/src/resolution/generators/generate-resolution-schemas.js +51 -0
- package/src/resolution/generators/generate-resolution-schemas.js.map +1 -0
- package/src/resolution/generators/generate-resolved-dimensions.d.ts +3 -0
- package/src/resolution/generators/generate-resolved-dimensions.js +25 -0
- package/src/resolution/generators/generate-resolved-dimensions.js.map +1 -0
- package/src/resolution/generators/generate-row-number-sql.d.ts +15 -0
- package/src/resolution/generators/generate-row-number-sql.js +35 -0
- package/src/resolution/generators/generate-row-number-sql.js.map +1 -0
- package/src/resolution/generators/index.d.ts +4 -0
- package/src/resolution/generators/index.js +8 -0
- package/src/resolution/generators/index.js.map +1 -0
- package/src/resolution/resolution.d.ts +50 -5
- package/src/resolution/resolution.js +73 -81
- package/src/resolution/resolution.js.map +1 -1
- package/src/resolution/steps/aggregation-step.d.ts +24 -0
- package/src/resolution/steps/aggregation-step.js +81 -0
- package/src/resolution/steps/aggregation-step.js.map +1 -0
- package/src/resolution/steps/resolution-step.d.ts +21 -0
- package/src/resolution/steps/resolution-step.js +85 -0
- package/src/resolution/steps/resolution-step.js.map +1 -0
- package/src/resolution/steps/unnest-step.d.ts +19 -0
- package/src/resolution/steps/unnest-step.js +28 -0
- package/src/resolution/steps/unnest-step.js.map +1 -0
- package/src/resolution/types.d.ts +2 -1
- package/src/resolution/types.js.map +1 -1
- package/src/types/cube-types/table.d.ts +1 -0
- package/src/utils/find-in-table-schema.js +8 -1
- package/src/utils/find-in-table-schema.js.map +1 -1
|
@@ -1,9 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.wrapWithRowIdOrderingAndExclusion = exports.getArrayTypeResolutionColumnConfigs = exports.withArrayFlattenModifier = exports.createWrapperTableSchema = exports.createBaseTableSchema = exports.shouldSkipResolution = exports.getColumnReference = void 0;
|
|
4
4
|
const member_formatters_1 = require("../member-formatters");
|
|
5
|
-
const
|
|
5
|
+
const is_array_member_type_1 = require("../utils/is-array-member-type");
|
|
6
6
|
const types_1 = require("./types");
|
|
7
|
+
/**
|
|
8
|
+
* Constructs a SQL column reference from a table name and a dimension/measure.
|
|
9
|
+
*
|
|
10
|
+
* @param tableName - The name of the table
|
|
11
|
+
* @param member - The dimension or measure object with name and optional alias
|
|
12
|
+
* @returns Formatted SQL column reference like: tableName."columnName"
|
|
13
|
+
*/
|
|
14
|
+
const getColumnReference = (tableName, member) => {
|
|
15
|
+
return `${tableName}."${member.alias || member.name}"`;
|
|
16
|
+
};
|
|
17
|
+
exports.getColumnReference = getColumnReference;
|
|
18
|
+
/**
|
|
19
|
+
* Checks if resolution should be skipped based on the resolution configuration and column projections.
|
|
20
|
+
* Resolution is skipped when there are no columns to resolve and no column projections.
|
|
21
|
+
*
|
|
22
|
+
* @param resolutionConfig - The resolution configuration
|
|
23
|
+
* @param columnProjections - Optional array of column projections
|
|
24
|
+
* @returns true if resolution should be skipped, false otherwise
|
|
25
|
+
*/
|
|
26
|
+
const shouldSkipResolution = (resolutionConfig, query, columnProjections) => {
|
|
27
|
+
// If no resolution required and no column projections to ensure order in which export is happening
|
|
28
|
+
// and explicit order is not provided, then skip resolution.
|
|
29
|
+
return (resolutionConfig.columnConfigs.length === 0 &&
|
|
30
|
+
(columnProjections === null || columnProjections === void 0 ? void 0 : columnProjections.length) === 0 &&
|
|
31
|
+
!query.order);
|
|
32
|
+
};
|
|
33
|
+
exports.shouldSkipResolution = shouldSkipResolution;
|
|
7
34
|
const constructBaseDimension = (name, schema) => {
|
|
8
35
|
return {
|
|
9
36
|
name: (0, member_formatters_1.memberKeyToSafeKey)(name),
|
|
@@ -58,86 +85,51 @@ const createBaseTableSchema = (baseSql, tableSchemas, resolutionConfig, measures
|
|
|
58
85
|
};
|
|
59
86
|
};
|
|
60
87
|
exports.createBaseTableSchema = createBaseTableSchema;
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
name: baseName,
|
|
80
|
-
sql: tableSchema.sql,
|
|
81
|
-
measures: [],
|
|
82
|
-
dimensions: colConfig.resolutionColumns.map((col) => {
|
|
83
|
-
const dimension = (0, find_in_table_schema_1.findInDimensionSchemas)((0, member_formatters_1.getNamespacedKey)(colConfig.source, col), config.tableSchemas);
|
|
84
|
-
if (!dimension) {
|
|
85
|
-
throw new Error(`Dimension not found: ${col}`);
|
|
86
|
-
}
|
|
87
|
-
return {
|
|
88
|
-
// Need to create a new name due to limitations with how
|
|
89
|
-
// CubeToSql handles duplicate dimension names between different sources.
|
|
90
|
-
name: (0, member_formatters_1.memberKeyToSafeKey)((0, member_formatters_1.getNamespacedKey)(colConfig.name, col)),
|
|
91
|
-
sql: `${baseName}.${col}`,
|
|
92
|
-
type: dimension.type,
|
|
93
|
-
alias: `${baseAlias} - ${(0, member_formatters_1.constructAlias)({
|
|
94
|
-
name: col,
|
|
95
|
-
alias: dimension.alias,
|
|
96
|
-
aliasContext: { isTableSchemaAlias: true },
|
|
97
|
-
})}`,
|
|
98
|
-
};
|
|
99
|
-
}),
|
|
100
|
-
};
|
|
101
|
-
resolutionSchemas.push(resolutionSchema);
|
|
102
|
-
});
|
|
103
|
-
return resolutionSchemas;
|
|
88
|
+
const createWrapperTableSchema = (sql, baseTableSchema) => {
|
|
89
|
+
return {
|
|
90
|
+
name: types_1.BASE_DATA_SOURCE_NAME,
|
|
91
|
+
sql: sql,
|
|
92
|
+
dimensions: baseTableSchema.dimensions.map((d) => ({
|
|
93
|
+
name: d.name,
|
|
94
|
+
sql: (0, exports.getColumnReference)(types_1.BASE_DATA_SOURCE_NAME, d),
|
|
95
|
+
type: d.type,
|
|
96
|
+
alias: d.alias,
|
|
97
|
+
})),
|
|
98
|
+
measures: baseTableSchema.measures.map((m) => ({
|
|
99
|
+
name: m.name,
|
|
100
|
+
sql: (0, exports.getColumnReference)(types_1.BASE_DATA_SOURCE_NAME, m),
|
|
101
|
+
type: m.type,
|
|
102
|
+
alias: m.alias,
|
|
103
|
+
})),
|
|
104
|
+
joins: baseTableSchema.joins,
|
|
105
|
+
};
|
|
104
106
|
};
|
|
105
|
-
exports.
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return [
|
|
116
|
-
(0, member_formatters_1.getNamespacedKey)(types_1.BASE_DATA_SOURCE_NAME, (0, member_formatters_1.memberKeyToSafeKey)(dimension)),
|
|
117
|
-
];
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
return columnConfig.resolutionColumns.map((col) => (0, member_formatters_1.getNamespacedKey)((0, member_formatters_1.memberKeyToSafeKey)(dimension), (0, member_formatters_1.memberKeyToSafeKey)((0, member_formatters_1.getNamespacedKey)(columnConfig.name, col))));
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
return resolvedDimensions;
|
|
107
|
+
exports.createWrapperTableSchema = createWrapperTableSchema;
|
|
108
|
+
const withArrayFlattenModifier = (baseTableSchema, resolutionConfig) => {
|
|
109
|
+
const arrayColumns = (0, exports.getArrayTypeResolutionColumnConfigs)(resolutionConfig);
|
|
110
|
+
return Object.assign(Object.assign({}, baseTableSchema), { dimensions: baseTableSchema.dimensions.map((dimension) => {
|
|
111
|
+
const shouldFlatten = arrayColumns.some((ac) => ac.name === dimension.name);
|
|
112
|
+
if (shouldFlatten) {
|
|
113
|
+
return Object.assign(Object.assign({}, dimension), { modifier: { shouldFlattenArray: true } });
|
|
114
|
+
}
|
|
115
|
+
return dimension;
|
|
116
|
+
}) });
|
|
124
117
|
};
|
|
125
|
-
exports.
|
|
126
|
-
const
|
|
127
|
-
return resolutionConfig.columnConfigs.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
});
|
|
118
|
+
exports.withArrayFlattenModifier = withArrayFlattenModifier;
|
|
119
|
+
const getArrayTypeResolutionColumnConfigs = (resolutionConfig) => {
|
|
120
|
+
return resolutionConfig.columnConfigs.filter((config) => (0, is_array_member_type_1.isArrayTypeMember)(config.type));
|
|
121
|
+
};
|
|
122
|
+
exports.getArrayTypeResolutionColumnConfigs = getArrayTypeResolutionColumnConfigs;
|
|
123
|
+
/**
|
|
124
|
+
* Wraps SQL to order by row_id and then exclude it from results.
|
|
125
|
+
* This maintains the ordering from the base query while removing the internal row_id column.
|
|
126
|
+
*
|
|
127
|
+
* @param sql - The SQL query that includes a __row_id column
|
|
128
|
+
* @param rowIdColumnName - The name of the row_id column (defaults to '__row_id')
|
|
129
|
+
* @returns SQL query ordered by row_id with the row_id column excluded
|
|
130
|
+
*/
|
|
131
|
+
const wrapWithRowIdOrderingAndExclusion = (sql, rowIdColumnName) => {
|
|
132
|
+
return `select * exclude(${rowIdColumnName}) from (${sql}) order by ${rowIdColumnName}`;
|
|
141
133
|
};
|
|
142
|
-
exports.
|
|
134
|
+
exports.wrapWithRowIdOrderingAndExclusion = wrapWithRowIdOrderingAndExclusion;
|
|
143
135
|
//# sourceMappingURL=resolution.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolution.js","sourceRoot":"","sources":["../../../../meerkat-core/src/resolution/resolution.ts"],"names":[],"mappings":";;;AAAA,4DAI8B;AAG9B,
|
|
1
|
+
{"version":3,"file":"resolution.js","sourceRoot":"","sources":["../../../../meerkat-core/src/resolution/resolution.ts"],"names":[],"mappings":";;;AAAA,4DAI8B;AAG9B,wEAAkE;AAClE,mCAIiB;AAEjB;;;;;;GAMG;AACI,MAAM,kBAAkB,GAAG,CAChC,SAAiB,EACjB,MAAwC,EAChC,EAAE;IACV,OAAO,GAAG,SAAS,KAAK,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI,GAAG,CAAC;AACzD,CAAC,CAAC;AALW,QAAA,kBAAkB,sBAK7B;AAEF;;;;;;;GAOG;AACI,MAAM,oBAAoB,GAAG,CAClC,gBAAkC,EAClC,KAAY,EACZ,iBAA4B,EACnB,EAAE;IACX,mGAAmG;IACnG,4DAA4D;IAC5D,OAAO,CACL,gBAAgB,CAAC,aAAa,CAAC,MAAM,KAAK,CAAC;QAC3C,CAAA,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,MAAM,MAAK,CAAC;QAC/B,CAAC,KAAK,CAAC,KAAK,CACb,CAAC;AACJ,CAAC,CAAC;AAZW,QAAA,oBAAoB,wBAY/B;AAEF,MAAM,sBAAsB,GAAG,CAAC,IAAY,EAAE,MAA2B,EAAE,EAAE;IAC3E,OAAO;QACL,IAAI,EAAE,IAAA,sCAAkB,EAAC,IAAI,CAAC;QAC9B,GAAG,EAAE,GAAG,6BAAqB,IAAI,IAAA,kCAAc,EAAC;YAC9C,IAAI;YACJ,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,YAAY,EAAE,EAAE,eAAe,EAAE,KAAK,EAAE;SACzC,CAAC,EAAE;QACJ,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,wDAAwD;QACxD,KAAK,EAAE,IAAA,kCAAc,EAAC;YACpB,IAAI;YACJ,KAAK,EAAE,MAAM,CAAC,KAAK;YAC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wBAAwB,GAAG,CACtC,eAA4B,EAC5B,gBAAkC,EACrB,EAAE;IACf,MAAM,YAAY,GAAG,IAAA,2CAAmC,EAAC,gBAAgB,CAAC,CAAC;IAE3E,uCACK,eAAe,KAClB,UAAU,EAAE,eAAe,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE;YACvD,MAAM,aAAa,GAAG,YAAY,CAAC,IAAI,CACrC,CAAC,EAA0B,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI,CAC3D,CAAC;YAEF,IAAI,aAAa,EAAE;gBACjB,uCACK,SAAS,KACZ,QAAQ,EAAE,EAAE,kBAAkB,EAAE,IAAI,EAAE,IACtC;aACH;YAED,OAAO,SAAS,CAAC;QACnB,CAAC,CAAC,IACF;AACJ,CAAC,CAAC;AAvBW,QAAA,wBAAwB,4BAuBnC;AAEK,MAAM,mCAAmC,GAAG,CACjD,gBAAkC,EAClC,EAAE;IACF,OAAO,gBAAgB,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CACtD,IAAA,wCAAiB,EAAC,MAAM,CAAC,IAAI,CAAC,CAC/B,CAAC;AACJ,CAAC,CAAC;AANW,QAAA,mCAAmC,uCAM9C;AAEF;;;;;;;GAOG;AACI,MAAM,iCAAiC,GAAG,CAC/C,GAAW,EACX,eAAuB,EACf,EAAE;IACV,OAAO,oBAAoB,eAAe,WAAW,GAAG,cAAc,eAAe,EAAE,CAAC;AAC1F,CAAC,CAAC;AALW,QAAA,iCAAiC,qCAK5C"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ContextParams, Query, ResolutionConfig, TableSchema } from '../../index';
|
|
2
|
+
/**
|
|
3
|
+
* Re-aggregate to reverse the unnest
|
|
4
|
+
*
|
|
5
|
+
* This function:
|
|
6
|
+
* 1. Groups by row_id
|
|
7
|
+
* 2. Uses MAX for non-array columns (they're duplicated)
|
|
8
|
+
* 3. Uses ARRAY_AGG for resolved array columns
|
|
9
|
+
*
|
|
10
|
+
* @param resolvedTableSchema - Schema from Phase 2 (contains all column info)
|
|
11
|
+
* @param resolutionConfig - Resolution configuration
|
|
12
|
+
* @param contextParams - Optional context parameters
|
|
13
|
+
* @returns Final SQL with arrays containing resolved values
|
|
14
|
+
*/
|
|
15
|
+
export declare const getAggregatedSql: ({ resolvedTableSchema, resolutionConfig, contextParams, cubeQueryToSQL, }: {
|
|
16
|
+
resolvedTableSchema: TableSchema;
|
|
17
|
+
resolutionConfig: ResolutionConfig;
|
|
18
|
+
contextParams?: ContextParams | undefined;
|
|
19
|
+
cubeQueryToSQL: (params: {
|
|
20
|
+
query: Query;
|
|
21
|
+
tableSchemas: TableSchema[];
|
|
22
|
+
contextParams?: ContextParams | undefined;
|
|
23
|
+
}) => Promise<string>;
|
|
24
|
+
}) => Promise<string>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAggregatedSql = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const index_1 = require("../../index");
|
|
6
|
+
/**
|
|
7
|
+
* Constructs the resolved column name prefix for array resolution.
|
|
8
|
+
* This is used to identify which columns in the resolved schema correspond to array fields.
|
|
9
|
+
*
|
|
10
|
+
* @param columnName - The original column name
|
|
11
|
+
* @returns The prefixed column name used in resolution
|
|
12
|
+
*/
|
|
13
|
+
const getResolvedArrayColumnPrefix = (columnName) => {
|
|
14
|
+
return `${columnName}${index_1.MEERKAT_OUTPUT_DELIMITER}`;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Re-aggregate to reverse the unnest
|
|
18
|
+
*
|
|
19
|
+
* This function:
|
|
20
|
+
* 1. Groups by row_id
|
|
21
|
+
* 2. Uses MAX for non-array columns (they're duplicated)
|
|
22
|
+
* 3. Uses ARRAY_AGG for resolved array columns
|
|
23
|
+
*
|
|
24
|
+
* @param resolvedTableSchema - Schema from Phase 2 (contains all column info)
|
|
25
|
+
* @param resolutionConfig - Resolution configuration
|
|
26
|
+
* @param contextParams - Optional context parameters
|
|
27
|
+
* @returns Final SQL with arrays containing resolved values
|
|
28
|
+
*/
|
|
29
|
+
const getAggregatedSql = ({ resolvedTableSchema, resolutionConfig, contextParams, cubeQueryToSQL, }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
const aggregationBaseTableSchema = resolvedTableSchema;
|
|
31
|
+
// Identify which columns need ARRAY_AGG vs MAX
|
|
32
|
+
const arrayColumns = (0, index_1.getArrayTypeResolutionColumnConfigs)(resolutionConfig);
|
|
33
|
+
const baseTableName = aggregationBaseTableSchema.name;
|
|
34
|
+
const isResolvedArrayColumn = (dimName) => {
|
|
35
|
+
return arrayColumns.some((arrayCol) => {
|
|
36
|
+
return dimName.includes(getResolvedArrayColumnPrefix(arrayCol.name));
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
// Create aggregation measures with proper aggregation functions
|
|
40
|
+
// Get row_id dimension for GROUP BY
|
|
41
|
+
const rowIdDimension = aggregationBaseTableSchema.dimensions.find((d) => d.name === index_1.ROW_ID_DIMENSION_NAME);
|
|
42
|
+
if (!rowIdDimension) {
|
|
43
|
+
throw new Error('Row id dimension not found');
|
|
44
|
+
}
|
|
45
|
+
// Create measures with MAX or ARRAY_AGG based on column type
|
|
46
|
+
const aggregationMeasures = [];
|
|
47
|
+
aggregationBaseTableSchema.dimensions
|
|
48
|
+
.filter((dim) => dim.name !== (rowIdDimension === null || rowIdDimension === void 0 ? void 0 : rowIdDimension.name))
|
|
49
|
+
.forEach((dim) => {
|
|
50
|
+
const isArrayColumn = isResolvedArrayColumn(dim.name);
|
|
51
|
+
// The dimension's sql field already has the correct reference (e.g., __resolved_query."__row_id")
|
|
52
|
+
// We just need to wrap it in the aggregation function
|
|
53
|
+
const columnRef = dim.sql;
|
|
54
|
+
// Use ARRAY_AGG for resolved array columns, MAX for others
|
|
55
|
+
// Filter out null values for ARRAY_AGG using FILTER clause
|
|
56
|
+
const aggregationFn = isArrayColumn
|
|
57
|
+
? `COALESCE(ARRAY_AGG(DISTINCT ${columnRef}) FILTER (WHERE ${columnRef} IS NOT NULL), [])`
|
|
58
|
+
: `MAX(${columnRef})`;
|
|
59
|
+
aggregationMeasures.push({
|
|
60
|
+
name: dim.name,
|
|
61
|
+
sql: aggregationFn,
|
|
62
|
+
type: dim.type,
|
|
63
|
+
alias: dim.alias,
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
// Update the schema with aggregation measures
|
|
67
|
+
const schemaWithAggregation = Object.assign(Object.assign({}, aggregationBaseTableSchema), { measures: aggregationMeasures, dimensions: [rowIdDimension] });
|
|
68
|
+
// Generate the final SQL
|
|
69
|
+
const aggregatedSql = yield cubeQueryToSQL({
|
|
70
|
+
query: {
|
|
71
|
+
measures: aggregationMeasures.map((m) => (0, index_1.getNamespacedKey)(baseTableName, m.name)),
|
|
72
|
+
dimensions: [(0, index_1.getNamespacedKey)(baseTableName, rowIdDimension.name)],
|
|
73
|
+
},
|
|
74
|
+
tableSchemas: [schemaWithAggregation],
|
|
75
|
+
contextParams,
|
|
76
|
+
});
|
|
77
|
+
// Order by row_id to maintain consistent ordering before excluding it
|
|
78
|
+
return (0, index_1.wrapWithRowIdOrderingAndExclusion)(aggregatedSql, index_1.ROW_ID_DIMENSION_NAME);
|
|
79
|
+
});
|
|
80
|
+
exports.getAggregatedSql = getAggregatedSql;
|
|
81
|
+
//# sourceMappingURL=aggregation-step.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aggregation-step.js","sourceRoot":"","sources":["../../../../../meerkat-core/src/resolution/steps/aggregation-step.ts"],"names":[],"mappings":";;;;AAAA,uCAWqB;AAErB;;;;;;GAMG;AACH,MAAM,4BAA4B,GAAG,CAAC,UAAkB,EAAU,EAAE;IAClE,OAAO,GAAG,UAAU,GAAG,gCAAwB,EAAE,CAAC;AACpD,C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DAA2D;QAC3D,MAAM,aAAa,GAAG,aAAa;YACjC,CAAC,CAAC,+BAA+B,SAAS,mBAAmB,SAAS,oBAAoB;YAC1F,CAAC,CAAC,OAAO,SAAS,GAAG,CAAC;QAExB,mBAAmB,CAAC,IAAI,CAAC;YACvB,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,GAAG,EAAE,aAAa;YAClB,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,KAAK,EAAE,GAAG,CAAC,KAAK;SACjB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEL,8CAA8C;IAC9C,MAAM,qBAAqB,mCACtB,0BAA0B,KAC7B,QAAQ,EAAE,mBAAmB,EAC7B,UAAU,EAAE,CAAC,cAAc,CAAC,GAC7B,CAAC;IAEF,yBAAyB;IACzB,MAAM,aAAa,GAAG,MAAM,cAAc,CAAC;QACzC,KAAK,EAAE;YACL,QAAQ,EAAE,mBAAmB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACtC,IAAA,wBAAgB,EAAC,aAAa,EAAE,CAAC,CAAC,IAAI,CAAC,CACxC;YACD,UAAU,EAAE,CAAC,IAAA,wBAAgB,EAAC,aAAa,EAAE,cAAc,CAAC,IAAI,CAAC,CAAC;SACnE;QACD,YAAY,EAAE,CAAC,qBAAqB,CAAC;QACrC,aAAa;KACd,CAAC,CAAC;IAEH,sEAAsE;IACtE,OAAO,IAAA,yCAAiC,EACtC,aAAa,EACb,6BAAqB,CACtB,CAAC;AACJ,CAAC,CAAA,CAAC;AAtFW,QAAA,gBAAgB,oBAsF3B"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ContextParams, Query, ResolutionConfig, TableSchema } from '../../index';
|
|
2
|
+
/**
|
|
3
|
+
* Apply resolution (join with lookup tables)
|
|
4
|
+
*
|
|
5
|
+
* This function:
|
|
6
|
+
* 1. Uses the base table schema from Phase 1 (source of truth)
|
|
7
|
+
* 2. Generates resolution schemas for array fields
|
|
8
|
+
* 3. Sets up join paths between unnested data and resolution tables
|
|
9
|
+
* @returns Table schema with resolved values from lookup tables
|
|
10
|
+
*/
|
|
11
|
+
export declare const getResolvedTableSchema: ({ baseTableSchema, resolutionConfig, columnProjections, contextParams, cubeQueryToSQL, }: {
|
|
12
|
+
baseTableSchema: TableSchema;
|
|
13
|
+
resolutionConfig: ResolutionConfig;
|
|
14
|
+
columnProjections: string[];
|
|
15
|
+
contextParams?: ContextParams | undefined;
|
|
16
|
+
cubeQueryToSQL: (params: {
|
|
17
|
+
query: Query;
|
|
18
|
+
tableSchemas: TableSchema[];
|
|
19
|
+
contextParams?: ContextParams | undefined;
|
|
20
|
+
}) => Promise<string>;
|
|
21
|
+
}) => Promise<TableSchema>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getResolvedTableSchema = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const index_1 = require("../../index");
|
|
6
|
+
/**
|
|
7
|
+
* Apply resolution (join with lookup tables)
|
|
8
|
+
*
|
|
9
|
+
* This function:
|
|
10
|
+
* 1. Uses the base table schema from Phase 1 (source of truth)
|
|
11
|
+
* 2. Generates resolution schemas for array fields
|
|
12
|
+
* 3. Sets up join paths between unnested data and resolution tables
|
|
13
|
+
* @returns Table schema with resolved values from lookup tables
|
|
14
|
+
*/
|
|
15
|
+
const getResolvedTableSchema = ({ baseTableSchema, resolutionConfig, columnProjections, contextParams, cubeQueryToSQL, }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
const updatedBaseTableSchema = baseTableSchema;
|
|
17
|
+
// Generate resolution schemas for fields that need resolution
|
|
18
|
+
const resolutionSchemas = (0, index_1.generateResolutionSchemas)(resolutionConfig, [
|
|
19
|
+
updatedBaseTableSchema,
|
|
20
|
+
]);
|
|
21
|
+
const joinPaths = (0, index_1.generateResolutionJoinPaths)(updatedBaseTableSchema.name, resolutionConfig, [updatedBaseTableSchema]);
|
|
22
|
+
const tempQuery = {
|
|
23
|
+
measures: [],
|
|
24
|
+
dimensions: baseTableSchema.dimensions.map((d) => (0, index_1.getNamespacedKey)(updatedBaseTableSchema.name, d.name)),
|
|
25
|
+
};
|
|
26
|
+
const updatedColumnProjections = columnProjections === null || columnProjections === void 0 ? void 0 : columnProjections.map((cp) => (0, index_1.memberKeyToSafeKey)(cp));
|
|
27
|
+
// Generate resolved dimensions using columnProjections
|
|
28
|
+
const resolvedDimensions = (0, index_1.generateResolvedDimensions)(updatedBaseTableSchema.name, tempQuery, resolutionConfig, updatedColumnProjections);
|
|
29
|
+
// Create query and generate SQL
|
|
30
|
+
const resolutionQuery = {
|
|
31
|
+
measures: [],
|
|
32
|
+
dimensions: resolvedDimensions,
|
|
33
|
+
joinPaths,
|
|
34
|
+
};
|
|
35
|
+
const resolvedSql = yield cubeQueryToSQL({
|
|
36
|
+
query: resolutionQuery,
|
|
37
|
+
tableSchemas: [updatedBaseTableSchema, ...resolutionSchemas],
|
|
38
|
+
contextParams,
|
|
39
|
+
});
|
|
40
|
+
// Use the baseTableSchema which already has all the column info
|
|
41
|
+
const resolvedTableSchema = (0, index_1.createWrapperTableSchema)(resolvedSql, updatedBaseTableSchema);
|
|
42
|
+
// Create a map of resolution schema dimensions by original column name
|
|
43
|
+
const resolutionDimensionsByColumnName = new Map();
|
|
44
|
+
// Create a map of resolution schemas by config name for efficient lookup
|
|
45
|
+
const resolutionSchemaByConfigName = new Map();
|
|
46
|
+
resolutionSchemas.forEach((resSchema) => {
|
|
47
|
+
resolutionConfig.columnConfigs.forEach((config) => {
|
|
48
|
+
if (resSchema.dimensions.some((dim) => dim.name.startsWith(config.name))) {
|
|
49
|
+
resolutionSchemaByConfigName.set(config.name, resSchema);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
// Build the dimension map using the pre-indexed schemas
|
|
54
|
+
resolutionConfig.columnConfigs.forEach((config) => {
|
|
55
|
+
const resSchema = resolutionSchemaByConfigName.get(config.name);
|
|
56
|
+
if (resSchema) {
|
|
57
|
+
resolutionDimensionsByColumnName.set(config.name, resSchema.dimensions.map((dim) => ({
|
|
58
|
+
name: dim.name,
|
|
59
|
+
sql: (0, index_1.getColumnReference)(resolvedTableSchema.name, dim),
|
|
60
|
+
type: dim.type,
|
|
61
|
+
alias: dim.alias,
|
|
62
|
+
})));
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
// Maintain the same order as columnProjections
|
|
66
|
+
// Replace dimensions that need resolution with their resolved counterparts
|
|
67
|
+
resolvedTableSchema.dimensions = (updatedColumnProjections || []).flatMap((projectionName) => {
|
|
68
|
+
// Check if this column has resolved dimensions
|
|
69
|
+
const resolvedDims = resolutionDimensionsByColumnName.get(projectionName);
|
|
70
|
+
if (resolvedDims) {
|
|
71
|
+
// Use resolved dimensions
|
|
72
|
+
return resolvedDims;
|
|
73
|
+
}
|
|
74
|
+
// Otherwise, find the original dimension from baseTableSchema
|
|
75
|
+
const originalDim = baseTableSchema.dimensions.find((d) => d.name === projectionName);
|
|
76
|
+
if (originalDim) {
|
|
77
|
+
return [originalDim];
|
|
78
|
+
}
|
|
79
|
+
// If not found, throw an error
|
|
80
|
+
throw new Error(`Column projection '${projectionName}' not found in base table schema dimensions`);
|
|
81
|
+
});
|
|
82
|
+
return resolvedTableSchema;
|
|
83
|
+
});
|
|
84
|
+
exports.getResolvedTableSchema = getResolvedTableSchema;
|
|
85
|
+
//# sourceMappingURL=resolution-step.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolution-step.js","sourceRoot":"","sources":["../../../../../meerkat-core/src/resolution/steps/resolution-step.ts"],"names":[],"mappings":";;;;AAAA,uCAYqB;AAErB;;;;;;;;GAQG;AACI,MAAM,sBAAsB,GAAG,CAAO,EAC3C,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,aAAa,EACb,cAAc,GAWf,EAAwB,EAAE;IACzB,MAAM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E,IAAI,YAAY,EAAE;YAChB,0BAA0B;YAC1B,OAAO,YAAY,CAAC;SACrB;QAED,8DAA8D;QAC9D,MAAM,WAAW,GAAG,eAAe,CAAC,UAAU,CAAC,IAAI,CACjD,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,cAAc,CACjC,CAAC;QACF,IAAI,WAAW,EAAE;YACf,OAAO,CAAC,WAAW,CAAC,CAAC;SACtB;QAED,+BAA+B;QAC/B,MAAM,IAAI,KAAK,CACb,sBAAsB,cAAc,6CAA6C,CAClF,CAAC;IACJ,CAAC,CACF,CAAC;IAEF,OAAO,mBAAmB,CAAC;AAC7B,CAAC,CAAA,CAAC;AAhIW,QAAA,sBAAsB,0BAgIjC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ContextParams, Query, ResolutionConfig, TableSchema } from '../../index';
|
|
2
|
+
/**
|
|
3
|
+
* Apply unnesting
|
|
4
|
+
*
|
|
5
|
+
* This function performs 1 step:
|
|
6
|
+
* 1. Create schema with unnest modifiers for array columns
|
|
7
|
+
* 2. Generate final unnested SQL
|
|
8
|
+
* @returns Table schema with unnest modifiers for array columns
|
|
9
|
+
*/
|
|
10
|
+
export declare const getUnnestTableSchema: ({ baseTableSchema, resolutionConfig, contextParams, cubeQueryToSQL, }: {
|
|
11
|
+
baseTableSchema: TableSchema;
|
|
12
|
+
resolutionConfig: ResolutionConfig;
|
|
13
|
+
contextParams?: ContextParams | undefined;
|
|
14
|
+
cubeQueryToSQL: (params: {
|
|
15
|
+
query: Query;
|
|
16
|
+
tableSchemas: TableSchema[];
|
|
17
|
+
contextParams?: ContextParams | undefined;
|
|
18
|
+
}) => Promise<string>;
|
|
19
|
+
}) => Promise<TableSchema>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getUnnestTableSchema = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const index_1 = require("../../index");
|
|
6
|
+
/**
|
|
7
|
+
* Apply unnesting
|
|
8
|
+
*
|
|
9
|
+
* This function performs 1 step:
|
|
10
|
+
* 1. Create schema with unnest modifiers for array columns
|
|
11
|
+
* 2. Generate final unnested SQL
|
|
12
|
+
* @returns Table schema with unnest modifiers for array columns
|
|
13
|
+
*/
|
|
14
|
+
const getUnnestTableSchema = ({ baseTableSchema, resolutionConfig, contextParams, cubeQueryToSQL, }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
const updatedBaseTableSchema = (0, index_1.withArrayFlattenModifier)(baseTableSchema, resolutionConfig);
|
|
16
|
+
const unnestedSql = yield cubeQueryToSQL({
|
|
17
|
+
query: {
|
|
18
|
+
measures: [],
|
|
19
|
+
dimensions: updatedBaseTableSchema.dimensions.map((d) => (0, index_1.getNamespacedKey)(updatedBaseTableSchema.name, d.name)),
|
|
20
|
+
},
|
|
21
|
+
tableSchemas: [updatedBaseTableSchema],
|
|
22
|
+
contextParams,
|
|
23
|
+
});
|
|
24
|
+
const unnestedBaseTableSchema = (0, index_1.createWrapperTableSchema)(unnestedSql, baseTableSchema);
|
|
25
|
+
return unnestedBaseTableSchema;
|
|
26
|
+
});
|
|
27
|
+
exports.getUnnestTableSchema = getUnnestTableSchema;
|
|
28
|
+
//# sourceMappingURL=unnest-step.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unnest-step.js","sourceRoot":"","sources":["../../../../../meerkat-core/src/resolution/steps/unnest-step.ts"],"names":[],"mappings":";;;;AAAA,uCAQqB;AAErB;;;;;;;GAOG;AACI,MAAM,oBAAoB,GAAG,CAAO,EACzC,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,cAAc,GAUf,EAAwB,EAAE;IACzB,MAAM,sBAAsB,GAAG,IAAA,gCAAwB,EACrD,eAAe,EACf,gBAAgB,CACjB,CAAC;IAEF,MAAM,WAAW,GAAG,MAAM,cAAc,CAAC;QACvC,KAAK,EAAE;YACL,QAAQ,EAAE,EAAE;YACZ,UAAU,EAAE,sBAAsB,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACtD,IAAA,wBAAgB,EAAC,sBAAsB,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CACtD;SACF;QACD,YAAY,EAAE,CAAC,sBAAsB,CAAC;QACtC,aAAa;KACd,CAAC,CAAC;IAEH,MAAM,uBAAuB,GAAgB,IAAA,gCAAwB,EACnE,WAAW,EACX,eAAe,CAChB,CAAC;IAEF,OAAO,uBAAuB,CAAC;AACjC,CAAC,CAAA,CAAC;AArCW,QAAA,oBAAoB,wBAqC/B"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { TableSchema } from '../types/cube-types/table';
|
|
1
|
+
import { DimensionType, MeasureType, TableSchema } from '../types/cube-types/table';
|
|
2
2
|
export interface ResolutionColumnConfig {
|
|
3
3
|
name: string;
|
|
4
|
+
type: DimensionType | MeasureType;
|
|
4
5
|
source: string;
|
|
5
6
|
joinColumn: string;
|
|
6
7
|
resolutionColumns: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../meerkat-core/src/resolution/types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../meerkat-core/src/resolution/types.ts"],"names":[],"mappings":";;;AA0Ba,QAAA,qBAAqB,GAAG,cAAc,CAAC"}
|
|
@@ -42,8 +42,15 @@ exports.findInDimensionSchemas = findInDimensionSchemas;
|
|
|
42
42
|
const findInSchemas = (name, tableSchemas) => {
|
|
43
43
|
/*
|
|
44
44
|
** Finds the dimension or measure in the provided table schemas.
|
|
45
|
-
**
|
|
45
|
+
** Handles both namespaced (`tableName.columnName`) and non-namespaced names.
|
|
46
46
|
*/
|
|
47
|
+
// TODO: Move to only using namespaced keys.
|
|
48
|
+
if (!name.includes('.')) {
|
|
49
|
+
if (tableSchemas.length > 1) {
|
|
50
|
+
throw new Error(`Multiple table schemas found for ${name} and field doesn't have a table name`);
|
|
51
|
+
}
|
|
52
|
+
return (0, exports.findInSchema)(name, tableSchemas[0]);
|
|
53
|
+
}
|
|
47
54
|
const [tableName, columnName] = (0, member_formatters_1.splitIntoDataSourceAndFields)(name);
|
|
48
55
|
const tableSchema = tableSchemas.find((table) => table.name === tableName);
|
|
49
56
|
if (!tableSchema) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-in-table-schema.js","sourceRoot":"","sources":["../../../../meerkat-core/src/utils/find-in-table-schema.ts"],"names":[],"mappings":";;;AAAA,4DAAoE;AAG7D,MAAM,qBAAqB,GAAG,CACnC,OAAe,EACf,WAAwB,EACxB,EAAE;IACF,OAAO,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC;AAChE,CAAC,CAAC;AALW,QAAA,qBAAqB,yBAKhC;AAEK,MAAM,mBAAmB,GAAG,CACjC,OAAe,EACf,WAAwB,EACxB,EAAE;IACF,OAAO,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC;AAC9D,CAAC,CAAC;AALW,QAAA,mBAAmB,uBAK9B;AAEK,MAAM,YAAY,GAAG,CAAC,OAAe,EAAE,WAAwB,EAAE,EAAE;IACxE;;;OAGG;IACH,MAAM,cAAc,GAAG,IAAA,6BAAqB,EAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IACnE,IAAI,cAAc,EAAE;QAClB,OAAO,cAAc,CAAC;KACvB;IACD,MAAM,YAAY,GAAG,IAAA,2BAAmB,EAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IAC/D,IAAI,YAAY,EAAE;QAChB,OAAO,YAAY,CAAC;KACrB;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAdW,QAAA,YAAY,gBAcvB;AAEK,MAAM,sBAAsB,GAAG,CACpC,IAAY,EACZ,YAA2B,EAC3B,EAAE;IACF;;;OAGG;IACH,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,GAAG,IAAA,gDAA4B,EAAC,IAAI,CAAC,CAAC;IACnE,MAAM,WAAW,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;IAC3E,IAAI,CAAC,WAAW,EAAE;QAChB,OAAO,SAAS,CAAC;KAClB;IACD,OAAO,IAAA,6BAAqB,EAAC,UAAU,EAAE,WAAW,CAAC,CAAC;AACxD,CAAC,CAAC;AAdW,QAAA,sBAAsB,0BAcjC;AAEK,MAAM,aAAa,GAAG,CAAC,IAAY,EAAE,YAA2B,EAAE,EAAE;IACzE;;;OAGG;IACH,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,GAAG,IAAA,gDAA4B,EAAC,IAAI,CAAC,CAAC;IACnE,MAAM,WAAW,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;IAC3E,IAAI,CAAC,WAAW,EAAE;QAChB,OAAO,SAAS,CAAC;KAClB;IACD,OAAO,IAAA,oBAAY,EAAC,UAAU,EAAE,WAAW,CAAC,CAAC;AAC/C,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"find-in-table-schema.js","sourceRoot":"","sources":["../../../../meerkat-core/src/utils/find-in-table-schema.ts"],"names":[],"mappings":";;;AAAA,4DAAoE;AAG7D,MAAM,qBAAqB,GAAG,CACnC,OAAe,EACf,WAAwB,EACxB,EAAE;IACF,OAAO,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC;AA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