@devrev/meerkat-core 0.0.79 → 0.0.80
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/get-wrapped-base-query-with-projections/get-projection-clause.js +4 -4
- package/src/get-wrapped-base-query-with-projections/get-projection-clause.js.map +1 -1
- package/src/get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections.js +1 -1
- package/src/get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections.js.map +1 -1
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@ const _cubemeasuretransformer = require("../cube-measure-transformer/cube-measur
|
|
|
9
9
|
const _memberkeytosafekey = require("../utils/member-key-to-safe-key");
|
|
10
10
|
const _getaliasedcolumnsfromfilters = require("./get-aliased-columns-from-filters");
|
|
11
11
|
const _sqlexpressionmodifiers = require("./sql-expression-modifiers");
|
|
12
|
-
const
|
|
12
|
+
const memberClauseAggregator = ({ member, aliasedColumnSet, acc, sql })=>{
|
|
13
13
|
if (aliasedColumnSet.has(member) || !sql) {
|
|
14
14
|
return acc;
|
|
15
15
|
}
|
|
@@ -32,8 +32,8 @@ const getProjectionClause = (query, tableSchema, aliasedColumnSet)=>{
|
|
|
32
32
|
modifiers: _sqlexpressionmodifiers.MODIFIERS,
|
|
33
33
|
query
|
|
34
34
|
});
|
|
35
|
-
return
|
|
36
|
-
member,
|
|
35
|
+
return memberClauseAggregator({
|
|
36
|
+
member: (0, _memberkeytosafekey.memberKeyToSafeKey)(member),
|
|
37
37
|
aliasedColumnSet,
|
|
38
38
|
acc,
|
|
39
39
|
currentIndex,
|
|
@@ -48,7 +48,7 @@ const getProjectionClause = (query, tableSchema, aliasedColumnSet)=>{
|
|
|
48
48
|
tableSchema,
|
|
49
49
|
measures
|
|
50
50
|
});
|
|
51
|
-
return
|
|
51
|
+
return memberClauseAggregator({
|
|
52
52
|
member,
|
|
53
53
|
aliasedColumnSet,
|
|
54
54
|
acc,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../meerkat-core/src/get-wrapped-base-query-with-projections/get-projection-clause.ts"],"sourcesContent":["import { getAllColumnUsedInMeasures } from '../cube-measure-transformer/cube-measure-transformer';\nimport { Query, TableSchema } from '../types/cube-types';\nimport { memberKeyToSafeKey } from '../utils/member-key-to-safe-key';\nimport { getDimensionProjection, getFilterMeasureProjection } from './get-aliased-columns-from-filters';\nimport { MODIFIERS } from './sql-expression-modifiers';\n\nconst
|
|
1
|
+
{"version":3,"sources":["../../../../meerkat-core/src/get-wrapped-base-query-with-projections/get-projection-clause.ts"],"sourcesContent":["import { getAllColumnUsedInMeasures } from '../cube-measure-transformer/cube-measure-transformer';\nimport { Query, TableSchema } from '../types/cube-types';\nimport { memberKeyToSafeKey } from '../utils/member-key-to-safe-key';\nimport { getDimensionProjection, getFilterMeasureProjection } from './get-aliased-columns-from-filters';\nimport { MODIFIERS } from './sql-expression-modifiers';\n\nconst memberClauseAggregator = ({\n member,\n aliasedColumnSet,\n acc,\n sql,\n}: {\n member: string;\n aliasedColumnSet: Set<string>;\n acc: string[];\n sql?: string;\n currentIndex: number;\n members: string[];\n}) => {\n if (aliasedColumnSet.has(member) || !sql) {\n return acc;\n }\n aliasedColumnSet.add(member);\n acc.push(sql);\n return acc;\n};\n\nexport const getProjectionClause = (\n query: Query,\n tableSchema: TableSchema,\n aliasedColumnSet: Set<string>\n) => {\n const { measures, dimensions = [] } = query;\n const filteredDimensions = dimensions.filter((dimension) => {\n return dimension.split('.')[0] === tableSchema.name;\n });\n const filteredMeasures = measures.filter((measure) => {\n return measure.split('.')[0] === tableSchema.name;\n });\n const dimensionsProjectionsArr = filteredDimensions.reduce(\n (acc, member, currentIndex, members) => {\n const { sql: memberSql } = getDimensionProjection({\n key: member,\n tableSchema,\n modifiers: MODIFIERS,\n query\n });\n return memberClauseAggregator({\n member: memberKeyToSafeKey(member),\n aliasedColumnSet,\n acc,\n currentIndex,\n members,\n sql: memberSql,\n });\n },\n [] as string[]\n );\n const dimensionsProjections = dimensionsProjectionsArr.join(', ');\n\n const measureProjectionsArr = filteredMeasures.reduce(\n (acc, member, currentIndex, members) => {\n const { sql: memberSql } = getFilterMeasureProjection({\n key: member,\n tableSchema,\n measures,\n });\n return memberClauseAggregator({\n member,\n aliasedColumnSet,\n acc,\n currentIndex,\n members,\n sql: memberSql,\n });\n },\n [] as string[]\n );\n\n const measureProjections = measureProjectionsArr.join(', ');\n\n const usedMeasureObjects = tableSchema.measures.filter((measure) => {\n return (\n measures.findIndex((key) => {\n const keyWithoutTable = key.split('.')[1];\n return keyWithoutTable === measure.name;\n }) !== -1\n );\n });\n const columnsUsedInMeasures = getAllColumnUsedInMeasures(\n usedMeasureObjects,\n tableSchema\n );\n\n let columnsUsedInMeasuresInProjection = '';\n columnsUsedInMeasures.forEach((column, index) => {\n const safeKey = memberKeyToSafeKey(column);\n columnsUsedInMeasuresInProjection += `${column} AS ${safeKey}`;\n if (index !== columnsUsedInMeasures.length - 1) {\n columnsUsedInMeasuresInProjection += ', ';\n }\n });\n\n const combinedStr = [\n dimensionsProjections,\n measureProjections,\n columnsUsedInMeasuresInProjection,\n ];\n\n return combinedStr.filter((str) => str.length > 0).join(', ');\n};\n"],"names":["getProjectionClause","memberClauseAggregator","member","aliasedColumnSet","acc","sql","has","add","push","query","tableSchema","measures","dimensions","filteredDimensions","filter","dimension","split","name","filteredMeasures","measure","dimensionsProjectionsArr","reduce","currentIndex","members","memberSql","getDimensionProjection","key","modifiers","MODIFIERS","memberKeyToSafeKey","dimensionsProjections","join","measureProjectionsArr","getFilterMeasureProjection","measureProjections","usedMeasureObjects","findIndex","keyWithoutTable","columnsUsedInMeasures","getAllColumnUsedInMeasures","columnsUsedInMeasuresInProjection","forEach","column","index","safeKey","length","combinedStr","str"],"mappings":";+BA2BaA;;;eAAAA;;;wCA3B8B;oCAER;8CACgC;wCACzC;AAE1B,MAAMC,yBAAyB,CAAC,EAC9BC,MAAM,EACNC,gBAAgB,EAChBC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,YAAYC,QAAQ,CAACG,MAAM,CAAC,CAACK;QACtD,OACER,SAASyB,SAAS,CAAC,CAACV;YAClB,MAAMW,kBAAkBX,IAAIV,KAAK,CAAC,IAAI,CAAC,EAAE;YACzC,OAAOqB,oBAAoBlB,QAAQF,IAAI;QACzC,OAAO,CAAC;IAEZ;IACA,MAAMqB,wBAAwBC,IAAAA,kDAA0B,EACtDJ,oBACAzB;IAGF,IAAI8B,oCAAoC;IACxCF,sBAAsBG,OAAO,CAAC,CAACC,QAAQC;QACrC,MAAMC,UAAUf,IAAAA,sCAAkB,EAACa;QACnCF,qCAAqC,CAAC,EAAEE,OAAO,IAAI,EAAEE,QAAQ,CAAC;QAC9D,IAAID,UAAUL,sBAAsBO,MAAM,GAAG,GAAG;YAC9CL,qCAAqC;QACvC;IACF;IAEA,MAAMM,cAAc;QAClBhB;QACAI;QACAM;KACD;IAED,OAAOM,YAAYhC,MAAM,CAAC,CAACiC,MAAQA,IAAIF,MAAM,GAAG,GAAGd,IAAI,CAAC;AAC1D"}
|
package/src/get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections.js
CHANGED
|
@@ -15,6 +15,7 @@ const getWrappedBaseQueryWithProjections = ({ baseQuery, tableSchema, query })=>
|
|
|
15
15
|
*/ // Wrap the query into another 'SELECT * FROM (baseQuery) AS baseTable'' in order to project everything in the base query, and other computed metrics to be able to filter on them
|
|
16
16
|
const newBaseSql = `SELECT * FROM (${baseQuery}) AS ${tableSchema.name}`;
|
|
17
17
|
const aliasedColumnSet = new Set();
|
|
18
|
+
const memberProjections = (0, _getprojectionclause.getProjectionClause)(query, tableSchema, aliasedColumnSet);
|
|
18
19
|
const aliasFromFilters = (0, _getaliasedcolumnsfromfilters.getAliasedColumnsFromFilters)({
|
|
19
20
|
aliasedColumnSet,
|
|
20
21
|
baseSql: 'SELECT *',
|
|
@@ -23,7 +24,6 @@ const getWrappedBaseQueryWithProjections = ({ baseQuery, tableSchema, query })=>
|
|
|
23
24
|
query,
|
|
24
25
|
meerkatFilters: query.filters
|
|
25
26
|
});
|
|
26
|
-
const memberProjections = (0, _getprojectionclause.getProjectionClause)(query, tableSchema, aliasedColumnSet);
|
|
27
27
|
const formattedMemberProjection = memberProjections ? `, ${memberProjections}` : '';
|
|
28
28
|
const finalAliasedColumnsClause = aliasFromFilters + formattedMemberProjection;
|
|
29
29
|
const sqlWithFilterProjects = (0, _cubemeasuretransformer.getSelectReplacedSql)(newBaseSql, finalAliasedColumnsClause);
|
package/src/get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../meerkat-core/src/get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections.ts"],"sourcesContent":["import { getSelectReplacedSql } from '../cube-measure-transformer/cube-measure-transformer';\nimport { Query, TableSchema } from '../types/cube-types';\nimport { getAliasedColumnsFromFilters } from './get-aliased-columns-from-filters';\nimport {\n getProjectionClause\n} from './get-projection-clause';\n\ninterface GetWrappedBaseQueryWithProjectionsParams {\n baseQuery: string;\n tableSchema: TableSchema;\n query: Query;\n}\n\nexport const getWrappedBaseQueryWithProjections = ({\n baseQuery,\n tableSchema,\n query,\n}: GetWrappedBaseQueryWithProjectionsParams) => {\n /*\n * Im order to be able to filter on computed metric from a query, we need to project the computed metric in the base query.\n * If theres filters supplied, we can safely return the original base query. Since nothing need to be projected and filtered in this case\n */\n // Wrap the query into another 'SELECT * FROM (baseQuery) AS baseTable'' in order to project everything in the base query, and other computed metrics to be able to filter on them\n const newBaseSql = `SELECT * FROM (${baseQuery}) AS ${tableSchema.name}`;\n const aliasedColumnSet = new Set<string>();\n\n const aliasFromFilters = getAliasedColumnsFromFilters({\n aliasedColumnSet,\n baseSql: 'SELECT *',\n // setting measures to empty array, since we don't want to project measures present in the filters in the base query\n tableSchema: tableSchema,\n query,\n meerkatFilters: query.filters,\n });\n\n const
|
|
1
|
+
{"version":3,"sources":["../../../../meerkat-core/src/get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections.ts"],"sourcesContent":["import { getSelectReplacedSql } from '../cube-measure-transformer/cube-measure-transformer';\nimport { Query, TableSchema } from '../types/cube-types';\nimport { getAliasedColumnsFromFilters } from './get-aliased-columns-from-filters';\nimport {\n getProjectionClause\n} from './get-projection-clause';\n\ninterface GetWrappedBaseQueryWithProjectionsParams {\n baseQuery: string;\n tableSchema: TableSchema;\n query: Query;\n}\n\nexport const getWrappedBaseQueryWithProjections = ({\n baseQuery,\n tableSchema,\n query,\n}: GetWrappedBaseQueryWithProjectionsParams) => {\n /*\n * Im order to be able to filter on computed metric from a query, we need to project the computed metric in the base query.\n * If theres filters supplied, we can safely return the original base query. Since nothing need to be projected and filtered in this case\n */\n // Wrap the query into another 'SELECT * FROM (baseQuery) AS baseTable'' in order to project everything in the base query, and other computed metrics to be able to filter on them\n const newBaseSql = `SELECT * FROM (${baseQuery}) AS ${tableSchema.name}`;\n const aliasedColumnSet = new Set<string>();\n\n const memberProjections = getProjectionClause(\n query,\n tableSchema,\n aliasedColumnSet\n );\n\n const aliasFromFilters = getAliasedColumnsFromFilters({\n aliasedColumnSet,\n baseSql: 'SELECT *',\n // setting measures to empty array, since we don't want to project measures present in the filters in the base query\n tableSchema: tableSchema,\n query,\n meerkatFilters: query.filters,\n });\n\n const formattedMemberProjection = memberProjections\n ? `, ${memberProjections}`\n : '';\n\n const finalAliasedColumnsClause =\n aliasFromFilters + formattedMemberProjection;\n\n const sqlWithFilterProjects = getSelectReplacedSql(\n newBaseSql,\n finalAliasedColumnsClause\n );\n return sqlWithFilterProjects;\n};\n"],"names":["getWrappedBaseQueryWithProjections","baseQuery","tableSchema","query","newBaseSql","name","aliasedColumnSet","Set","memberProjections","getProjectionClause","aliasFromFilters","getAliasedColumnsFromFilters","baseSql","meerkatFilters","filters","formattedMemberProjection","finalAliasedColumnsClause","sqlWithFilterProjects","getSelectReplacedSql"],"mappings":";+BAaaA;;;eAAAA;;;wCAbwB;8CAEQ;qCAGtC;AAQA,MAAMA,qCAAqC,CAAC,EACjDC,SAAS,EACTC,WAAW,EACXC,KAAK,EACoC;IACzC;;;GAGC,GACD,kLAAkL;IAClL,MAAMC,aAAa,CAAC,eAAe,EAAEH,UAAU,KAAK,EAAEC,YAAYG,IAAI,CAAC,CAAC;IACxE,MAAMC,mBAAmB,IAAIC;IAE7B,MAAMC,oBAAoBC,IAAAA,wCAAmB,EAC3CN,OACAD,aACAI;IAGF,MAAMI,mBAAmBC,IAAAA,0DAA4B,EAAC;QACpDL;QACAM,SAAS;QACT,oHAAoH;QACpHV,aAAaA;QACbC;QACAU,gBAAgBV,MAAMW,OAAO;IAC/B;IAEA,MAAMC,4BAA4BP,oBAC9B,CAAC,EAAE,EAAEA,kBAAkB,CAAC,GACxB;IAEJ,MAAMQ,4BACJN,mBAAmBK;IAErB,MAAME,wBAAwBC,IAAAA,4CAAoB,EAChDd,YACAY;IAEF,OAAOC;AACT"}
|