@devrev/meerkat-browser 0.0.83 → 0.0.84
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,8 +1,10 @@
|
|
|
1
1
|
import { ContextParams, Query, TableSchema } from '@devrev/meerkat-core';
|
|
2
2
|
import { AsyncDuckDBConnection } from '@duckdb/duckdb-wasm';
|
|
3
|
-
|
|
3
|
+
interface CubeQueryToSQLParams {
|
|
4
4
|
connection: AsyncDuckDBConnection;
|
|
5
5
|
query: Query;
|
|
6
6
|
tableSchemas: TableSchema[];
|
|
7
|
-
contextParams?: ContextParams
|
|
8
|
-
}
|
|
7
|
+
contextParams?: ContextParams;
|
|
8
|
+
}
|
|
9
|
+
export declare const cubeQueryToSQL: ({ connection, query, tableSchemas, contextParams }: CubeQueryToSQLParams) => Promise<string>;
|
|
10
|
+
export {};
|
|
@@ -7,45 +7,18 @@ Object.defineProperty(exports, "cubeQueryToSQL", {
|
|
|
7
7
|
});
|
|
8
8
|
const _extends = require("@swc/helpers/_/_extends");
|
|
9
9
|
const _meerkatcore = require("@devrev/meerkat-core");
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
if (!filterParamAST.ast) {
|
|
15
|
-
continue;
|
|
16
|
-
}
|
|
17
|
-
const queryOutput = await connection.query((0, _meerkatcore.astDeserializerQuery)(filterParamAST.ast));
|
|
18
|
-
const parsedOutputQuery = queryOutput.toArray().map((row)=>row.toJSON());
|
|
19
|
-
const sql = (0, _meerkatcore.deserializeQuery)(parsedOutputQuery);
|
|
20
|
-
filterParamsSQL.push({
|
|
21
|
-
memberKey: filterParamAST.memberKey,
|
|
22
|
-
sql: sql,
|
|
23
|
-
matchKey: filterParamAST.matchKey
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
return filterParamsSQL;
|
|
27
|
-
};
|
|
28
|
-
const getFinalBaseSQL = async (query, tableSchema, connection)=>{
|
|
29
|
-
/**
|
|
30
|
-
* Apply transformation to the supplied base query.
|
|
31
|
-
* This involves updating the filter placeholder with the actual filter values.
|
|
32
|
-
*/ const baseFilterParamsSQL = await getFilterParamsSQL({
|
|
33
|
-
query: query,
|
|
34
|
-
tableSchema,
|
|
35
|
-
filterType: 'BASE_FILTER',
|
|
36
|
-
connection
|
|
37
|
-
});
|
|
38
|
-
const baseSQL = (0, _meerkatcore.applyFilterParamsToBaseSQL)(tableSchema.sql, baseFilterParamsSQL);
|
|
39
|
-
const baseSQLWithFilterProjection = (0, _meerkatcore.getWrappedBaseQueryWithProjections)({
|
|
40
|
-
baseQuery: baseSQL,
|
|
41
|
-
tableSchema,
|
|
42
|
-
query: query
|
|
43
|
-
});
|
|
44
|
-
return baseSQLWithFilterProjection;
|
|
10
|
+
const getQueryOutput = async (query, connection)=>{
|
|
11
|
+
const queryOutput = await connection.query(query);
|
|
12
|
+
const parsedOutputQuery = queryOutput.toArray().map((row)=>row.toJSON());
|
|
13
|
+
return parsedOutputQuery;
|
|
45
14
|
};
|
|
46
15
|
const cubeQueryToSQL = async ({ connection, query, tableSchemas, contextParams })=>{
|
|
47
16
|
const updatedTableSchemas = await Promise.all(tableSchemas.map(async (schema)=>{
|
|
48
|
-
const baseFilterParamsSQL = await
|
|
17
|
+
const baseFilterParamsSQL = await (0, _meerkatcore.getFinalBaseSQL)({
|
|
18
|
+
query,
|
|
19
|
+
tableSchema: schema,
|
|
20
|
+
getQueryOutput: (query)=>getQueryOutput(query, connection)
|
|
21
|
+
});
|
|
49
22
|
return _extends._({}, schema, {
|
|
50
23
|
sql: baseFilterParamsSQL
|
|
51
24
|
});
|
|
@@ -59,8 +32,8 @@ const cubeQueryToSQL = async ({ connection, query, tableSchemas, contextParams }
|
|
|
59
32
|
const arrowResult = await connection.query(queryTemp);
|
|
60
33
|
const parsedOutputQuery = arrowResult.toArray().map((row)=>row.toJSON());
|
|
61
34
|
const preBaseQuery = (0, _meerkatcore.deserializeQuery)(parsedOutputQuery);
|
|
62
|
-
const filterParamsSQL = await getFilterParamsSQL({
|
|
63
|
-
connection,
|
|
35
|
+
const filterParamsSQL = await (0, _meerkatcore.getFilterParamsSQL)({
|
|
36
|
+
getQueryOutput: (query)=>getQueryOutput(query, connection),
|
|
64
37
|
query,
|
|
65
38
|
tableSchema: updatedTableSchema,
|
|
66
39
|
filterType: 'BASE_FILTER'
|
|
@@ -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
|
|
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 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 { AsyncDuckDBConnection } from '@duckdb/duckdb-wasm';\n\n\nconst getQueryOutput = async (query: string, connection: AsyncDuckDBConnection) => {\n const queryOutput = await connection.query(query);\n const parsedOutputQuery = queryOutput.toArray().map((row) => row.toJSON());\n return parsedOutputQuery;\n}\n\n\ninterface CubeQueryToSQLParams {\n connection: AsyncDuckDBConnection,\n query: Query,\n tableSchemas: TableSchema[],\n contextParams?: ContextParams,\n}\n\nexport const cubeQueryToSQL = async ({\n connection,\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: (query) => getQueryOutput(query, 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 getQueryOutput: (query) => getQueryOutput(query, 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","getQueryOutput","query","connection","queryOutput","parsedOutputQuery","toArray","map","row","toJSON","tableSchemas","contextParams","updatedTableSchemas","Promise","all","schema","baseFilterParamsSQL","getFinalBaseSQL","tableSchema","sql","updatedTableSchema","getCombinedTableSchema","ast","cubeToDuckdbAST","Error","queryTemp","astDeserializerQuery","arrowResult","preBaseQuery","deserializeQuery","filterParamsSQL","getFilterParamsSQL","filterType","filterParamQuery","applyFilterParamsToBaseSQL","baseQuery","detectApplyContextParamsToBaseSQL","replaceBaseTableName","replace","BASE_TABLE_NAME","name","measures","dimensions","finalQuery","applyProjectionToSQLQuery"],"mappings":";+BAgCaA;;;eAAAA;;;;6BAlBN;AA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