@devrev/meerkat-browser 0.0.82 → 0.0.83
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
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import { ContextParams, Query, TableSchema } from '@devrev/meerkat-core';
|
|
2
2
|
import { AsyncDuckDBConnection } from '@duckdb/duckdb-wasm';
|
|
3
|
-
export declare const cubeQueryToSQL: (connection
|
|
3
|
+
export declare const cubeQueryToSQL: ({ connection, query, tableSchemas, contextParams }: {
|
|
4
|
+
connection: AsyncDuckDBConnection;
|
|
5
|
+
query: Query;
|
|
6
|
+
tableSchemas: TableSchema[];
|
|
7
|
+
contextParams?: ContextParams | undefined;
|
|
8
|
+
}) => Promise<string>;
|
|
@@ -7,8 +7,8 @@ Object.defineProperty(exports, "cubeQueryToSQL", {
|
|
|
7
7
|
});
|
|
8
8
|
const _extends = require("@swc/helpers/_/_extends");
|
|
9
9
|
const _meerkatcore = require("@devrev/meerkat-core");
|
|
10
|
-
const getFilterParamsSQL = async ({
|
|
11
|
-
const filterParamsAST = (0, _meerkatcore.getFilterParamsAST)(
|
|
10
|
+
const getFilterParamsSQL = async ({ query, tableSchema, filterType, connection })=>{
|
|
11
|
+
const filterParamsAST = (0, _meerkatcore.getFilterParamsAST)(query, tableSchema, filterType);
|
|
12
12
|
const filterParamsSQL = [];
|
|
13
13
|
for (const filterParamAST of filterParamsAST){
|
|
14
14
|
if (!filterParamAST.ast) {
|
|
@@ -25,12 +25,12 @@ const getFilterParamsSQL = async ({ cubeQuery, tableSchema, filterType, connecti
|
|
|
25
25
|
}
|
|
26
26
|
return filterParamsSQL;
|
|
27
27
|
};
|
|
28
|
-
const getFinalBaseSQL = async (
|
|
28
|
+
const getFinalBaseSQL = async (query, tableSchema, connection)=>{
|
|
29
29
|
/**
|
|
30
30
|
* Apply transformation to the supplied base query.
|
|
31
31
|
* This involves updating the filter placeholder with the actual filter values.
|
|
32
32
|
*/ const baseFilterParamsSQL = await getFilterParamsSQL({
|
|
33
|
-
|
|
33
|
+
query: query,
|
|
34
34
|
tableSchema,
|
|
35
35
|
filterType: 'BASE_FILTER',
|
|
36
36
|
connection
|
|
@@ -39,19 +39,19 @@ const getFinalBaseSQL = async (cubeQuery, tableSchema, connection)=>{
|
|
|
39
39
|
const baseSQLWithFilterProjection = (0, _meerkatcore.getWrappedBaseQueryWithProjections)({
|
|
40
40
|
baseQuery: baseSQL,
|
|
41
41
|
tableSchema,
|
|
42
|
-
query:
|
|
42
|
+
query: query
|
|
43
43
|
});
|
|
44
44
|
return baseSQLWithFilterProjection;
|
|
45
45
|
};
|
|
46
|
-
const cubeQueryToSQL = async (connection,
|
|
46
|
+
const cubeQueryToSQL = async ({ connection, query, tableSchemas, contextParams })=>{
|
|
47
47
|
const updatedTableSchemas = await Promise.all(tableSchemas.map(async (schema)=>{
|
|
48
|
-
const baseFilterParamsSQL = await getFinalBaseSQL(
|
|
48
|
+
const baseFilterParamsSQL = await getFinalBaseSQL(query, schema, connection);
|
|
49
49
|
return _extends._({}, schema, {
|
|
50
50
|
sql: baseFilterParamsSQL
|
|
51
51
|
});
|
|
52
52
|
}));
|
|
53
|
-
const updatedTableSchema = await (0, _meerkatcore.getCombinedTableSchema)(updatedTableSchemas,
|
|
54
|
-
const ast = (0, _meerkatcore.cubeToDuckdbAST)(
|
|
53
|
+
const updatedTableSchema = await (0, _meerkatcore.getCombinedTableSchema)(updatedTableSchemas, query);
|
|
54
|
+
const ast = (0, _meerkatcore.cubeToDuckdbAST)(query, updatedTableSchema);
|
|
55
55
|
if (!ast) {
|
|
56
56
|
throw new Error('Could not generate AST');
|
|
57
57
|
}
|
|
@@ -61,7 +61,7 @@ const cubeQueryToSQL = async (connection, cubeQuery, tableSchemas, contextParams
|
|
|
61
61
|
const preBaseQuery = (0, _meerkatcore.deserializeQuery)(parsedOutputQuery);
|
|
62
62
|
const filterParamsSQL = await getFilterParamsSQL({
|
|
63
63
|
connection,
|
|
64
|
-
|
|
64
|
+
query,
|
|
65
65
|
tableSchema: updatedTableSchema,
|
|
66
66
|
filterType: 'BASE_FILTER'
|
|
67
67
|
});
|
|
@@ -74,8 +74,8 @@ const cubeQueryToSQL = async (connection, cubeQuery, tableSchemas, contextParams
|
|
|
74
74
|
*/ const replaceBaseTableName = preBaseQuery.replace(_meerkatcore.BASE_TABLE_NAME, `(${baseQuery}) AS ${updatedTableSchema.name}`);
|
|
75
75
|
/**
|
|
76
76
|
* Add measures to the query
|
|
77
|
-
*/ const measures =
|
|
78
|
-
const dimensions =
|
|
77
|
+
*/ const measures = query.measures;
|
|
78
|
+
const dimensions = query.dimensions || [];
|
|
79
79
|
const finalQuery = (0, _meerkatcore.applyProjectionToSQLQuery)(dimensions, measures, updatedTableSchema, replaceBaseTableName);
|
|
80
80
|
return finalQuery;
|
|
81
81
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../meerkat-browser/src/browser-cube-to-sql/browser-cube-to-sql.ts"],"sourcesContent":["import {\n BASE_TABLE_NAME,\n ContextParams,\n FilterType,\n Query,\n TableSchema,\n applyFilterParamsToBaseSQL,\n applyProjectionToSQLQuery,\n astDeserializerQuery,\n cubeToDuckdbAST,\n deserializeQuery,\n detectApplyContextParamsToBaseSQL,\n getCombinedTableSchema,\n getFilterParamsAST,\n getWrappedBaseQueryWithProjections,\n} from '@devrev/meerkat-core';\nimport { AsyncDuckDBConnection } from '@duckdb/duckdb-wasm';\n\nconst getFilterParamsSQL = async ({\n
|
|
1
|
+
{"version":3,"sources":["../../../../meerkat-browser/src/browser-cube-to-sql/browser-cube-to-sql.ts"],"sourcesContent":["import {\n BASE_TABLE_NAME,\n ContextParams,\n FilterType,\n Query,\n TableSchema,\n applyFilterParamsToBaseSQL,\n applyProjectionToSQLQuery,\n astDeserializerQuery,\n cubeToDuckdbAST,\n deserializeQuery,\n detectApplyContextParamsToBaseSQL,\n getCombinedTableSchema,\n getFilterParamsAST,\n getWrappedBaseQueryWithProjections,\n} from '@devrev/meerkat-core';\nimport { AsyncDuckDBConnection } from '@duckdb/duckdb-wasm';\n\nconst getFilterParamsSQL = async ({\n query,\n tableSchema,\n filterType,\n connection,\n}: {\n query: Query;\n tableSchema: TableSchema;\n filterType?: FilterType;\n connection: AsyncDuckDBConnection;\n}) => {\n const filterParamsAST = getFilterParamsAST(\n query,\n tableSchema,\n filterType\n );\n const filterParamsSQL = [];\n\n for (const filterParamAST of filterParamsAST) {\n if (!filterParamAST.ast) {\n continue;\n }\n\n const queryOutput = await connection.query(\n astDeserializerQuery(filterParamAST.ast)\n );\n const parsedOutputQuery = queryOutput.toArray().map((row) => row.toJSON());\n\n const sql = deserializeQuery(parsedOutputQuery);\n\n filterParamsSQL.push({\n memberKey: filterParamAST.memberKey,\n sql: sql,\n matchKey: filterParamAST.matchKey,\n });\n }\n return filterParamsSQL;\n};\n\nconst getFinalBaseSQL = async (\n query: Query,\n tableSchema: TableSchema,\n connection: AsyncDuckDBConnection\n) => {\n /**\n * Apply transformation to the supplied base query.\n * This involves updating the filter placeholder with the actual filter values.\n */\n const baseFilterParamsSQL = await getFilterParamsSQL({\n query: query,\n tableSchema,\n filterType: 'BASE_FILTER',\n connection,\n });\n const baseSQL = applyFilterParamsToBaseSQL(\n tableSchema.sql,\n baseFilterParamsSQL\n );\n const baseSQLWithFilterProjection = getWrappedBaseQueryWithProjections({\n baseQuery: baseSQL,\n tableSchema,\n query: query,\n });\n return baseSQLWithFilterProjection;\n};\n\nexport const cubeQueryToSQL = async ({\n connection,\n query,\n tableSchemas,\n contextParams\n}: {\n connection: AsyncDuckDBConnection,\n query: Query,\n tableSchemas: TableSchema[],\n contextParams?: ContextParams\n}) => {\n const updatedTableSchemas: TableSchema[] = await Promise.all(\n tableSchemas.map(async (schema: TableSchema) => {\n const baseFilterParamsSQL = await getFinalBaseSQL(\n query,\n schema,\n connection\n );\n return {\n ...schema,\n sql: baseFilterParamsSQL,\n };\n })\n );\n\n const updatedTableSchema = await getCombinedTableSchema(\n updatedTableSchemas,\n query\n );\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 arrowResult = await connection.query(queryTemp);\n const parsedOutputQuery = arrowResult.toArray().map((row) => row.toJSON());\n\n const preBaseQuery = deserializeQuery(parsedOutputQuery);\n const filterParamsSQL = await getFilterParamsSQL({\n connection,\n query,\n tableSchema: updatedTableSchema,\n filterType: 'BASE_FILTER',\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 finalQuery = applyProjectionToSQLQuery(\n dimensions,\n measures,\n updatedTableSchema,\n replaceBaseTableName\n );\n\n return finalQuery;\n};\n"],"names":["cubeQueryToSQL","getFilterParamsSQL","query","tableSchema","filterType","connection","filterParamsAST","getFilterParamsAST","filterParamsSQL","filterParamAST","ast","queryOutput","astDeserializerQuery","parsedOutputQuery","toArray","map","row","toJSON","sql","deserializeQuery","push","memberKey","matchKey","getFinalBaseSQL","baseFilterParamsSQL","baseSQL","applyFilterParamsToBaseSQL","baseSQLWithFilterProjection","getWrappedBaseQueryWithProjections","baseQuery","tableSchemas","contextParams","updatedTableSchemas","Promise","all","schema","updatedTableSchema","getCombinedTableSchema","cubeToDuckdbAST","Error","queryTemp","arrowResult","preBaseQuery","filterParamQuery","detectApplyContextParamsToBaseSQL","replaceBaseTableName","replace","BASE_TABLE_NAME","name","measures","dimensions","finalQuery","applyProjectionToSQLQuery"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