@devrev/meerkat-browser 0.0.75
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/README.md +11 -0
- package/package.json +29 -0
- package/src/browser-cube-to-sql/browser-cube-to-sql.d.ts +3 -0
- package/src/browser-cube-to-sql/browser-cube-to-sql.js +83 -0
- package/src/browser-cube-to-sql/browser-cube-to-sql.js.map +1 -0
- package/src/index.d.ts +3 -0
- package/src/index.js +12 -0
- package/src/index.js.map +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# meerkat-browser
|
|
2
|
+
|
|
3
|
+
This library was generated with [Nx](https://nx.dev).
|
|
4
|
+
|
|
5
|
+
## Building
|
|
6
|
+
|
|
7
|
+
Run `nx build meerkat-browser` to build the library.
|
|
8
|
+
|
|
9
|
+
## Running unit tests
|
|
10
|
+
|
|
11
|
+
Run `nx test meerkat-browser` to execute the unit tests via [Jest](https://jestjs.io).
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@devrev/meerkat-browser",
|
|
3
|
+
"version": "0.0.75",
|
|
4
|
+
"dependencies": {
|
|
5
|
+
"@swc/helpers": "~0.5.0",
|
|
6
|
+
"@devrev/meerkat-core": "*",
|
|
7
|
+
"@duckdb/duckdb-wasm": "^1.27.1-dev125.0"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"release": "semantic-release"
|
|
11
|
+
},
|
|
12
|
+
"release": {
|
|
13
|
+
"plugins": [
|
|
14
|
+
"@semantic-release/commit-analyzer",
|
|
15
|
+
"@semantic-release/release-notes-generator",
|
|
16
|
+
"@semantic-release/github"
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
"type": "commonjs",
|
|
20
|
+
"main": "./src/index.js",
|
|
21
|
+
"typings": "./src/index.d.ts",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/devrev/meerkat.git"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"registry": "https://registry.npmjs.org"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ContextParams, Query, TableSchema } from '@devrev/meerkat-core';
|
|
2
|
+
import { AsyncDuckDBConnection } from '@duckdb/duckdb-wasm';
|
|
3
|
+
export declare const cubeQueryToSQL: (connection: AsyncDuckDBConnection, cubeQuery: Query, tableSchemas: TableSchema[], contextParams?: ContextParams) => Promise<string>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "cubeQueryToSQL", {
|
|
3
|
+
enumerable: true,
|
|
4
|
+
get: function() {
|
|
5
|
+
return cubeQueryToSQL;
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
const _extends = require("@swc/helpers/_/_extends");
|
|
9
|
+
const _meerkatcore = require("@devrev/meerkat-core");
|
|
10
|
+
const getFilterParamsSQL = async ({ cubeQuery, tableSchema, filterType, connection })=>{
|
|
11
|
+
const filterParamsAST = (0, _meerkatcore.getFilterParamsAST)(cubeQuery, tableSchema, filterType);
|
|
12
|
+
const filterParamsSQL = [];
|
|
13
|
+
for (const filterParamAST of filterParamsAST){
|
|
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 (cubeQuery, 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
|
+
cubeQuery: cubeQuery,
|
|
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: cubeQuery
|
|
43
|
+
});
|
|
44
|
+
return baseSQLWithFilterProjection;
|
|
45
|
+
};
|
|
46
|
+
const cubeQueryToSQL = async (connection, cubeQuery, tableSchemas, contextParams)=>{
|
|
47
|
+
const updatedTableSchemas = await Promise.all(tableSchemas.map(async (schema)=>{
|
|
48
|
+
const baseFilterParamsSQL = await getFinalBaseSQL(cubeQuery, schema, connection);
|
|
49
|
+
return _extends._({}, schema, {
|
|
50
|
+
sql: baseFilterParamsSQL
|
|
51
|
+
});
|
|
52
|
+
}));
|
|
53
|
+
const updatedTableSchema = await (0, _meerkatcore.getCombinedTableSchema)(updatedTableSchemas, cubeQuery);
|
|
54
|
+
const ast = (0, _meerkatcore.cubeToDuckdbAST)(cubeQuery, updatedTableSchema);
|
|
55
|
+
if (!ast) {
|
|
56
|
+
throw new Error('Could not generate AST');
|
|
57
|
+
}
|
|
58
|
+
const queryTemp = (0, _meerkatcore.astDeserializerQuery)(ast);
|
|
59
|
+
const arrowResult = await connection.query(queryTemp);
|
|
60
|
+
const parsedOutputQuery = arrowResult.toArray().map((row)=>row.toJSON());
|
|
61
|
+
const preBaseQuery = (0, _meerkatcore.deserializeQuery)(parsedOutputQuery);
|
|
62
|
+
const filterParamsSQL = await getFilterParamsSQL({
|
|
63
|
+
connection,
|
|
64
|
+
cubeQuery,
|
|
65
|
+
tableSchema: updatedTableSchema,
|
|
66
|
+
filterType: 'BASE_FILTER'
|
|
67
|
+
});
|
|
68
|
+
const filterParamQuery = (0, _meerkatcore.applyFilterParamsToBaseSQL)(updatedTableSchema.sql, filterParamsSQL);
|
|
69
|
+
/**
|
|
70
|
+
* Replace CONTEXT_PARAMS with context params
|
|
71
|
+
*/ const baseQuery = (0, _meerkatcore.detectApplyContextParamsToBaseSQL)(filterParamQuery, contextParams || {});
|
|
72
|
+
/**
|
|
73
|
+
* Replace BASE_TABLE_NAME with cube query
|
|
74
|
+
*/ const replaceBaseTableName = preBaseQuery.replace(_meerkatcore.BASE_TABLE_NAME, `(${baseQuery}) AS ${updatedTableSchema.name}`);
|
|
75
|
+
/**
|
|
76
|
+
* Add measures to the query
|
|
77
|
+
*/ const measures = cubeQuery.measures;
|
|
78
|
+
const dimensions = cubeQuery.dimensions || [];
|
|
79
|
+
const finalQuery = (0, _meerkatcore.applyProjectionToSQLQuery)(dimensions, measures, updatedTableSchema, replaceBaseTableName);
|
|
80
|
+
return finalQuery;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
//# sourceMappingURL=browser-cube-to-sql.js.map
|
|
@@ -0,0 +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 cubeQuery,\n tableSchema,\n filterType,\n connection,\n}: {\n cubeQuery: Query;\n tableSchema: TableSchema;\n filterType?: FilterType;\n connection: AsyncDuckDBConnection;\n}) => {\n const filterParamsAST = getFilterParamsAST(\n cubeQuery,\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 cubeQuery: 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 cubeQuery: cubeQuery,\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: cubeQuery,\n });\n return baseSQLWithFilterProjection;\n};\n\nexport const cubeQueryToSQL = async (\n connection: AsyncDuckDBConnection,\n cubeQuery: 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 cubeQuery,\n schema,\n connection\n );\n return {\n ...schema,\n sql: baseFilterParamsSQL,\n };\n })\n );\n\n const updatedTableSchema = await getCombinedTableSchema(\n updatedTableSchemas,\n cubeQuery\n );\n\n const ast = cubeToDuckdbAST(cubeQuery, 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 cubeQuery,\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 = cubeQuery.measures;\n const dimensions = cubeQuery.dimensions || [];\n const finalQuery = applyProjectionToSQLQuery(\n dimensions,\n measures,\n updatedTableSchema,\n replaceBaseTableName\n );\n\n return finalQuery;\n};\n"],"names":["cubeQueryToSQL","getFilterParamsSQL","cubeQuery","tableSchema","filterType","connection","filterParamsAST","getFilterParamsAST","filterParamsSQL","filterParamAST","ast","queryOutput","query","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"],"mappings":";+BAoFaA;;;eAAAA;;;;6BArEN;AAGP,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,IAAI,CAAC3B,KAAK;QACR,MAAM,IAAI8B,MAAM;IAClB;IAEA,MAAMC,YAAY5B,IAAAA,iCAAoB,EAACH;IAEvC,MAAMgC,cAAc,MAAMrC,WAAWO,KAAK,CAAC6B;IAC3C,MAAM3B,oBAAoB4B,YAAY3B,OAAO,GAAGC,GAAG,CAAC,CAACC,MAAQA,IAAIC,MAAM;IAEvE,MAAMyB,eAAevB,IAAAA,6BAAgB,EAACN;IACtC,MAAMN,kBAAkB,MAAMP,mBAAmB;QAC/CI;QACAH;QACAC,aAAakC;QACbjC,YAAY;IACd;IAEA,MAAMwC,mBAAmBjB,IAAAA,uCAA0B,EACjDU,mBAAmBlB,GAAG,EACtBX;IAGF;;GAEC,GACD,MAAMsB,YAAYe,IAAAA,8CAAiC,EACjDD,kBACAZ,iBAAiB,CAAC;IAGpB;;GAEC,GACD,MAAMc,uBAAuBH,aAAaI,OAAO,CAC/CC,4BAAe,EACf,CAAC,CAAC,EAAElB,UAAU,KAAK,EAAEO,mBAAmBY,IAAI,CAAC,CAAC;IAGhD;;GAEC,GACD,MAAMC,WAAWhD,UAAUgD,QAAQ;IACnC,MAAMC,aAAajD,UAAUiD,UAAU,IAAI,EAAE;IAC7C,MAAMC,aAAaC,IAAAA,sCAAyB,EAC1CF,YACAD,UACAb,oBACAS;IAGF,OAAOM;AACT"}
|
package/src/index.d.ts
ADDED
package/src/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "convertCubeStringToTableSchema", {
|
|
3
|
+
enumerable: true,
|
|
4
|
+
get: function() {
|
|
5
|
+
return _meerkatcore.convertCubeStringToTableSchema;
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
const _export_star = require("@swc/helpers/_/_export_star");
|
|
9
|
+
_export_star._(require("./browser-cube-to-sql/browser-cube-to-sql"), exports);
|
|
10
|
+
const _meerkatcore = require("@devrev/meerkat-core");
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../meerkat-browser/src/index.ts"],"sourcesContent":["export * from './browser-cube-to-sql/browser-cube-to-sql';\nexport { convertCubeStringToTableSchema };\nimport { convertCubeStringToTableSchema } from '@devrev/meerkat-core';\n"],"names":["convertCubeStringToTableSchema"],"mappings":";+BACSA;;;eAAAA,2CAA8B;;;;uBADzB;6BAEiC"}
|