@devrev/meerkat-core 0.0.77
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 +30 -0
- package/src/ast-builder/ast-builder.d.ts +6 -0
- package/src/ast-builder/ast-builder.js +89 -0
- package/src/ast-builder/ast-builder.js.map +1 -0
- package/src/ast-deserializer/ast-deserializer.d.ts +5 -0
- package/src/ast-deserializer/ast-deserializer.js +30 -0
- package/src/ast-deserializer/ast-deserializer.js.map +1 -0
- package/src/context-params/context-params-ast.d.ts +11 -0
- package/src/context-params/context-params-ast.js +55 -0
- package/src/context-params/context-params-ast.js.map +1 -0
- package/src/cube-filter-transformer/and/and.d.ts +2 -0
- package/src/cube-filter-transformer/and/and.js +18 -0
- package/src/cube-filter-transformer/and/and.js.map +1 -0
- package/src/cube-filter-transformer/base-condition-builder/base-condition-builder.d.ts +154 -0
- package/src/cube-filter-transformer/base-condition-builder/base-condition-builder.js +159 -0
- package/src/cube-filter-transformer/base-condition-builder/base-condition-builder.js.map +1 -0
- package/src/cube-filter-transformer/contains/contains.d.ts +65 -0
- package/src/cube-filter-transformer/contains/contains.js +70 -0
- package/src/cube-filter-transformer/contains/contains.js.map +1 -0
- package/src/cube-filter-transformer/equals/equals-array.d.ts +2 -0
- package/src/cube-filter-transformer/equals/equals-array.js +30 -0
- package/src/cube-filter-transformer/equals/equals-array.js.map +1 -0
- package/src/cube-filter-transformer/equals/equals.d.ts +2 -0
- package/src/cube-filter-transformer/equals/equals.js +37 -0
- package/src/cube-filter-transformer/equals/equals.js.map +1 -0
- package/src/cube-filter-transformer/factory.d.ts +5 -0
- package/src/cube-filter-transformer/factory.js +124 -0
- package/src/cube-filter-transformer/factory.js.map +1 -0
- package/src/cube-filter-transformer/gt/gt.d.ts +2 -0
- package/src/cube-filter-transformer/gt/gt.js +30 -0
- package/src/cube-filter-transformer/gt/gt.js.map +1 -0
- package/src/cube-filter-transformer/gte/gte.d.ts +2 -0
- package/src/cube-filter-transformer/gte/gte.js +30 -0
- package/src/cube-filter-transformer/gte/gte.js.map +1 -0
- package/src/cube-filter-transformer/in/in.d.ts +2 -0
- package/src/cube-filter-transformer/in/in.js +77 -0
- package/src/cube-filter-transformer/in/in.js.map +1 -0
- package/src/cube-filter-transformer/in-date-range/in-date-range.d.ts +2 -0
- package/src/cube-filter-transformer/in-date-range/in-date-range.js +24 -0
- package/src/cube-filter-transformer/in-date-range/in-date-range.js.map +1 -0
- package/src/cube-filter-transformer/lt/lt.d.ts +2 -0
- package/src/cube-filter-transformer/lt/lt.js +30 -0
- package/src/cube-filter-transformer/lt/lt.js.map +1 -0
- package/src/cube-filter-transformer/lte/lte.d.ts +2 -0
- package/src/cube-filter-transformer/lte/lte.js +30 -0
- package/src/cube-filter-transformer/lte/lte.js.map +1 -0
- package/src/cube-filter-transformer/not/not.d.ts +2 -0
- package/src/cube-filter-transformer/not/not.js +18 -0
- package/src/cube-filter-transformer/not/not.js.map +1 -0
- package/src/cube-filter-transformer/not-In-date-range/not-In-date-range.d.ts +2 -0
- package/src/cube-filter-transformer/not-In-date-range/not-In-date-range.js +24 -0
- package/src/cube-filter-transformer/not-In-date-range/not-In-date-range.js.map +1 -0
- package/src/cube-filter-transformer/not-contains/not-contains.d.ts +65 -0
- package/src/cube-filter-transformer/not-contains/not-contains.js +70 -0
- package/src/cube-filter-transformer/not-contains/not-contains.js.map +1 -0
- package/src/cube-filter-transformer/not-equals/not-equals-array.d.ts +2 -0
- package/src/cube-filter-transformer/not-equals/not-equals-array.js +26 -0
- package/src/cube-filter-transformer/not-equals/not-equals-array.js.map +1 -0
- package/src/cube-filter-transformer/not-equals/not-equals.d.ts +8 -0
- package/src/cube-filter-transformer/not-equals/not-equals.js +37 -0
- package/src/cube-filter-transformer/not-equals/not-equals.js.map +1 -0
- package/src/cube-filter-transformer/not-in/not-in.d.ts +2 -0
- package/src/cube-filter-transformer/not-in/not-in.js +84 -0
- package/src/cube-filter-transformer/not-in/not-in.js.map +1 -0
- package/src/cube-filter-transformer/not-set/not-set.d.ts +2 -0
- package/src/cube-filter-transformer/not-set/not-set.js +26 -0
- package/src/cube-filter-transformer/not-set/not-set.js.map +1 -0
- package/src/cube-filter-transformer/or/or.d.ts +2 -0
- package/src/cube-filter-transformer/or/or.js +18 -0
- package/src/cube-filter-transformer/or/or.js.map +1 -0
- package/src/cube-filter-transformer/set/set.d.ts +2 -0
- package/src/cube-filter-transformer/set/set.js +26 -0
- package/src/cube-filter-transformer/set/set.js.map +1 -0
- package/src/cube-group-by-transformer/cube-group-by-transformer.d.ts +8 -0
- package/src/cube-group-by-transformer/cube-group-by-transformer.js +25 -0
- package/src/cube-group-by-transformer/cube-group-by-transformer.js.map +1 -0
- package/src/cube-limit-offset-transformer/cube-limit-offset-transformer.d.ts +31 -0
- package/src/cube-limit-offset-transformer/cube-limit-offset-transformer.js +42 -0
- package/src/cube-limit-offset-transformer/cube-limit-offset-transformer.js.map +1 -0
- package/src/cube-measure-transformer/cube-measure-transformer.d.ts +21 -0
- package/src/cube-measure-transformer/cube-measure-transformer.js +126 -0
- package/src/cube-measure-transformer/cube-measure-transformer.js.map +1 -0
- package/src/cube-order-by-transformer/cube-order-by-transformer.d.ts +21 -0
- package/src/cube-order-by-transformer/cube-order-by-transformer.js +39 -0
- package/src/cube-order-by-transformer/cube-order-by-transformer.js.map +1 -0
- package/src/cube-to-duckdb/cube-filter-to-duckdb.d.ts +16 -0
- package/src/cube-to-duckdb/cube-filter-to-duckdb.js +3 -0
- package/src/cube-to-duckdb/cube-filter-to-duckdb.js.map +1 -0
- package/src/filter-params/filter-params-ast.d.ts +33 -0
- package/src/filter-params/filter-params-ast.js +115 -0
- package/src/filter-params/filter-params-ast.js.map +1 -0
- package/src/get-projection-clause/get-projection-clause.d.ts +27 -0
- package/src/get-projection-clause/get-projection-clause.js +135 -0
- package/src/get-projection-clause/get-projection-clause.js.map +1 -0
- package/src/get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections.d.ts +8 -0
- package/src/get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections.js +99 -0
- package/src/get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections.js.map +1 -0
- package/src/index.d.ts +16 -0
- package/src/index.js +55 -0
- package/src/index.js.map +1 -0
- package/src/joins/joins.d.ts +22 -0
- package/src/joins/joins.js +170 -0
- package/src/joins/joins.js.map +1 -0
- package/src/types/cube-types/index.d.js +6 -0
- package/src/types/cube-types/index.d.js.map +1 -0
- package/src/types/cube-types/index.d.ts +2 -0
- package/src/types/cube-types/index.js +6 -0
- package/src/types/cube-types/index.js.map +1 -0
- package/src/types/cube-types/query.d.js +5 -0
- package/src/types/cube-types/query.d.js.map +1 -0
- package/src/types/cube-types/query.d.ts +141 -0
- package/src/types/cube-types/query.js +14 -0
- package/src/types/cube-types/query.js.map +1 -0
- package/src/types/cube-types/table.d.js +3 -0
- package/src/types/cube-types/table.d.js.map +1 -0
- package/src/types/cube-types/table.d.ts +25 -0
- package/src/types/cube-types/table.js +3 -0
- package/src/types/cube-types/table.js.map +1 -0
- package/src/types/duckdb-serialization-types/index.d.js +11 -0
- package/src/types/duckdb-serialization-types/index.d.js.map +1 -0
- package/src/types/duckdb-serialization-types/index.d.ts +7 -0
- package/src/types/duckdb-serialization-types/index.js +11 -0
- package/src/types/duckdb-serialization-types/index.js.map +1 -0
- package/src/types/duckdb-serialization-types/serialization/Constraint.d.ts +47 -0
- package/src/types/duckdb-serialization-types/serialization/Constraint.js +31 -0
- package/src/types/duckdb-serialization-types/serialization/Constraint.js.map +1 -0
- package/src/types/duckdb-serialization-types/serialization/CreateInfo.d.ts +95 -0
- package/src/types/duckdb-serialization-types/serialization/CreateInfo.js +67 -0
- package/src/types/duckdb-serialization-types/serialization/CreateInfo.js.map +1 -0
- package/src/types/duckdb-serialization-types/serialization/Expression.d.js +3 -0
- package/src/types/duckdb-serialization-types/serialization/Expression.d.js.map +1 -0
- package/src/types/duckdb-serialization-types/serialization/Expression.d.ts +186 -0
- package/src/types/duckdb-serialization-types/serialization/Expression.js +130 -0
- package/src/types/duckdb-serialization-types/serialization/Expression.js.map +1 -0
- package/src/types/duckdb-serialization-types/serialization/LogicalOperator.d.ts +231 -0
- package/src/types/duckdb-serialization-types/serialization/LogicalOperator.js +47 -0
- package/src/types/duckdb-serialization-types/serialization/LogicalOperator.js.map +1 -0
- package/src/types/duckdb-serialization-types/serialization/MacroFunction.d.ts +20 -0
- package/src/types/duckdb-serialization-types/serialization/MacroFunction.js +15 -0
- package/src/types/duckdb-serialization-types/serialization/MacroFunction.js.map +1 -0
- package/src/types/duckdb-serialization-types/serialization/Misc.d.js +3 -0
- package/src/types/duckdb-serialization-types/serialization/Misc.d.js.map +1 -0
- package/src/types/duckdb-serialization-types/serialization/Misc.d.ts +3 -0
- package/src/types/duckdb-serialization-types/serialization/Misc.js +3 -0
- package/src/types/duckdb-serialization-types/serialization/Misc.js.map +1 -0
- package/src/types/duckdb-serialization-types/serialization/Nodes.d.js +10 -0
- package/src/types/duckdb-serialization-types/serialization/Nodes.d.js.map +1 -0
- package/src/types/duckdb-serialization-types/serialization/Nodes.d.ts +212 -0
- package/src/types/duckdb-serialization-types/serialization/Nodes.js +92 -0
- package/src/types/duckdb-serialization-types/serialization/Nodes.js.map +1 -0
- package/src/types/duckdb-serialization-types/serialization/ParseInfo.d.ts +192 -0
- package/src/types/duckdb-serialization-types/serialization/ParseInfo.js +128 -0
- package/src/types/duckdb-serialization-types/serialization/ParseInfo.js.map +1 -0
- package/src/types/duckdb-serialization-types/serialization/ParsedExpression.d.js +3 -0
- package/src/types/duckdb-serialization-types/serialization/ParsedExpression.d.js.map +1 -0
- package/src/types/duckdb-serialization-types/serialization/ParsedExpression.d.ts +114 -0
- package/src/types/duckdb-serialization-types/serialization/ParsedExpression.js +37 -0
- package/src/types/duckdb-serialization-types/serialization/ParsedExpression.js.map +1 -0
- package/src/types/duckdb-serialization-types/serialization/QueryNode.d.js +3 -0
- package/src/types/duckdb-serialization-types/serialization/QueryNode.d.js.map +1 -0
- package/src/types/duckdb-serialization-types/serialization/QueryNode.d.ts +62 -0
- package/src/types/duckdb-serialization-types/serialization/QueryNode.js +42 -0
- package/src/types/duckdb-serialization-types/serialization/QueryNode.js.map +1 -0
- package/src/types/duckdb-serialization-types/serialization/ResultModifier.d.js +3 -0
- package/src/types/duckdb-serialization-types/serialization/ResultModifier.d.js.map +1 -0
- package/src/types/duckdb-serialization-types/serialization/ResultModifier.d.ts +29 -0
- package/src/types/duckdb-serialization-types/serialization/ResultModifier.js +16 -0
- package/src/types/duckdb-serialization-types/serialization/ResultModifier.js.map +1 -0
- package/src/types/duckdb-serialization-types/serialization/Statement.d.js +3 -0
- package/src/types/duckdb-serialization-types/serialization/Statement.d.js.map +1 -0
- package/src/types/duckdb-serialization-types/serialization/Statement.d.ts +4 -0
- package/src/types/duckdb-serialization-types/serialization/Statement.js +3 -0
- package/src/types/duckdb-serialization-types/serialization/Statement.js.map +1 -0
- package/src/types/duckdb-serialization-types/serialization/TableFilter.d.js +3 -0
- package/src/types/duckdb-serialization-types/serialization/TableFilter.d.js.map +1 -0
- package/src/types/duckdb-serialization-types/serialization/TableFilter.d.ts +32 -0
- package/src/types/duckdb-serialization-types/serialization/TableFilter.js +17 -0
- package/src/types/duckdb-serialization-types/serialization/TableFilter.js.map +1 -0
- package/src/types/duckdb-serialization-types/serialization/TableRef.d.js +3 -0
- package/src/types/duckdb-serialization-types/serialization/TableRef.d.js.map +1 -0
- package/src/types/duckdb-serialization-types/serialization/TableRef.d.ts +84 -0
- package/src/types/duckdb-serialization-types/serialization/TableRef.js +53 -0
- package/src/types/duckdb-serialization-types/serialization/TableRef.js.map +1 -0
- package/src/types/duckdb-serialization-types/serialization/Types.d.js +3 -0
- package/src/types/duckdb-serialization-types/serialization/Types.d.js.map +1 -0
- package/src/types/duckdb-serialization-types/serialization/Types.d.ts +53 -0
- package/src/types/duckdb-serialization-types/serialization/Types.js +21 -0
- package/src/types/duckdb-serialization-types/serialization/Types.js.map +1 -0
- package/src/types/duckdb-serialization-types/serialization/example.d.ts +1 -0
- package/src/types/duckdb-serialization-types/serialization/example.js +131 -0
- package/src/types/duckdb-serialization-types/serialization/example.js.map +1 -0
- package/src/utils/__fixtures__/joins.fixtures.d.ts +211 -0
- package/src/utils/__fixtures__/joins.fixtures.js +922 -0
- package/src/utils/__fixtures__/joins.fixtures.js.map +1 -0
- package/src/utils/base-ast.d.ts +3 -0
- package/src/utils/base-ast.js +64 -0
- package/src/utils/base-ast.js.map +1 -0
- package/src/utils/constants.d.ts +2 -0
- package/src/utils/constants.js +19 -0
- package/src/utils/constants.js.map +1 -0
- package/src/utils/cube-filter-enrichment.d.ts +4 -0
- package/src/utils/cube-filter-enrichment.js +63 -0
- package/src/utils/cube-filter-enrichment.js.map +1 -0
- package/src/utils/cube-to-table-schema.d.ts +3 -0
- package/src/utils/cube-to-table-schema.js +104 -0
- package/src/utils/cube-to-table-schema.js.map +1 -0
- package/src/utils/cube-type-to-duckdb-type.d.ts +6 -0
- package/src/utils/cube-type-to-duckdb-type.js +17 -0
- package/src/utils/cube-type-to-duckdb-type.js.map +1 -0
- package/src/utils/find-in-table-schema.d.ts +4 -0
- package/src/utils/find-in-table-schema.js +40 -0
- package/src/utils/find-in-table-schema.js.map +1 -0
- package/src/utils/get-possible-nodes.d.ts +15 -0
- package/src/utils/get-possible-nodes.js +152 -0
- package/src/utils/get-possible-nodes.js.map +1 -0
- package/src/utils/get-type-info.d.ts +7 -0
- package/src/utils/get-type-info.js +44 -0
- package/src/utils/get-type-info.js.map +1 -0
- package/src/utils/is-array-member-type.d.ts +4 -0
- package/src/utils/is-array-member-type.js +12 -0
- package/src/utils/is-array-member-type.js.map +1 -0
- package/src/utils/key-from-measures-dimension.d.ts +2 -0
- package/src/utils/key-from-measures-dimension.js +34 -0
- package/src/utils/key-from-measures-dimension.js.map +1 -0
- package/src/utils/meerkat-placeholder-replacer.d.ts +1 -0
- package/src/utils/meerkat-placeholder-replacer.js +14 -0
- package/src/utils/meerkat-placeholder-replacer.js.map +1 -0
- package/src/utils/member-key-to-safe-key.d.ts +1 -0
- package/src/utils/member-key-to-safe-key.js +13 -0
- package/src/utils/member-key-to-safe-key.js.map +1 -0
- package/src/utils/modify-meerkat-filter.d.ts +3 -0
- package/src/utils/modify-meerkat-filter.js +30 -0
- package/src/utils/modify-meerkat-filter.js.map +1 -0
- package/src/utils/type-guards.d.ts +8 -0
- package/src/utils/type-guards.js +83 -0
- package/src/utils/type-guards.js.map +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../meerkat-core/src/get-projection-clause/get-projection-clause.ts"],"sourcesContent":["import { getAllColumnUsedInMeasures } from '../cube-measure-transformer/cube-measure-transformer';\nimport { TableSchema } from '../types/cube-types';\nimport {\n findInDimensionSchema,\n findInMeasureSchema,\n} from '../utils/find-in-table-schema';\nimport { memberKeyToSafeKey } from '../utils/member-key-to-safe-key';\n\nexport const getFilterMeasureProjection = ({\n key,\n tableSchema,\n measures,\n}: {\n key: string;\n tableSchema: TableSchema;\n measures: string[];\n}) => {\n const tableName = key.split('.')[0];\n const measureWithoutTable = key.split('.')[1];\n const foundMember = findInMeasureSchema(measureWithoutTable, tableSchema);\n const isMeasure = measures.includes(key);\n if (!foundMember || isMeasure || tableName !== tableSchema.name) {\n // If the selected member is not found in the table schema or if it is already selected, continue.\n // If the selected member is a measure, don't create an alias. Since measure computation is done in the outermost level of the query\n // If the selected member is not from the current table, don't create an alias.\n return {\n sql: undefined,\n foundMember: undefined,\n aliasKey: undefined,\n };\n }\n const aliasKey = memberKeyToSafeKey(key);\n return { sql: `${key} AS ${aliasKey}`, foundMember, aliasKey };\n};\n\nexport const getDimensionProjection = ({\n key,\n tableSchema,\n}: {\n key: string;\n tableSchema: TableSchema;\n}) => {\n // Find the table access key\n const measureWithoutTable = key.split('.')[1];\n const tableName = key.split('.')[0];\n\n const foundMember = findInDimensionSchema(measureWithoutTable, tableSchema);\n if (!foundMember || tableName !== tableSchema.name) {\n // If the selected member is not found in the table schema or if it is already selected, continue.\n // If the selected member is not from the current table, don't create an alias.\n return {\n sql: undefined,\n foundMember: undefined,\n aliasKey: undefined,\n };\n }\n const aliasKey = memberKeyToSafeKey(key);\n // Add the alias key to the set. So we have a reference to all the previously selected members.\n return { sql: `${foundMember.sql} AS ${aliasKey}`, foundMember, aliasKey };\n};\n\nconst aggregator = ({\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 measures: string[],\n dimensions: string[],\n tableSchema: TableSchema,\n aliasedColumnSet: Set<string>\n) => {\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 });\n return aggregator({\n 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 aggregator({\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":["getFilterMeasureProjection","getDimensionProjection","getProjectionClause","key","tableSchema","measures","tableName","split","measureWithoutTable","foundMember","findInMeasureSchema","isMeasure","includes","name","sql","undefined","aliasKey","memberKeyToSafeKey","findInDimensionSchema","aggregator","member","aliasedColumnSet","acc","has","add","push","dimensions","filteredDimensions","filter","dimension","filteredMeasures","measure","dimensionsProjectionsArr","reduce","currentIndex","members","memberSql","dimensionsProjections","join","measureProjectionsArr","measureProjections","usedMeasureObjects","findIndex","keyWithoutTable","columnsUsedInMeasures","getAllColumnUsedInMeasures","columnsUsedInMeasuresInProjection","forEach","column","index","safeKey","length","combinedStr","str"],"mappings":";;;;;;;;IAQaA,0BAA0B;eAA1BA;;IA2BAC,sBAAsB;eAAtBA;;IA+CAC,mBAAmB;eAAnBA;;;wCAlF8B;mCAKpC;oCAC4B;AAE5B,MAAMF,6BAA6B,CAAC,EACzCG,GAAG,EACHC,WAAW,EACXC,QAAQ,EAKT;IACC,MAAMC,YAAYH,IAAII,KAAK,CAAC,IAAI,CAAC,EAAE;IACnC,MAAMC,sBAAsBL,IAAII,KAAK,CAAC,IAAI,CAAC,EAAE;IAC7C,MAAME,cAAcC,IAAAA,sCAAmB,EAACF,qBAAqBJ;IAC7D,MAAMO,YAAYN,SAASO,QAAQ,CAACT;IACpC,IAAI,CAACM,eAAeE,aAAaL,cAAcF,YAAYS,IAAI,EAAE;QAC/D,kGAAkG;QAClG,oIAAoI;QACpI,+EAA+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AOM,YAAYxB,MAAM,CAAC,CAACyB,MAAQA,IAAIF,MAAM,GAAG,GAAGb,IAAI,CAAC;AAC1D"}
|
package/src/get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Query, TableSchema } from '../types/cube-types';
|
|
2
|
+
interface GetWrappedBaseQueryWithProjectionsParams {
|
|
3
|
+
baseQuery: string;
|
|
4
|
+
tableSchema: TableSchema;
|
|
5
|
+
query: Query;
|
|
6
|
+
}
|
|
7
|
+
export declare const getWrappedBaseQueryWithProjections: ({ baseQuery, tableSchema, query, }: GetWrappedBaseQueryWithProjectionsParams) => string;
|
|
8
|
+
export {};
|
package/src/get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "getWrappedBaseQueryWithProjections", {
|
|
3
|
+
enumerable: true,
|
|
4
|
+
get: function() {
|
|
5
|
+
return getWrappedBaseQueryWithProjections;
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
const _cubemeasuretransformer = require("../cube-measure-transformer/cube-measure-transformer");
|
|
9
|
+
const _getprojectionclause = require("../get-projection-clause/get-projection-clause");
|
|
10
|
+
const _findintableschema = require("../utils/find-in-table-schema");
|
|
11
|
+
const getFilterProjections = ({ member, tableSchema, measures })=>{
|
|
12
|
+
const memberWithoutTable = member.split('.')[1];
|
|
13
|
+
const isDimension = (0, _findintableschema.findInDimensionSchema)(memberWithoutTable, tableSchema);
|
|
14
|
+
if (isDimension) {
|
|
15
|
+
return (0, _getprojectionclause.getDimensionProjection)({
|
|
16
|
+
key: member,
|
|
17
|
+
tableSchema
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
const isMeasure = (0, _findintableschema.findInMeasureSchema)(memberWithoutTable, tableSchema);
|
|
21
|
+
if (isMeasure) {
|
|
22
|
+
return (0, _getprojectionclause.getFilterMeasureProjection)({
|
|
23
|
+
key: member,
|
|
24
|
+
tableSchema,
|
|
25
|
+
measures
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
sql: undefined,
|
|
30
|
+
foundMember: undefined,
|
|
31
|
+
aliasKey: undefined
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
const getAliasedColumnsFromFilters = ({ baseSql, meerkatFilters, tableSchema, aliasedColumnSet, measures })=>{
|
|
35
|
+
let sql = baseSql;
|
|
36
|
+
meerkatFilters == null ? void 0 : meerkatFilters.forEach((filter)=>{
|
|
37
|
+
if ('and' in filter) {
|
|
38
|
+
// Traverse through the passed 'and' filters
|
|
39
|
+
sql += getAliasedColumnsFromFilters({
|
|
40
|
+
baseSql: '',
|
|
41
|
+
meerkatFilters: filter.and,
|
|
42
|
+
tableSchema,
|
|
43
|
+
aliasedColumnSet,
|
|
44
|
+
measures
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
if ('or' in filter) {
|
|
48
|
+
// Traverse through the passed 'or' filters
|
|
49
|
+
sql += getAliasedColumnsFromFilters({
|
|
50
|
+
baseSql: '',
|
|
51
|
+
tableSchema,
|
|
52
|
+
meerkatFilters: filter.or,
|
|
53
|
+
aliasedColumnSet,
|
|
54
|
+
measures
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
if ('member' in filter) {
|
|
58
|
+
const { aliasKey, foundMember, sql: memberSql } = getFilterProjections({
|
|
59
|
+
member: filter.member,
|
|
60
|
+
tableSchema,
|
|
61
|
+
measures
|
|
62
|
+
});
|
|
63
|
+
if (!foundMember || aliasedColumnSet.has(aliasKey)) {
|
|
64
|
+
// If the selected member is not found in the table schema or if it is already selected, continue.
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (aliasKey) {
|
|
68
|
+
aliasedColumnSet.add(aliasKey);
|
|
69
|
+
}
|
|
70
|
+
// Add the alias key to the set. So we have a reference to all the previously selected members.
|
|
71
|
+
sql += `, ${memberSql}`;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return sql;
|
|
75
|
+
};
|
|
76
|
+
const getWrappedBaseQueryWithProjections = ({ baseQuery, tableSchema, query })=>{
|
|
77
|
+
/*
|
|
78
|
+
* Im order to be able to filter on computed metric from a query, we need to project the computed metric in the base query.
|
|
79
|
+
* If theres filters supplied, we can safely return the original base query. Since nothing need to be projected and filtered in this case
|
|
80
|
+
*/ // 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
|
|
81
|
+
const newBaseSql = `SELECT * FROM (${baseQuery}) AS ${tableSchema.name}`;
|
|
82
|
+
const aliasedColumnSet = new Set();
|
|
83
|
+
const aliasFromFilters = getAliasedColumnsFromFilters({
|
|
84
|
+
aliasedColumnSet,
|
|
85
|
+
baseSql: 'SELECT *',
|
|
86
|
+
// setting measures to empty array, since we don't want to project measures present in the filters in the base query
|
|
87
|
+
tableSchema: tableSchema,
|
|
88
|
+
meerkatFilters: query.filters,
|
|
89
|
+
measures: query.measures
|
|
90
|
+
});
|
|
91
|
+
var _query_dimensions;
|
|
92
|
+
const memberProjections = (0, _getprojectionclause.getProjectionClause)(query.measures, (_query_dimensions = query.dimensions) != null ? _query_dimensions : [], tableSchema, aliasedColumnSet);
|
|
93
|
+
const formattedMemberProjection = memberProjections ? `, ${memberProjections}` : '';
|
|
94
|
+
const finalAliasedColumnsClause = aliasFromFilters + formattedMemberProjection;
|
|
95
|
+
const sqlWithFilterProjects = (0, _cubemeasuretransformer.getSelectReplacedSql)(newBaseSql, finalAliasedColumnsClause);
|
|
96
|
+
return sqlWithFilterProjects;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
//# sourceMappingURL=get-wrapped-base-query-with-projections.js.map
|
package/src/get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections.js.map
ADDED
|
@@ -0,0 +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 {\n getDimensionProjection,\n getFilterMeasureProjection as getFilterMeasureProjections,\n getProjectionClause,\n} from '../get-projection-clause/get-projection-clause';\nimport { MeerkatQueryFilter, Query, TableSchema } from '../types/cube-types';\nimport {\n findInDimensionSchema,\n findInMeasureSchema,\n} from '../utils/find-in-table-schema';\n\ninterface GetWrappedBaseQueryWithProjectionsParams {\n baseQuery: string;\n tableSchema: TableSchema;\n query: Query;\n}\n\nconst getFilterProjections = ({\n member,\n tableSchema,\n measures,\n}: {\n member: string;\n tableSchema: TableSchema;\n measures: string[];\n}) => {\n const memberWithoutTable = member.split('.')[1];\n const isDimension = findInDimensionSchema(memberWithoutTable, tableSchema);\n if (isDimension) {\n return getDimensionProjection({ key: member, tableSchema });\n }\n const isMeasure = findInMeasureSchema(memberWithoutTable, tableSchema);\n if (isMeasure) {\n return getFilterMeasureProjections({ key: member, tableSchema, measures });\n }\n return {\n sql: undefined,\n foundMember: undefined,\n aliasKey: undefined,\n };\n};\n\nconst getAliasedColumnsFromFilters = ({\n baseSql,\n meerkatFilters,\n tableSchema,\n aliasedColumnSet,\n measures,\n}: {\n meerkatFilters?: MeerkatQueryFilter[];\n tableSchema: TableSchema;\n baseSql: string;\n aliasedColumnSet: Set<string>;\n measures: string[];\n}) => {\n let sql = baseSql;\n meerkatFilters?.forEach((filter) => {\n if ('and' in filter) {\n // Traverse through the passed 'and' filters\n sql += getAliasedColumnsFromFilters({\n baseSql: '',\n meerkatFilters: filter.and,\n tableSchema,\n aliasedColumnSet,\n measures,\n });\n }\n if ('or' in filter) {\n // Traverse through the passed 'or' filters\n sql += getAliasedColumnsFromFilters({\n baseSql: '',\n tableSchema,\n meerkatFilters: filter.or,\n aliasedColumnSet,\n measures,\n });\n }\n if ('member' in filter) {\n const {\n aliasKey,\n foundMember,\n sql: memberSql,\n } = getFilterProjections({\n member: filter.member,\n tableSchema,\n measures,\n });\n if (!foundMember || aliasedColumnSet.has(aliasKey)) {\n // If the selected member is not found in the table schema or if it is already selected, continue.\n return;\n }\n if (aliasKey) {\n aliasedColumnSet.add(aliasKey);\n }\n // Add the alias key to the set. So we have a reference to all the previously selected members.\n sql += `, ${memberSql}`;\n }\n });\n return sql;\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 meerkatFilters: query.filters,\n measures: query.measures,\n });\n\n const memberProjections = getProjectionClause(\n query.measures,\n query.dimensions ?? [],\n tableSchema,\n aliasedColumnSet\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","getFilterProjections","member","tableSchema","measures","memberWithoutTable","split","isDimension","findInDimensionSchema","getDimensionProjection","key","isMeasure","findInMeasureSchema","getFilterMeasureProjections","sql","undefined","foundMember","aliasKey","getAliasedColumnsFromFilters","baseSql","meerkatFilters","aliasedColumnSet","forEach","filter","and","or","memberSql","has","add","baseQuery","query","newBaseSql","name","Set","aliasFromFilters","filters","memberProjections","getProjectionClause","dimensions","formattedMemberProjection","finalAliasedColumnsClause","sqlWithFilterProjects","getSelectReplacedSql"],"mappings":";+BAsGaA;;;eAAAA;;;wCAtGwB;qCAK9B;mCAKA;AAQP,MAAMC,uBAAuB,CAAC,EAC5BC,MAAM,EACNC,WAAW,EACXC,QAAQ,EAKT;IACC,MAAMC,qBAAqBH,OAAOI,KAAK,CAAC,IAAI,CAAC,EAAE;IAC/C,MAAMC,cAAcC,IAAAA,wCAAqB,EAACH,oBAAoBF;IAC9D,IAAII,aAAa;QACf,OAAOE,IAAAA,2CAAsB,EAAC;YAAEC,KAAKR;YAAQC;QAAY;IAC3D;IACA,MAAMQ,YAAYC,IAAAA,sCAAmB,EAACP,oBAAoBF;IAC1D,IAAIQ,WAAW;QACb,OAAOE,IAAAA,+CAA2B,EAAC;YAAEH,KAAKR;YAAQC;YAAaC;QAAS;IAC1E;IACA,OAAO;QACLU,KAAKC;QACLC,aAAaD;QACbE,UAAUF;IACZ;AACF;AAEA,MAAMG,+BAA+B,CAAC,EACpCC,OAAO,EACPC,cAAc,EACdjB,WAAW,EACXkB,gBAAgB,EAChBjB,QAAQ,EAOT;IACC,IAAIU,MAAMK;IACVC,kCAAAA,eAAgBE,OAAO,CAAC,CAACC;QACvB,IAAI,SAASA,QAAQ;YACnB,4CAA4C;YAC5CT,OAAOI,6BAA6B;gBAClCC,SAAS;gBACTC,gBAAgBG,OAAOC,GAAG;gBAC1BrB;gBACAkB;gBACAjB;YACF;QACF;QACA,IAAI,QAAQmB,QAAQ;YAClB,2CAA2C;YAC3CT,OAAOI,6BAA6B;gBAClCC,SAAS;gBACThB;gBACAiB,gBAAgBG,OAAOE,EAAE;gBACzBJ;gBACAjB;YACF;QACF;QACA,IAAI,YAAYmB,QAAQ;YACtB,MAAM,EACJN,QAAQ,EACRD,WAAW,EACXF,KAAKY,SAAS,EACf,GAAGzB,qBAAqB;gBACvBC,QAAQqB,OAAOrB,MAAM;gBACrBC;gBACAC;YACF;YACA,IAAI,CAACY,eAAeK,iBAAiBM,GAAG,CAACV,WAAW;gBAClD,kGAAkG;gBAClG;YACF;YACA,IAAIA,UAAU;gBACZI,iBAAiBO,GAAG,CAACX;YACvB;YACA,+FAA+F;YAC/FH,OAAO,CAAC,EAAE,EAAEY,UAAU,CAAC;QACzB;IACF;IACA,OAAOZ;AACT;AAEO,MAAMd,qCAAqC,CAAC,EACjD6B,SAAS,EACT1B,WAAW,EACX2B,KAAK,EACoC;IACzC;;;GAGC,GACD,kLAAkL;IAClL,MAAMC,aAAa,CAAC,eAAe,EAAEF,UAAU,KAAK,EAAE1B,YAAY6B,IAAI,CAAC,CAAC;IACxE,MAAMX,mBAAmB,IAAIY;IAE7B,MAAMC,mBAAmBhB,6BAA6B;QACpDG;QACAF,SAAS;QACT,oHAAoH;QACpHhB,aAAaA;QACbiB,gBAAgBU,MAAMK,OAAO;QAC7B/B,UAAU0B,MAAM1B,QAAQ;IAC1B;QAIE0B;IAFF,MAAMM,oBAAoBC,IAAAA,wCAAmB,EAC3CP,MAAM1B,QAAQ,EACd0B,CAAAA,oBAAAA,MAAMQ,UAAU,YAAhBR,oBAAoB,EAAE,EACtB3B,aACAkB;IAEF,MAAMkB,4BAA4BH,oBAC9B,CAAC,EAAE,EAAEA,kBAAkB,CAAC,GACxB;IAEJ,MAAMI,4BACJN,mBAAmBK;IAErB,MAAME,wBAAwBC,IAAAA,4CAAoB,EAChDX,YACAS;IAEF,OAAOC;AACT"}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from './ast-builder/ast-builder';
|
|
2
|
+
export * from './ast-deserializer/ast-deserializer';
|
|
3
|
+
export { detectApplyContextParamsToBaseSQL } from './context-params/context-params-ast';
|
|
4
|
+
export * from './cube-measure-transformer/cube-measure-transformer';
|
|
5
|
+
export * from './cube-to-duckdb/cube-filter-to-duckdb';
|
|
6
|
+
export { applyFilterParamsToBaseSQL, detectAllFilterParamsFromSQL, getFilterParamsAST, } from './filter-params/filter-params-ast';
|
|
7
|
+
export { getWrappedBaseQueryWithProjections } from './get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections';
|
|
8
|
+
export * from './joins/joins';
|
|
9
|
+
export { FilterType } from './types/cube-types';
|
|
10
|
+
export * from './types/cube-types/index';
|
|
11
|
+
export * from './types/duckdb-serialization-types/index';
|
|
12
|
+
export { BASE_TABLE_NAME } from './utils/base-ast';
|
|
13
|
+
export * from './utils/cube-to-table-schema';
|
|
14
|
+
export * from './utils/get-possible-nodes';
|
|
15
|
+
export { meerkatPlaceholderReplacer } from './utils/meerkat-placeholder-replacer';
|
|
16
|
+
export { memberKeyToSafeKey } from './utils/member-key-to-safe-key';
|
package/src/index.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
function _export(target, all) {
|
|
3
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
4
|
+
enumerable: true,
|
|
5
|
+
get: all[name]
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
_export(exports, {
|
|
9
|
+
detectApplyContextParamsToBaseSQL: function() {
|
|
10
|
+
return _contextparamsast.detectApplyContextParamsToBaseSQL;
|
|
11
|
+
},
|
|
12
|
+
applyFilterParamsToBaseSQL: function() {
|
|
13
|
+
return _filterparamsast.applyFilterParamsToBaseSQL;
|
|
14
|
+
},
|
|
15
|
+
detectAllFilterParamsFromSQL: function() {
|
|
16
|
+
return _filterparamsast.detectAllFilterParamsFromSQL;
|
|
17
|
+
},
|
|
18
|
+
getFilterParamsAST: function() {
|
|
19
|
+
return _filterparamsast.getFilterParamsAST;
|
|
20
|
+
},
|
|
21
|
+
getWrappedBaseQueryWithProjections: function() {
|
|
22
|
+
return _getwrappedbasequerywithprojections.getWrappedBaseQueryWithProjections;
|
|
23
|
+
},
|
|
24
|
+
FilterType: function() {
|
|
25
|
+
return _cubetypes.FilterType;
|
|
26
|
+
},
|
|
27
|
+
BASE_TABLE_NAME: function() {
|
|
28
|
+
return _baseast.BASE_TABLE_NAME;
|
|
29
|
+
},
|
|
30
|
+
meerkatPlaceholderReplacer: function() {
|
|
31
|
+
return _meerkatplaceholderreplacer.meerkatPlaceholderReplacer;
|
|
32
|
+
},
|
|
33
|
+
memberKeyToSafeKey: function() {
|
|
34
|
+
return _memberkeytosafekey.memberKeyToSafeKey;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
const _export_star = require("@swc/helpers/_/_export_star");
|
|
38
|
+
_export_star._(require("./ast-builder/ast-builder"), exports);
|
|
39
|
+
_export_star._(require("./ast-deserializer/ast-deserializer"), exports);
|
|
40
|
+
const _contextparamsast = require("./context-params/context-params-ast");
|
|
41
|
+
_export_star._(require("./cube-measure-transformer/cube-measure-transformer"), exports);
|
|
42
|
+
_export_star._(require("./cube-to-duckdb/cube-filter-to-duckdb"), exports);
|
|
43
|
+
const _filterparamsast = require("./filter-params/filter-params-ast");
|
|
44
|
+
const _getwrappedbasequerywithprojections = require("./get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections");
|
|
45
|
+
_export_star._(require("./joins/joins"), exports);
|
|
46
|
+
const _cubetypes = require("./types/cube-types");
|
|
47
|
+
_export_star._(require("./types/cube-types/index"), exports);
|
|
48
|
+
_export_star._(require("./types/duckdb-serialization-types/index"), exports);
|
|
49
|
+
const _baseast = require("./utils/base-ast");
|
|
50
|
+
_export_star._(require("./utils/cube-to-table-schema"), exports);
|
|
51
|
+
_export_star._(require("./utils/get-possible-nodes"), exports);
|
|
52
|
+
const _meerkatplaceholderreplacer = require("./utils/meerkat-placeholder-replacer");
|
|
53
|
+
const _memberkeytosafekey = require("./utils/member-key-to-safe-key");
|
|
54
|
+
|
|
55
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../meerkat-core/src/index.ts"],"sourcesContent":["export * from './ast-builder/ast-builder';\nexport * from './ast-deserializer/ast-deserializer';\nexport { detectApplyContextParamsToBaseSQL } from './context-params/context-params-ast';\nexport * from './cube-measure-transformer/cube-measure-transformer';\nexport * from './cube-to-duckdb/cube-filter-to-duckdb';\nexport {\n applyFilterParamsToBaseSQL,\n detectAllFilterParamsFromSQL,\n getFilterParamsAST,\n} from './filter-params/filter-params-ast';\nexport { getWrappedBaseQueryWithProjections } from './get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections';\nexport * from './joins/joins';\nexport { FilterType } from './types/cube-types';\nexport * from './types/cube-types/index';\nexport * from './types/duckdb-serialization-types/index';\nexport { BASE_TABLE_NAME } from './utils/base-ast';\nexport * from './utils/cube-to-table-schema';\nexport * from './utils/get-possible-nodes';\nexport { meerkatPlaceholderReplacer } from './utils/meerkat-placeholder-replacer';\nexport { memberKeyToSafeKey } from './utils/member-key-to-safe-key';\n"],"names":["detectApplyContextParamsToBaseSQL","applyFilterParamsToBaseSQL","detectAllFilterParamsFromSQL","getFilterParamsAST","getWrappedBaseQueryWithProjections","FilterType","BASE_TABLE_NAME","meerkatPlaceholderReplacer","memberKeyToSafeKey"],"mappings":";;;;;;;;IAESA,iCAAiC;eAAjCA,mDAAiC;;IAIxCC,0BAA0B;eAA1BA,2CAA0B;;IAC1BC,4BAA4B;eAA5BA,6CAA4B;;IAC5BC,kBAAkB;eAAlBA,mCAAkB;;IAEXC,kCAAkC;eAAlCA,sEAAkC;;IAElCC,UAAU;eAAVA,qBAAU;;IAGVC,eAAe;eAAfA,wBAAe;;IAGfC,0BAA0B;eAA1BA,sDAA0B;;IAC1BC,kBAAkB;eAAlBA,sCAAkB;;;;uBAnBb;uBACA;kCACoC;uBACpC;uBACA;iCAKP;oDAC4C;uBACrC;2BACa;uBACb;uBACA;yBACkB;uBAClB;uBACA;4CAC6B;oCACR"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { JoinPath, Query, TableSchema } from '../types/cube-types';
|
|
2
|
+
export type Graph = {
|
|
3
|
+
[key: string]: {
|
|
4
|
+
[key: string]: {
|
|
5
|
+
[key: string]: string;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export declare function generateSqlQuery(path: JoinPath[], tableSchemaSqlMap: {
|
|
10
|
+
[key: string]: string;
|
|
11
|
+
}, directedGraph: Graph): string;
|
|
12
|
+
export declare const createDirectedGraph: (tableSchema: TableSchema[], tableSchemaSqlMap: {
|
|
13
|
+
[key: string]: string;
|
|
14
|
+
}) => {
|
|
15
|
+
[key: string]: {
|
|
16
|
+
[key: string]: {
|
|
17
|
+
[key: string]: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export declare const checkLoopInJoinPath: (joinPath: JoinPath[]) => boolean;
|
|
22
|
+
export declare const getCombinedTableSchema: (tableSchema: TableSchema[], cubeQuery: Query) => Promise<TableSchema>;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
function _export(target, all) {
|
|
3
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
4
|
+
enumerable: true,
|
|
5
|
+
get: all[name]
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
_export(exports, {
|
|
9
|
+
generateSqlQuery: function() {
|
|
10
|
+
return generateSqlQuery;
|
|
11
|
+
},
|
|
12
|
+
createDirectedGraph: function() {
|
|
13
|
+
return createDirectedGraph;
|
|
14
|
+
},
|
|
15
|
+
checkLoopInJoinPath: function() {
|
|
16
|
+
return checkLoopInJoinPath;
|
|
17
|
+
},
|
|
18
|
+
getCombinedTableSchema: function() {
|
|
19
|
+
return getCombinedTableSchema;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const _extends = require("@swc/helpers/_/_extends");
|
|
23
|
+
const _cubetypes = require("../types/cube-types");
|
|
24
|
+
function generateSqlQuery(path, tableSchemaSqlMap, directedGraph) {
|
|
25
|
+
if (path.length === 0) {
|
|
26
|
+
throw new Error('Invalid path, multiple data sources are present without a join path.');
|
|
27
|
+
}
|
|
28
|
+
const startingNode = path[0][0].left;
|
|
29
|
+
let query = `${tableSchemaSqlMap[startingNode]}`;
|
|
30
|
+
/**
|
|
31
|
+
* If the starting node is not a join node, then return the query as is.
|
|
32
|
+
* It means that the query is a single node query.
|
|
33
|
+
*/ if (!(0, _cubetypes.isJoinNode)(path[0][0])) {
|
|
34
|
+
return query;
|
|
35
|
+
}
|
|
36
|
+
const visitedNodes = new Map();
|
|
37
|
+
for(let i = 0; i < path.length; i++){
|
|
38
|
+
if (path[i][0].left !== startingNode) {
|
|
39
|
+
throw new Error('Invalid path, starting node is not the same for all paths.');
|
|
40
|
+
}
|
|
41
|
+
for(let j = 0; j < path[i].length; j++){
|
|
42
|
+
const currentEdge = path[i][j];
|
|
43
|
+
if (!(0, _cubetypes.isJoinNode)(currentEdge)) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const visitedFrom = visitedNodes.get(currentEdge.right);
|
|
47
|
+
// If node is already visited from the same edge, continue to next iteration
|
|
48
|
+
if (visitedFrom && visitedFrom.left === currentEdge.left) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
// If node is already visited from a different edge, throw ambiguity error
|
|
52
|
+
if (visitedFrom) {
|
|
53
|
+
throw new Error(`Path ambiguity, node ${currentEdge.right} visited from different sources`);
|
|
54
|
+
}
|
|
55
|
+
// If visitedFrom is undefined, this is the first visit to the node
|
|
56
|
+
visitedNodes.set(currentEdge.right, currentEdge);
|
|
57
|
+
query += ` LEFT JOIN (${tableSchemaSqlMap[currentEdge.right]}) AS ${currentEdge.right} ON ${directedGraph[currentEdge.left][currentEdge.right][currentEdge.on]}`;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return query;
|
|
61
|
+
}
|
|
62
|
+
const createDirectedGraph = (tableSchema, tableSchemaSqlMap)=>{
|
|
63
|
+
const directedGraph = {};
|
|
64
|
+
function addEdge(table1, table2, joinOn, joinCondition) {
|
|
65
|
+
if (table1 === table2 || directedGraph[table1] && directedGraph[table1][table2] && directedGraph[table1][table2][joinOn]) {
|
|
66
|
+
throw new Error('An invalid path was detected.');
|
|
67
|
+
}
|
|
68
|
+
if (!directedGraph[table1]) directedGraph[table1] = {};
|
|
69
|
+
if (!directedGraph[table1][table2]) directedGraph[table1][table2] = {};
|
|
70
|
+
directedGraph[table1][table2][joinOn] = joinCondition;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Iterate through the table schema and add the edges to the directed graph.
|
|
74
|
+
* The edges are added based on the join conditions provided in the table schema.
|
|
75
|
+
* The SQL is split by the '=' sign and the tables columns involved in the joins are extracted.
|
|
76
|
+
* The tables are then added as edges to the directed graph.
|
|
77
|
+
*/ tableSchema.forEach((schema)=>{
|
|
78
|
+
var _schema_joins;
|
|
79
|
+
schema == null ? void 0 : (_schema_joins = schema.joins) == null ? void 0 : _schema_joins.forEach((join)=>{
|
|
80
|
+
const tables = join.sql.split('=').map((str)=>str.split('.')[0].trim());
|
|
81
|
+
const conditions = join.sql.split('=').map((str)=>str.split('.')[1].trim());
|
|
82
|
+
/**
|
|
83
|
+
* If the join SQL does not contain exactly 2 tables, then the join is invalid.
|
|
84
|
+
*/ if (tables.length !== 2) {
|
|
85
|
+
throw new Error(`Invalid join SQL: ${join.sql}`);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* If the tables are the same, then the join is invalid.
|
|
89
|
+
*/ if (tables[0] === tables[1]) {
|
|
90
|
+
throw new Error(`Invalid join SQL: ${join.sql}`);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* If the tables are not found in the table schema, then the join is invalid.
|
|
94
|
+
*/ if (tables[0] !== schema.name && tables[1] !== schema.name) {
|
|
95
|
+
throw new Error(`Table "${schema.name}" not found in provided join SQL: ${join.sql}`);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Check if the tables are found in the table schema SQL map.
|
|
99
|
+
*/ if (!tableSchemaSqlMap[tables[0]] || !tableSchemaSqlMap[tables[1]]) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* If the table is the source table, then add the edge from the source to the target.
|
|
104
|
+
* Thus find which table is the source and which is the target and add the edge accordingly.
|
|
105
|
+
*/ if (tables[0] === schema.name) {
|
|
106
|
+
addEdge(tables[0], tables[1], conditions[0], join.sql);
|
|
107
|
+
} else {
|
|
108
|
+
addEdge(tables[1], tables[0], conditions[1], join.sql);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
return directedGraph;
|
|
113
|
+
};
|
|
114
|
+
const checkLoopInJoinPath = (joinPath)=>{
|
|
115
|
+
for(let i = 0; i < joinPath.length; i++){
|
|
116
|
+
const visitedNodes = new Set();
|
|
117
|
+
const currentJoinPath = joinPath[i];
|
|
118
|
+
visitedNodes.add(currentJoinPath[0].left);
|
|
119
|
+
for(let j = 0; j < currentJoinPath.length; j++){
|
|
120
|
+
const currentEdge = currentJoinPath[j];
|
|
121
|
+
if ((0, _cubetypes.isJoinNode)(currentEdge) && visitedNodes.has(currentEdge.right)) {
|
|
122
|
+
if (visitedNodes.has(currentEdge.right)) {
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
visitedNodes.add(currentEdge.right);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return false;
|
|
130
|
+
};
|
|
131
|
+
const getCombinedTableSchema = async (tableSchema, cubeQuery)=>{
|
|
132
|
+
if (tableSchema.length === 1) {
|
|
133
|
+
return tableSchema[0];
|
|
134
|
+
}
|
|
135
|
+
const tableSchemaSqlMap = tableSchema.reduce((acc, schema)=>{
|
|
136
|
+
return _extends._({}, acc, {
|
|
137
|
+
[schema.name]: schema.sql
|
|
138
|
+
});
|
|
139
|
+
}, {});
|
|
140
|
+
const directedGraph = createDirectedGraph(tableSchema, tableSchemaSqlMap);
|
|
141
|
+
const hasLoop = checkLoopInJoinPath(cubeQuery.joinPaths || []);
|
|
142
|
+
if (hasLoop) {
|
|
143
|
+
throw new Error(`A loop was detected in the joins. ${JSON.stringify(cubeQuery.joinPaths || [])}`);
|
|
144
|
+
}
|
|
145
|
+
const baseSql = generateSqlQuery(cubeQuery.joinPaths || [], tableSchemaSqlMap, directedGraph);
|
|
146
|
+
const combinedTableSchema = tableSchema.reduce((acc, schema)=>{
|
|
147
|
+
return {
|
|
148
|
+
name: 'MEERKAT_GENERATED_TABLE',
|
|
149
|
+
sql: baseSql,
|
|
150
|
+
measures: [
|
|
151
|
+
...acc.measures,
|
|
152
|
+
...schema.measures
|
|
153
|
+
],
|
|
154
|
+
dimensions: [
|
|
155
|
+
...acc.dimensions,
|
|
156
|
+
...schema.dimensions
|
|
157
|
+
],
|
|
158
|
+
joins: []
|
|
159
|
+
};
|
|
160
|
+
}, {
|
|
161
|
+
name: '',
|
|
162
|
+
sql: '',
|
|
163
|
+
measures: [],
|
|
164
|
+
dimensions: [],
|
|
165
|
+
joins: []
|
|
166
|
+
});
|
|
167
|
+
return combinedTableSchema;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
//# sourceMappingURL=joins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../meerkat-core/src/joins/joins.ts"],"sourcesContent":["import { JoinPath, Query, TableSchema, isJoinNode } from '../types/cube-types';\n\nexport type Graph = {\n [key: string]: { [key: string]: { [key: string]: string } };\n};\n\nexport function generateSqlQuery(\n path: JoinPath[],\n tableSchemaSqlMap: { [key: string]: string },\n directedGraph: Graph\n): string {\n if (path.length === 0) {\n throw new Error(\n 'Invalid path, multiple data sources are present without a join path.'\n );\n }\n\n const startingNode = path[0][0].left;\n let query = `${tableSchemaSqlMap[startingNode]}`;\n\n /**\n * If the starting node is not a join node, then return the query as is.\n * It means that the query is a single node query.\n */\n if (!isJoinNode(path[0][0])) {\n return query;\n }\n\n const visitedNodes = new Map();\n\n for (let i = 0; i < path.length; i++) {\n if (path[i][0].left !== startingNode) {\n throw new Error(\n 'Invalid path, starting node is not the same for all paths.'\n );\n }\n for (let j = 0; j < path[i].length; j++) {\n const currentEdge = path[i][j];\n\n if (!isJoinNode(currentEdge)) {\n continue;\n }\n\n const visitedFrom = visitedNodes.get(currentEdge.right);\n\n // If node is already visited from the same edge, continue to next iteration\n if (visitedFrom && visitedFrom.left === currentEdge.left) {\n continue;\n }\n // If node is already visited from a different edge, throw ambiguity error\n if (visitedFrom) {\n throw new Error(\n `Path ambiguity, node ${currentEdge.right} visited from different sources`\n );\n }\n\n // If visitedFrom is undefined, this is the first visit to the node\n visitedNodes.set(currentEdge.right, currentEdge);\n\n query += ` LEFT JOIN (${tableSchemaSqlMap[currentEdge.right]}) AS ${currentEdge.right\n } ON ${directedGraph[currentEdge.left][currentEdge.right][currentEdge.on]\n }`;\n }\n }\n\n return query;\n}\n\nexport const createDirectedGraph = (\n tableSchema: TableSchema[],\n tableSchemaSqlMap: { [key: string]: string }\n) => {\n const directedGraph: {\n [key: string]: { [key: string]: { [key: string]: string } };\n } = {};\n\n function addEdge(\n table1: string,\n table2: string,\n joinOn: string,\n joinCondition: string\n ) {\n if (\n table1 === table2 ||\n (directedGraph[table1] &&\n directedGraph[table1][table2] &&\n directedGraph[table1][table2][joinOn])\n ) {\n throw new Error('An invalid path was detected.');\n }\n if (!directedGraph[table1]) directedGraph[table1] = {};\n if (!directedGraph[table1][table2]) directedGraph[table1][table2] = {};\n directedGraph[table1][table2][joinOn] = joinCondition;\n }\n /**\n * Iterate through the table schema and add the edges to the directed graph.\n * The edges are added based on the join conditions provided in the table schema.\n * The SQL is split by the '=' sign and the tables columns involved in the joins are extracted.\n * The tables are then added as edges to the directed graph.\n */\n tableSchema.forEach((schema) => {\n schema?.joins?.forEach((join) => {\n const tables = join.sql.split('=').map((str) => str.split('.')[0].trim());\n const conditions = join.sql\n .split('=')\n .map((str) => str.split('.')[1].trim());\n\n /**\n * If the join SQL does not contain exactly 2 tables, then the join is invalid.\n */\n if (tables.length !== 2) {\n throw new Error(`Invalid join SQL: ${join.sql}`);\n }\n\n /**\n * If the tables are the same, then the join is invalid.\n */\n if (tables[0] === tables[1]) {\n throw new Error(`Invalid join SQL: ${join.sql}`);\n }\n\n /**\n * If the tables are not found in the table schema, then the join is invalid.\n */\n\n if (tables[0] !== schema.name && tables[1] !== schema.name) {\n throw new Error(\n `Table \"${schema.name}\" not found in provided join SQL: ${join.sql}`\n );\n }\n\n /**\n * Check if the tables are found in the table schema SQL map.\n */\n if (!tableSchemaSqlMap[tables[0]] || !tableSchemaSqlMap[tables[1]]) {\n return;\n }\n /**\n * If the table is the source table, then add the edge from the source to the target.\n * Thus find which table is the source and which is the target and add the edge accordingly.\n */\n if (tables[0] === schema.name) {\n addEdge(tables[0], tables[1], conditions[0], join.sql);\n } else {\n addEdge(tables[1], tables[0], conditions[1], join.sql);\n }\n });\n });\n\n return directedGraph;\n};\n\n\nexport const checkLoopInJoinPath = (joinPath: JoinPath[]) => {\n for (let i = 0; i < joinPath.length; i++) {\n const visitedNodes = new Set<string>();\n const currentJoinPath = joinPath[i];\n visitedNodes.add(currentJoinPath[0].left);\n for (let j = 0; j < currentJoinPath.length; j++) {\n const currentEdge = currentJoinPath[j];\n if (isJoinNode(currentEdge) && visitedNodes.has(currentEdge.right)) {\n if (visitedNodes.has(currentEdge.right)) {\n return true;\n }\n visitedNodes.add(currentEdge.right);\n }\n }\n }\n return false\n}\n\nexport const getCombinedTableSchema = async (\n tableSchema: TableSchema[],\n cubeQuery: Query\n) => {\n if (tableSchema.length === 1) {\n return tableSchema[0];\n }\n\n const tableSchemaSqlMap = tableSchema.reduce(\n (acc: { [key: string]: string }, schema: TableSchema) => {\n return { ...acc, [schema.name]: schema.sql };\n },\n {}\n );\n\n const directedGraph = createDirectedGraph(tableSchema, tableSchemaSqlMap);\n const hasLoop = checkLoopInJoinPath(cubeQuery.joinPaths || []);\n if (hasLoop) {\n throw new Error(`A loop was detected in the joins. ${JSON.stringify(cubeQuery.joinPaths || [])}`);\n }\n\n const baseSql = generateSqlQuery(\n cubeQuery.joinPaths || [],\n tableSchemaSqlMap,\n directedGraph\n );\n\n const combinedTableSchema = tableSchema.reduce(\n (acc: TableSchema, schema: TableSchema) => {\n return {\n name: 'MEERKAT_GENERATED_TABLE',\n sql: baseSql,\n measures: [...acc.measures, ...schema.measures],\n dimensions: [...acc.dimensions, ...schema.dimensions],\n joins: [],\n };\n },\n {\n name: '',\n sql: '',\n measures: [],\n dimensions: [],\n joins: [],\n }\n );\n return combinedTableSchema;\n};\n"],"names":["generateSqlQuery","createDirectedGraph","checkLoopInJoinPath","getCombinedTableSchema","path","tableSchemaSqlMap","directedGraph","length","Error","startingNode","left","query","isJoinNode","visitedNodes","Map","i","j","currentEdge","visitedFrom","get","right","set","on","tableSchema","addEdge","table1","table2","joinOn","joinCondition","forEach","schema","joins","join","tables","sql","split","map","str","trim","conditions","name","joinPath","Set","currentJoinPath","add","has","cubeQuery","reduce","acc","hasLoop","joinPaths","JSON","stringify","baseSql","combinedTableSchema","measures","dimensions"],"mappings":";;;;;;;;IAMgBA,gBAAgB;eAAhBA;;IA8DHC,mBAAmB;eAAnBA;;IAqFAC,mBAAmB;eAAnBA;;IAkBAC,sBAAsB;eAAtBA;;;;2BA3K4C;AAMlD,SAASH,iBACdI,IAAgB,EAChBC,iBAA4C,EAC5CC,aAAoB;IAEpB,IAAIF,KAAKG,MAAM,KAAK,GAAG;QACrB,MAAM,IAAIC,MACR;IAEJ;IAEA,MAAMC,eAAeL,IAAI,CAAC,EAAE,CAAC,EAAE,CAACM,IAAI;IACpC,IAAIC,QAAQ,CAAC,EAAEN,iBAAiB,CAACI,aAAa,CAAC,CAAC;IAEhD;;;GAGC,GACD,IAAI,CAACG,IAAAA,qBAAU,EAACR,IAAI,CAAC,EAAE,CAAC,EAAE,GAAG;QAC3B,OAAOO;IACT;IAEA,MAAME,eAAe,IAAIC;IAEzB,IAAK,IAAIC,IAAI,GAAGA,IAAIX,KAAKG,MAAM,EAAEQ,IAAK;QACpC,IAAIX,IAAI,CAACW,EAAE,CAAC,EAAE,CAACL,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7D,IAAID,SAAS;QACX,MAAM,IAAIzC,MAAM,CAAC,kCAAkC,EAAE2C,KAAKC,SAAS,CAACN,UAAUI,SAAS,IAAI,EAAE,EAAE,CAAC;IAClG;IAEA,MAAMG,UAAUrD,iBACd8C,UAAUI,SAAS,IAAI,EAAE,EACzB7C,mBACAC;IAGF,MAAMgD,sBAAsB/B,YAAYwB,MAAM,CAC5C,CAACC,KAAkBlB;QACjB,OAAO;YACLU,MAAM;YACNN,KAAKmB;YACLE,UAAU;mBAAIP,IAAIO,QAAQ;mBAAKzB,OAAOyB,QAAQ;aAAC;YAC/CC,YAAY;mBAAIR,IAAIQ,UAAU;mBAAK1B,OAAO0B,UAAU;aAAC;YACrDzB,OAAO,EAAE;QACX;IACF,GACA;QACES,MAAM;QACNN,KAAK;QACLqB,UAAU,EAAE;QACZC,YAAY,EAAE;QACdzB,OAAO,EAAE;IACX;IAEF,OAAOuB;AACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../meerkat-core/src/types/cube-types/index.d.ts"],"sourcesContent":["export * from './query';\nexport * from './table';\n"],"names":[],"mappings":";;uBAAc;uBACA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../meerkat-core/src/types/cube-types/index.ts"],"sourcesContent":["export * from './query';\nexport * from './table';\n"],"names":[],"mappings":";;uBAAc;uBACA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../meerkat-core/src/types/cube-types/query.d.ts"],"sourcesContent":["/**\n * Request type data type.\n */\ntype RequestType = 'multi';\n/**\n * Result type data type.\n */\ntype ResultType = 'default' | 'compact';\n/**\n * API type data type.\n */\ntype ApiType = 'sql' | 'graphql' | 'rest' | 'ws' | 'stream';\n/**\n * Parsed query type data type.\n */\ntype QueryType = 'regularQuery' | 'compareDateRangeQuery' | 'blendingQuery';\n/**\n * String that represent query member type.\n */\ntype MemberType = 'measures' | 'dimensions' | 'segments';\n/**\n * Member identifier. Should satisfy to the following regexp: /^[a-zA-Z0-9_]+\\.[a-zA-Z0-9_]+$/\n */\ntype Member = string;\n/**\n * Datetime member identifier. Should satisfy to the following\n * regexp: /^[a-zA-Z0-9_]+\\.[a-zA-Z0-9_]+(\\.(second|minute|hour|day|week|month|year))?$/\n */\ntype TimeMember = string;\n/**\n * Filter operator string.\n */\ntype FilterOperator = 'equals' | 'notEquals' | 'contains' | 'notContains' | 'in' | 'notIn' | 'gt' | 'gte' | 'lt' | 'lte' | 'set' | 'notSet' | 'inDateRange' | 'notInDateRange' | 'onTheDate' | 'beforeDate' | 'afterDate' | 'measureFilter';\n/**\n * Time dimension granularity data type.\n */\ntype QueryTimeDimensionGranularity = 'quarter' | 'day' | 'month' | 'year' | 'week' | 'hour' | 'minute' | 'second';\n/**\n * Query order data type.\n */\ntype QueryOrderType = 'asc' | 'desc';\n/**\n * ApiScopes data type.\n */\ntype ApiScopes = 'graphql' | 'meta' | 'data' | 'jobs';\ninterface QueryFilter {\n member: Member;\n operator: FilterOperator;\n values?: string[];\n}\n/**\n * Query 'and'-filters type definition.\n */\ntype LogicalAndFilter = {\n and: (QueryFilter | {\n or: (QueryFilter | LogicalAndFilter)[];\n })[];\n};\n/**\n * Query 'or'-filters type definition.\n */\ntype LogicalOrFilter = {\n or: (QueryFilter | LogicalAndFilter)[];\n};\n/**\n * Query datetime dimention interface.\n */\ninterface QueryTimeDimension {\n dimension: Member;\n dateRange?: string[] | string;\n granularity?: QueryTimeDimensionGranularity;\n}\n/**\n * Incoming network query data type.\n */\ninterface Query {\n measures: Member[];\n dimensions?: (Member | TimeMember)[];\n filters?: (QueryFilter | LogicalAndFilter | LogicalOrFilter)[];\n timeDimensions?: QueryTimeDimension[];\n segments?: Member[];\n limit?: null | number;\n offset?: number;\n total?: boolean;\n totalQuery?: boolean;\n order?: any;\n timezone?: string;\n renewQuery?: boolean;\n ungrouped?: boolean;\n responseFormat?: ResultType;\n}\n/**\n * Normalized filter interface.\n */\ninterface NormalizedQueryFilter extends QueryFilter {\n dimension?: Member;\n}\n/**\n * Normalized query interface.\n */\ninterface NormalizedQuery extends Query {\n filters?: NormalizedQueryFilter[];\n rowLimit?: null | number;\n order?: [{\n id: string;\n desc: boolean;\n }];\n}\nexport { ApiScopes, ApiType, FilterOperator, LogicalAndFilter, LogicalOrFilter, Member, MemberType, NormalizedQuery, NormalizedQueryFilter, Query, QueryFilter, QueryOrderType, QueryTimeDimension, QueryTimeDimensionGranularity, QueryType, RequestType, ResultType, TimeMember, };\n"],"names":[],"mappings":"AAAA;;CAEC"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Request type data type.
|
|
3
|
+
*/
|
|
4
|
+
type RequestType = 'multi';
|
|
5
|
+
/**
|
|
6
|
+
* Result type data type.
|
|
7
|
+
*/
|
|
8
|
+
type ResultType = 'default' | 'compact';
|
|
9
|
+
/**
|
|
10
|
+
* API type data type.
|
|
11
|
+
*/
|
|
12
|
+
type ApiType = 'sql' | 'graphql' | 'rest' | 'ws' | 'stream';
|
|
13
|
+
/**
|
|
14
|
+
* Parsed query type data type.
|
|
15
|
+
*/
|
|
16
|
+
type QueryType = 'regularQuery' | 'compareDateRangeQuery' | 'blendingQuery';
|
|
17
|
+
/**
|
|
18
|
+
* String that represent query member type.
|
|
19
|
+
*/
|
|
20
|
+
type MemberType = 'measures' | 'dimensions' | 'segments';
|
|
21
|
+
/**
|
|
22
|
+
* Member identifier. Should satisfy to the following regexp: /^[a-zA-Z0-9_]+\.[a-zA-Z0-9_]+$/
|
|
23
|
+
*/
|
|
24
|
+
type Member = string;
|
|
25
|
+
/**
|
|
26
|
+
* Datetime member identifier. Should satisfy to the following
|
|
27
|
+
* regexp: /^[a-zA-Z0-9_]+\.[a-zA-Z0-9_]+(\.(second|minute|hour|day|week|month|year))?$/
|
|
28
|
+
*/
|
|
29
|
+
type TimeMember = string;
|
|
30
|
+
/**
|
|
31
|
+
* Filter operator string.
|
|
32
|
+
*/
|
|
33
|
+
type FilterOperator = 'equals' | 'notEquals' | 'contains' | 'notContains' | 'in' | 'notIn' | 'gt' | 'gte' | 'lt' | 'lte' | 'set' | 'notSet' | 'inDateRange' | 'notInDateRange' | 'onTheDate' | 'beforeDate' | 'afterDate' | 'measureFilter';
|
|
34
|
+
/**
|
|
35
|
+
* Time dimension granularity data type.
|
|
36
|
+
*/
|
|
37
|
+
type QueryTimeDimensionGranularity = 'quarter' | 'day' | 'month' | 'year' | 'week' | 'hour' | 'minute' | 'second';
|
|
38
|
+
/**
|
|
39
|
+
* Query order data type.
|
|
40
|
+
*/
|
|
41
|
+
type QueryOrderType = 'asc' | 'desc';
|
|
42
|
+
/**
|
|
43
|
+
* ApiScopes data type.
|
|
44
|
+
*/
|
|
45
|
+
type ApiScopes = 'graphql' | 'meta' | 'data' | 'jobs';
|
|
46
|
+
export type FilterType = 'BASE_FILTER' | 'PROJECTION_FILTER';
|
|
47
|
+
interface QueryFilter {
|
|
48
|
+
member: Member;
|
|
49
|
+
operator: FilterOperator;
|
|
50
|
+
values?: string[];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Query 'and'-filters type definition.
|
|
54
|
+
*/
|
|
55
|
+
type LogicalAndFilter = {
|
|
56
|
+
and: (QueryFilter | {
|
|
57
|
+
or: (QueryFilter | LogicalAndFilter)[];
|
|
58
|
+
})[];
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Query 'or'-filters type definition.
|
|
62
|
+
*/
|
|
63
|
+
type LogicalOrFilter = {
|
|
64
|
+
or: (QueryFilter | LogicalAndFilter)[];
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Query datetime dimention interface.
|
|
68
|
+
*/
|
|
69
|
+
interface QueryTimeDimension {
|
|
70
|
+
dimension: Member;
|
|
71
|
+
dateRange?: string[] | string;
|
|
72
|
+
granularity?: QueryTimeDimensionGranularity;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Join Edge data type.
|
|
76
|
+
*/
|
|
77
|
+
interface JoinNode {
|
|
78
|
+
/**
|
|
79
|
+
* Left node.
|
|
80
|
+
*/
|
|
81
|
+
left: Member;
|
|
82
|
+
/**
|
|
83
|
+
* Right node.
|
|
84
|
+
*/
|
|
85
|
+
right: Member;
|
|
86
|
+
/**
|
|
87
|
+
* On condition.
|
|
88
|
+
*/
|
|
89
|
+
on: string;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Single node data type.
|
|
93
|
+
* This is the case when there is no join. Just a single node.
|
|
94
|
+
*/
|
|
95
|
+
interface SingleNode {
|
|
96
|
+
/**
|
|
97
|
+
* Left node.
|
|
98
|
+
*/
|
|
99
|
+
left: Member;
|
|
100
|
+
}
|
|
101
|
+
type JoinPath = [JoinNode | SingleNode, ...JoinNode[]];
|
|
102
|
+
export declare const isJoinNode: (node: JoinNode | SingleNode) => node is JoinNode;
|
|
103
|
+
/**
|
|
104
|
+
* Incoming network query data type.
|
|
105
|
+
*/
|
|
106
|
+
type MeerkatQueryFilter = QueryFilter | LogicalAndFilter | LogicalOrFilter;
|
|
107
|
+
interface Query {
|
|
108
|
+
measures: Member[];
|
|
109
|
+
dimensions?: (Member | TimeMember)[];
|
|
110
|
+
filters?: MeerkatQueryFilter[];
|
|
111
|
+
timeDimensions?: QueryTimeDimension[];
|
|
112
|
+
joinPaths?: JoinPath[];
|
|
113
|
+
segments?: Member[];
|
|
114
|
+
limit?: null | number;
|
|
115
|
+
offset?: number;
|
|
116
|
+
total?: boolean;
|
|
117
|
+
totalQuery?: boolean;
|
|
118
|
+
order?: any;
|
|
119
|
+
timezone?: string;
|
|
120
|
+
renewQuery?: boolean;
|
|
121
|
+
ungrouped?: boolean;
|
|
122
|
+
responseFormat?: ResultType;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Normalized filter interface.
|
|
126
|
+
*/
|
|
127
|
+
interface NormalizedQueryFilter extends QueryFilter {
|
|
128
|
+
dimension?: Member;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Normalized query interface.
|
|
132
|
+
*/
|
|
133
|
+
interface NormalizedQuery extends Query {
|
|
134
|
+
filters?: NormalizedQueryFilter[];
|
|
135
|
+
rowLimit?: null | number;
|
|
136
|
+
order?: [{
|
|
137
|
+
id: string;
|
|
138
|
+
desc: boolean;
|
|
139
|
+
}];
|
|
140
|
+
}
|
|
141
|
+
export { ApiScopes, ApiType, FilterOperator, JoinPath, LogicalAndFilter, LogicalOrFilter, MeerkatQueryFilter, Member, MemberType, NormalizedQuery, NormalizedQueryFilter, Query, QueryFilter, QueryOrderType, QueryTimeDimension, QueryTimeDimensionGranularity, QueryType, RequestType, ResultType, TimeMember, };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Request type data type.
|
|
3
|
+
*/ "use strict";
|
|
4
|
+
Object.defineProperty(exports, "isJoinNode", {
|
|
5
|
+
enumerable: true,
|
|
6
|
+
get: function() {
|
|
7
|
+
return isJoinNode;
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
const isJoinNode = (node)=>{
|
|
11
|
+
return 'right' in node;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=query.js.map
|