@devrev/meerkat-node 0.0.109 → 0.0.111
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.
|
@@ -43,7 +43,10 @@ const cubeQueryToSQL = async ({ query, tableSchemas, contextParams })=>{
|
|
|
43
43
|
* Add measures to the query
|
|
44
44
|
*/ const measures = query.measures;
|
|
45
45
|
const dimensions = query.dimensions || [];
|
|
46
|
-
const
|
|
46
|
+
const queryWithProjections = (0, _meerkatcore.applyProjectionToSQLQuery)(dimensions, measures, updatedTableSchema, replaceBaseTableName);
|
|
47
|
+
/**
|
|
48
|
+
* Replace SQL expression placeholders with actual SQL
|
|
49
|
+
*/ const finalQuery = (0, _meerkatcore.applySQLExpressions)(queryWithProjections);
|
|
47
50
|
return finalQuery;
|
|
48
51
|
};
|
|
49
52
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../meerkat-node/src/cube-to-sql/cube-to-sql.ts"],"sourcesContent":["import {\n BASE_TABLE_NAME,\n ContextParams,\n Query,\n TableSchema,\n applyFilterParamsToBaseSQL,\n applyProjectionToSQLQuery,\n astDeserializerQuery,\n cubeToDuckdbAST,\n deserializeQuery,\n detectApplyContextParamsToBaseSQL,\n getCombinedTableSchema,\n getFilterParamsSQL,\n getFinalBaseSQL,\n} from '@devrev/meerkat-core';\nimport { duckdbExec } from '../duckdb-exec';\n\nexport interface CubeQueryToSQLParams {\n query: Query;\n tableSchemas: TableSchema[];\n contextParams?: ContextParams;\n}\n\nexport const cubeQueryToSQL = async ({\n query,\n tableSchemas,\n contextParams,\n}: CubeQueryToSQLParams) => {\n const updatedTableSchemas: TableSchema[] = await Promise.all(\n tableSchemas.map(async (schema: TableSchema) => {\n const baseFilterParamsSQL = await getFinalBaseSQL({\n query,\n tableSchema: schema,\n getQueryOutput: duckdbExec,\n });\n return {\n ...schema,\n sql: baseFilterParamsSQL,\n };\n })\n );\n\n const updatedTableSchema = getCombinedTableSchema(updatedTableSchemas, query);\n\n const ast = cubeToDuckdbAST(query, updatedTableSchema);\n if (!ast) {\n throw new Error('Could not generate AST');\n }\n\n const queryTemp = astDeserializerQuery(ast);\n\n const queryOutput = (await duckdbExec(queryTemp)) as Record<string, string>[];\n const preBaseQuery = deserializeQuery(queryOutput);\n\n const filterParamsSQL = await getFilterParamsSQL({\n query,\n tableSchema: updatedTableSchema,\n getQueryOutput: duckdbExec,\n });\n\n const filterParamQuery = applyFilterParamsToBaseSQL(\n updatedTableSchema.sql,\n filterParamsSQL\n );\n\n /**\n * Replace CONTEXT_PARAMS with context params\n */\n const baseQuery = detectApplyContextParamsToBaseSQL(\n filterParamQuery,\n contextParams || {}\n );\n\n /**\n * Replace BASE_TABLE_NAME with cube query\n */\n const replaceBaseTableName = preBaseQuery.replace(\n BASE_TABLE_NAME,\n `(${baseQuery}) AS ${updatedTableSchema.name}`\n );\n\n /**\n * Add measures to the query\n */\n const measures = query.measures;\n const dimensions = query.dimensions || [];\n const
|
|
1
|
+
{"version":3,"sources":["../../../meerkat-node/src/cube-to-sql/cube-to-sql.ts"],"sourcesContent":["import {\n BASE_TABLE_NAME,\n ContextParams,\n Query,\n TableSchema,\n applyFilterParamsToBaseSQL,\n applyProjectionToSQLQuery,\n applySQLExpressions,\n astDeserializerQuery,\n cubeToDuckdbAST,\n deserializeQuery,\n detectApplyContextParamsToBaseSQL,\n getCombinedTableSchema,\n getFilterParamsSQL,\n getFinalBaseSQL,\n} from '@devrev/meerkat-core';\nimport { duckdbExec } from '../duckdb-exec';\n\nexport interface CubeQueryToSQLParams {\n query: Query;\n tableSchemas: TableSchema[];\n contextParams?: ContextParams;\n}\n\nexport const cubeQueryToSQL = async ({\n query,\n tableSchemas,\n contextParams,\n}: CubeQueryToSQLParams) => {\n const updatedTableSchemas: TableSchema[] = await Promise.all(\n tableSchemas.map(async (schema: TableSchema) => {\n const baseFilterParamsSQL = await getFinalBaseSQL({\n query,\n tableSchema: schema,\n getQueryOutput: duckdbExec,\n });\n return {\n ...schema,\n sql: baseFilterParamsSQL,\n };\n })\n );\n\n const updatedTableSchema = getCombinedTableSchema(updatedTableSchemas, query);\n\n const ast = cubeToDuckdbAST(query, updatedTableSchema);\n if (!ast) {\n throw new Error('Could not generate AST');\n }\n\n const queryTemp = astDeserializerQuery(ast);\n\n const queryOutput = (await duckdbExec(queryTemp)) as Record<string, string>[];\n const preBaseQuery = deserializeQuery(queryOutput);\n\n const filterParamsSQL = await getFilterParamsSQL({\n query,\n tableSchema: updatedTableSchema,\n getQueryOutput: duckdbExec,\n });\n\n const filterParamQuery = applyFilterParamsToBaseSQL(\n updatedTableSchema.sql,\n filterParamsSQL\n );\n\n /**\n * Replace CONTEXT_PARAMS with context params\n */\n const baseQuery = detectApplyContextParamsToBaseSQL(\n filterParamQuery,\n contextParams || {}\n );\n\n /**\n * Replace BASE_TABLE_NAME with cube query\n */\n const replaceBaseTableName = preBaseQuery.replace(\n BASE_TABLE_NAME,\n `(${baseQuery}) AS ${updatedTableSchema.name}`\n );\n\n /**\n * Add measures to the query\n */\n const measures = query.measures;\n const dimensions = query.dimensions || [];\n const queryWithProjections = applyProjectionToSQLQuery(\n dimensions,\n measures,\n updatedTableSchema,\n replaceBaseTableName\n );\n\n /**\n * Replace SQL expression placeholders with actual SQL\n */\n const finalQuery = applySQLExpressions(queryWithProjections);\n\n return finalQuery;\n};\n"],"names":["cubeQueryToSQL","query","tableSchemas","contextParams","updatedTableSchemas","Promise","all","map","schema","baseFilterParamsSQL","getFinalBaseSQL","tableSchema","getQueryOutput","duckdbExec","sql","updatedTableSchema","getCombinedTableSchema","ast","cubeToDuckdbAST","Error","queryTemp","astDeserializerQuery","queryOutput","preBaseQuery","deserializeQuery","filterParamsSQL","getFilterParamsSQL","filterParamQuery","applyFilterParamsToBaseSQL","baseQuery","detectApplyContextParamsToBaseSQL","replaceBaseTableName","replace","BASE_TABLE_NAME","name","measures","dimensions","queryWithProjections","applyProjectionToSQLQuery","finalQuery","applySQLExpressions"],"mappings":";+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