@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.
Files changed (237) hide show
  1. package/README.md +11 -0
  2. package/package.json +30 -0
  3. package/src/ast-builder/ast-builder.d.ts +6 -0
  4. package/src/ast-builder/ast-builder.js +89 -0
  5. package/src/ast-builder/ast-builder.js.map +1 -0
  6. package/src/ast-deserializer/ast-deserializer.d.ts +5 -0
  7. package/src/ast-deserializer/ast-deserializer.js +30 -0
  8. package/src/ast-deserializer/ast-deserializer.js.map +1 -0
  9. package/src/context-params/context-params-ast.d.ts +11 -0
  10. package/src/context-params/context-params-ast.js +55 -0
  11. package/src/context-params/context-params-ast.js.map +1 -0
  12. package/src/cube-filter-transformer/and/and.d.ts +2 -0
  13. package/src/cube-filter-transformer/and/and.js +18 -0
  14. package/src/cube-filter-transformer/and/and.js.map +1 -0
  15. package/src/cube-filter-transformer/base-condition-builder/base-condition-builder.d.ts +154 -0
  16. package/src/cube-filter-transformer/base-condition-builder/base-condition-builder.js +159 -0
  17. package/src/cube-filter-transformer/base-condition-builder/base-condition-builder.js.map +1 -0
  18. package/src/cube-filter-transformer/contains/contains.d.ts +65 -0
  19. package/src/cube-filter-transformer/contains/contains.js +70 -0
  20. package/src/cube-filter-transformer/contains/contains.js.map +1 -0
  21. package/src/cube-filter-transformer/equals/equals-array.d.ts +2 -0
  22. package/src/cube-filter-transformer/equals/equals-array.js +30 -0
  23. package/src/cube-filter-transformer/equals/equals-array.js.map +1 -0
  24. package/src/cube-filter-transformer/equals/equals.d.ts +2 -0
  25. package/src/cube-filter-transformer/equals/equals.js +37 -0
  26. package/src/cube-filter-transformer/equals/equals.js.map +1 -0
  27. package/src/cube-filter-transformer/factory.d.ts +5 -0
  28. package/src/cube-filter-transformer/factory.js +124 -0
  29. package/src/cube-filter-transformer/factory.js.map +1 -0
  30. package/src/cube-filter-transformer/gt/gt.d.ts +2 -0
  31. package/src/cube-filter-transformer/gt/gt.js +30 -0
  32. package/src/cube-filter-transformer/gt/gt.js.map +1 -0
  33. package/src/cube-filter-transformer/gte/gte.d.ts +2 -0
  34. package/src/cube-filter-transformer/gte/gte.js +30 -0
  35. package/src/cube-filter-transformer/gte/gte.js.map +1 -0
  36. package/src/cube-filter-transformer/in/in.d.ts +2 -0
  37. package/src/cube-filter-transformer/in/in.js +77 -0
  38. package/src/cube-filter-transformer/in/in.js.map +1 -0
  39. package/src/cube-filter-transformer/in-date-range/in-date-range.d.ts +2 -0
  40. package/src/cube-filter-transformer/in-date-range/in-date-range.js +24 -0
  41. package/src/cube-filter-transformer/in-date-range/in-date-range.js.map +1 -0
  42. package/src/cube-filter-transformer/lt/lt.d.ts +2 -0
  43. package/src/cube-filter-transformer/lt/lt.js +30 -0
  44. package/src/cube-filter-transformer/lt/lt.js.map +1 -0
  45. package/src/cube-filter-transformer/lte/lte.d.ts +2 -0
  46. package/src/cube-filter-transformer/lte/lte.js +30 -0
  47. package/src/cube-filter-transformer/lte/lte.js.map +1 -0
  48. package/src/cube-filter-transformer/not/not.d.ts +2 -0
  49. package/src/cube-filter-transformer/not/not.js +18 -0
  50. package/src/cube-filter-transformer/not/not.js.map +1 -0
  51. package/src/cube-filter-transformer/not-In-date-range/not-In-date-range.d.ts +2 -0
  52. package/src/cube-filter-transformer/not-In-date-range/not-In-date-range.js +24 -0
  53. package/src/cube-filter-transformer/not-In-date-range/not-In-date-range.js.map +1 -0
  54. package/src/cube-filter-transformer/not-contains/not-contains.d.ts +65 -0
  55. package/src/cube-filter-transformer/not-contains/not-contains.js +70 -0
  56. package/src/cube-filter-transformer/not-contains/not-contains.js.map +1 -0
  57. package/src/cube-filter-transformer/not-equals/not-equals-array.d.ts +2 -0
  58. package/src/cube-filter-transformer/not-equals/not-equals-array.js +26 -0
  59. package/src/cube-filter-transformer/not-equals/not-equals-array.js.map +1 -0
  60. package/src/cube-filter-transformer/not-equals/not-equals.d.ts +8 -0
  61. package/src/cube-filter-transformer/not-equals/not-equals.js +37 -0
  62. package/src/cube-filter-transformer/not-equals/not-equals.js.map +1 -0
  63. package/src/cube-filter-transformer/not-in/not-in.d.ts +2 -0
  64. package/src/cube-filter-transformer/not-in/not-in.js +84 -0
  65. package/src/cube-filter-transformer/not-in/not-in.js.map +1 -0
  66. package/src/cube-filter-transformer/not-set/not-set.d.ts +2 -0
  67. package/src/cube-filter-transformer/not-set/not-set.js +26 -0
  68. package/src/cube-filter-transformer/not-set/not-set.js.map +1 -0
  69. package/src/cube-filter-transformer/or/or.d.ts +2 -0
  70. package/src/cube-filter-transformer/or/or.js +18 -0
  71. package/src/cube-filter-transformer/or/or.js.map +1 -0
  72. package/src/cube-filter-transformer/set/set.d.ts +2 -0
  73. package/src/cube-filter-transformer/set/set.js +26 -0
  74. package/src/cube-filter-transformer/set/set.js.map +1 -0
  75. package/src/cube-group-by-transformer/cube-group-by-transformer.d.ts +8 -0
  76. package/src/cube-group-by-transformer/cube-group-by-transformer.js +25 -0
  77. package/src/cube-group-by-transformer/cube-group-by-transformer.js.map +1 -0
  78. package/src/cube-limit-offset-transformer/cube-limit-offset-transformer.d.ts +31 -0
  79. package/src/cube-limit-offset-transformer/cube-limit-offset-transformer.js +42 -0
  80. package/src/cube-limit-offset-transformer/cube-limit-offset-transformer.js.map +1 -0
  81. package/src/cube-measure-transformer/cube-measure-transformer.d.ts +21 -0
  82. package/src/cube-measure-transformer/cube-measure-transformer.js +126 -0
  83. package/src/cube-measure-transformer/cube-measure-transformer.js.map +1 -0
  84. package/src/cube-order-by-transformer/cube-order-by-transformer.d.ts +21 -0
  85. package/src/cube-order-by-transformer/cube-order-by-transformer.js +39 -0
  86. package/src/cube-order-by-transformer/cube-order-by-transformer.js.map +1 -0
  87. package/src/cube-to-duckdb/cube-filter-to-duckdb.d.ts +16 -0
  88. package/src/cube-to-duckdb/cube-filter-to-duckdb.js +3 -0
  89. package/src/cube-to-duckdb/cube-filter-to-duckdb.js.map +1 -0
  90. package/src/filter-params/filter-params-ast.d.ts +33 -0
  91. package/src/filter-params/filter-params-ast.js +115 -0
  92. package/src/filter-params/filter-params-ast.js.map +1 -0
  93. package/src/get-projection-clause/get-projection-clause.d.ts +27 -0
  94. package/src/get-projection-clause/get-projection-clause.js +135 -0
  95. package/src/get-projection-clause/get-projection-clause.js.map +1 -0
  96. package/src/get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections.d.ts +8 -0
  97. package/src/get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections.js +99 -0
  98. package/src/get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections.js.map +1 -0
  99. package/src/index.d.ts +16 -0
  100. package/src/index.js +55 -0
  101. package/src/index.js.map +1 -0
  102. package/src/joins/joins.d.ts +22 -0
  103. package/src/joins/joins.js +170 -0
  104. package/src/joins/joins.js.map +1 -0
  105. package/src/types/cube-types/index.d.js +6 -0
  106. package/src/types/cube-types/index.d.js.map +1 -0
  107. package/src/types/cube-types/index.d.ts +2 -0
  108. package/src/types/cube-types/index.js +6 -0
  109. package/src/types/cube-types/index.js.map +1 -0
  110. package/src/types/cube-types/query.d.js +5 -0
  111. package/src/types/cube-types/query.d.js.map +1 -0
  112. package/src/types/cube-types/query.d.ts +141 -0
  113. package/src/types/cube-types/query.js +14 -0
  114. package/src/types/cube-types/query.js.map +1 -0
  115. package/src/types/cube-types/table.d.js +3 -0
  116. package/src/types/cube-types/table.d.js.map +1 -0
  117. package/src/types/cube-types/table.d.ts +25 -0
  118. package/src/types/cube-types/table.js +3 -0
  119. package/src/types/cube-types/table.js.map +1 -0
  120. package/src/types/duckdb-serialization-types/index.d.js +11 -0
  121. package/src/types/duckdb-serialization-types/index.d.js.map +1 -0
  122. package/src/types/duckdb-serialization-types/index.d.ts +7 -0
  123. package/src/types/duckdb-serialization-types/index.js +11 -0
  124. package/src/types/duckdb-serialization-types/index.js.map +1 -0
  125. package/src/types/duckdb-serialization-types/serialization/Constraint.d.ts +47 -0
  126. package/src/types/duckdb-serialization-types/serialization/Constraint.js +31 -0
  127. package/src/types/duckdb-serialization-types/serialization/Constraint.js.map +1 -0
  128. package/src/types/duckdb-serialization-types/serialization/CreateInfo.d.ts +95 -0
  129. package/src/types/duckdb-serialization-types/serialization/CreateInfo.js +67 -0
  130. package/src/types/duckdb-serialization-types/serialization/CreateInfo.js.map +1 -0
  131. package/src/types/duckdb-serialization-types/serialization/Expression.d.js +3 -0
  132. package/src/types/duckdb-serialization-types/serialization/Expression.d.js.map +1 -0
  133. package/src/types/duckdb-serialization-types/serialization/Expression.d.ts +186 -0
  134. package/src/types/duckdb-serialization-types/serialization/Expression.js +130 -0
  135. package/src/types/duckdb-serialization-types/serialization/Expression.js.map +1 -0
  136. package/src/types/duckdb-serialization-types/serialization/LogicalOperator.d.ts +231 -0
  137. package/src/types/duckdb-serialization-types/serialization/LogicalOperator.js +47 -0
  138. package/src/types/duckdb-serialization-types/serialization/LogicalOperator.js.map +1 -0
  139. package/src/types/duckdb-serialization-types/serialization/MacroFunction.d.ts +20 -0
  140. package/src/types/duckdb-serialization-types/serialization/MacroFunction.js +15 -0
  141. package/src/types/duckdb-serialization-types/serialization/MacroFunction.js.map +1 -0
  142. package/src/types/duckdb-serialization-types/serialization/Misc.d.js +3 -0
  143. package/src/types/duckdb-serialization-types/serialization/Misc.d.js.map +1 -0
  144. package/src/types/duckdb-serialization-types/serialization/Misc.d.ts +3 -0
  145. package/src/types/duckdb-serialization-types/serialization/Misc.js +3 -0
  146. package/src/types/duckdb-serialization-types/serialization/Misc.js.map +1 -0
  147. package/src/types/duckdb-serialization-types/serialization/Nodes.d.js +10 -0
  148. package/src/types/duckdb-serialization-types/serialization/Nodes.d.js.map +1 -0
  149. package/src/types/duckdb-serialization-types/serialization/Nodes.d.ts +212 -0
  150. package/src/types/duckdb-serialization-types/serialization/Nodes.js +92 -0
  151. package/src/types/duckdb-serialization-types/serialization/Nodes.js.map +1 -0
  152. package/src/types/duckdb-serialization-types/serialization/ParseInfo.d.ts +192 -0
  153. package/src/types/duckdb-serialization-types/serialization/ParseInfo.js +128 -0
  154. package/src/types/duckdb-serialization-types/serialization/ParseInfo.js.map +1 -0
  155. package/src/types/duckdb-serialization-types/serialization/ParsedExpression.d.js +3 -0
  156. package/src/types/duckdb-serialization-types/serialization/ParsedExpression.d.js.map +1 -0
  157. package/src/types/duckdb-serialization-types/serialization/ParsedExpression.d.ts +114 -0
  158. package/src/types/duckdb-serialization-types/serialization/ParsedExpression.js +37 -0
  159. package/src/types/duckdb-serialization-types/serialization/ParsedExpression.js.map +1 -0
  160. package/src/types/duckdb-serialization-types/serialization/QueryNode.d.js +3 -0
  161. package/src/types/duckdb-serialization-types/serialization/QueryNode.d.js.map +1 -0
  162. package/src/types/duckdb-serialization-types/serialization/QueryNode.d.ts +62 -0
  163. package/src/types/duckdb-serialization-types/serialization/QueryNode.js +42 -0
  164. package/src/types/duckdb-serialization-types/serialization/QueryNode.js.map +1 -0
  165. package/src/types/duckdb-serialization-types/serialization/ResultModifier.d.js +3 -0
  166. package/src/types/duckdb-serialization-types/serialization/ResultModifier.d.js.map +1 -0
  167. package/src/types/duckdb-serialization-types/serialization/ResultModifier.d.ts +29 -0
  168. package/src/types/duckdb-serialization-types/serialization/ResultModifier.js +16 -0
  169. package/src/types/duckdb-serialization-types/serialization/ResultModifier.js.map +1 -0
  170. package/src/types/duckdb-serialization-types/serialization/Statement.d.js +3 -0
  171. package/src/types/duckdb-serialization-types/serialization/Statement.d.js.map +1 -0
  172. package/src/types/duckdb-serialization-types/serialization/Statement.d.ts +4 -0
  173. package/src/types/duckdb-serialization-types/serialization/Statement.js +3 -0
  174. package/src/types/duckdb-serialization-types/serialization/Statement.js.map +1 -0
  175. package/src/types/duckdb-serialization-types/serialization/TableFilter.d.js +3 -0
  176. package/src/types/duckdb-serialization-types/serialization/TableFilter.d.js.map +1 -0
  177. package/src/types/duckdb-serialization-types/serialization/TableFilter.d.ts +32 -0
  178. package/src/types/duckdb-serialization-types/serialization/TableFilter.js +17 -0
  179. package/src/types/duckdb-serialization-types/serialization/TableFilter.js.map +1 -0
  180. package/src/types/duckdb-serialization-types/serialization/TableRef.d.js +3 -0
  181. package/src/types/duckdb-serialization-types/serialization/TableRef.d.js.map +1 -0
  182. package/src/types/duckdb-serialization-types/serialization/TableRef.d.ts +84 -0
  183. package/src/types/duckdb-serialization-types/serialization/TableRef.js +53 -0
  184. package/src/types/duckdb-serialization-types/serialization/TableRef.js.map +1 -0
  185. package/src/types/duckdb-serialization-types/serialization/Types.d.js +3 -0
  186. package/src/types/duckdb-serialization-types/serialization/Types.d.js.map +1 -0
  187. package/src/types/duckdb-serialization-types/serialization/Types.d.ts +53 -0
  188. package/src/types/duckdb-serialization-types/serialization/Types.js +21 -0
  189. package/src/types/duckdb-serialization-types/serialization/Types.js.map +1 -0
  190. package/src/types/duckdb-serialization-types/serialization/example.d.ts +1 -0
  191. package/src/types/duckdb-serialization-types/serialization/example.js +131 -0
  192. package/src/types/duckdb-serialization-types/serialization/example.js.map +1 -0
  193. package/src/utils/__fixtures__/joins.fixtures.d.ts +211 -0
  194. package/src/utils/__fixtures__/joins.fixtures.js +922 -0
  195. package/src/utils/__fixtures__/joins.fixtures.js.map +1 -0
  196. package/src/utils/base-ast.d.ts +3 -0
  197. package/src/utils/base-ast.js +64 -0
  198. package/src/utils/base-ast.js.map +1 -0
  199. package/src/utils/constants.d.ts +2 -0
  200. package/src/utils/constants.js +19 -0
  201. package/src/utils/constants.js.map +1 -0
  202. package/src/utils/cube-filter-enrichment.d.ts +4 -0
  203. package/src/utils/cube-filter-enrichment.js +63 -0
  204. package/src/utils/cube-filter-enrichment.js.map +1 -0
  205. package/src/utils/cube-to-table-schema.d.ts +3 -0
  206. package/src/utils/cube-to-table-schema.js +104 -0
  207. package/src/utils/cube-to-table-schema.js.map +1 -0
  208. package/src/utils/cube-type-to-duckdb-type.d.ts +6 -0
  209. package/src/utils/cube-type-to-duckdb-type.js +17 -0
  210. package/src/utils/cube-type-to-duckdb-type.js.map +1 -0
  211. package/src/utils/find-in-table-schema.d.ts +4 -0
  212. package/src/utils/find-in-table-schema.js +40 -0
  213. package/src/utils/find-in-table-schema.js.map +1 -0
  214. package/src/utils/get-possible-nodes.d.ts +15 -0
  215. package/src/utils/get-possible-nodes.js +152 -0
  216. package/src/utils/get-possible-nodes.js.map +1 -0
  217. package/src/utils/get-type-info.d.ts +7 -0
  218. package/src/utils/get-type-info.js +44 -0
  219. package/src/utils/get-type-info.js.map +1 -0
  220. package/src/utils/is-array-member-type.d.ts +4 -0
  221. package/src/utils/is-array-member-type.js +12 -0
  222. package/src/utils/is-array-member-type.js.map +1 -0
  223. package/src/utils/key-from-measures-dimension.d.ts +2 -0
  224. package/src/utils/key-from-measures-dimension.js +34 -0
  225. package/src/utils/key-from-measures-dimension.js.map +1 -0
  226. package/src/utils/meerkat-placeholder-replacer.d.ts +1 -0
  227. package/src/utils/meerkat-placeholder-replacer.js +14 -0
  228. package/src/utils/meerkat-placeholder-replacer.js.map +1 -0
  229. package/src/utils/member-key-to-safe-key.d.ts +1 -0
  230. package/src/utils/member-key-to-safe-key.js +13 -0
  231. package/src/utils/member-key-to-safe-key.js.map +1 -0
  232. package/src/utils/modify-meerkat-filter.d.ts +3 -0
  233. package/src/utils/modify-meerkat-filter.js +30 -0
  234. package/src/utils/modify-meerkat-filter.js.map +1 -0
  235. package/src/utils/type-guards.d.ts +8 -0
  236. package/src/utils/type-guards.js +83 -0
  237. package/src/utils/type-guards.js.map +1 -0
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "cubeLimitOffsetToAST", {
3
+ enumerable: true,
4
+ get: function() {
5
+ return cubeLimitOffsetToAST;
6
+ }
7
+ });
8
+ const _Expression = require("../types/duckdb-serialization-types/serialization/Expression");
9
+ const _ResultModifier = require("../types/duckdb-serialization-types/serialization/ResultModifier");
10
+ const cubeLimitOffsetToAST = (limit, offset)=>{
11
+ return {
12
+ type: _ResultModifier.ResultModifierType.LIMIT_MODIFIER,
13
+ limit: limit ? {
14
+ class: _Expression.ExpressionClass.CONSTANT,
15
+ type: _Expression.ExpressionType.VALUE_CONSTANT,
16
+ alias: '',
17
+ value: {
18
+ type: {
19
+ id: 'INTEGER',
20
+ type_info: null
21
+ },
22
+ is_null: false,
23
+ value: limit
24
+ }
25
+ } : null,
26
+ offset: offset ? {
27
+ class: _Expression.ExpressionClass.CONSTANT,
28
+ type: _Expression.ExpressionType.VALUE_CONSTANT,
29
+ alias: '',
30
+ value: {
31
+ type: {
32
+ id: 'INTEGER',
33
+ type_info: null
34
+ },
35
+ is_null: false,
36
+ value: offset
37
+ }
38
+ } : null
39
+ };
40
+ };
41
+
42
+ //# sourceMappingURL=cube-limit-offset-transformer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../meerkat-core/src/cube-limit-offset-transformer/cube-limit-offset-transformer.ts"],"sourcesContent":["import { ExpressionClass, ExpressionType } from '../types/duckdb-serialization-types/serialization/Expression';\nimport { ResultModifierType } from '../types/duckdb-serialization-types/serialization/ResultModifier';\n\nexport const cubeLimitOffsetToAST = (\n limit?: number | null,\n offset?: number | null\n) => {\n return {\n type: ResultModifierType.LIMIT_MODIFIER,\n limit: limit\n ? {\n class: ExpressionClass.CONSTANT,\n type: ExpressionType.VALUE_CONSTANT,\n alias: '',\n value: {\n type: {\n id: 'INTEGER',\n type_info: null,\n },\n is_null: false,\n value: limit,\n },\n }\n : null,\n offset: offset\n ? {\n class: ExpressionClass.CONSTANT,\n type: ExpressionType.VALUE_CONSTANT,\n alias: '',\n value: {\n type: {\n id: 'INTEGER',\n type_info: null,\n },\n is_null: false,\n value: offset,\n },\n }\n : null,\n };\n};\n"],"names":["cubeLimitOffsetToAST","limit","offset","type","ResultModifierType","LIMIT_MODIFIER","class","ExpressionClass","CONSTANT","ExpressionType","VALUE_CONSTANT","alias","value","id","type_info","is_null"],"mappings":";+BAGaA;;;eAAAA;;;4BAHmC;gCACb;AAE5B,MAAMA,uBAAuB,CAClCC,OACAC;IAEA,OAAO;QACLC,MAAMC,kCAAkB,CAACC,cAAc;QACvCJ,OAAOA,QACH;YACEK,OAAOC,2BAAe,CAACC,QAAQ;YAC/BL,MAAMM,0BAAc,CAACC,cAAc;YACnCC,OAAO;YACPC,OAAO;gBACLT,MAAM;oBACJU,IAAI;oBACJC,WAAW;gBACb;gBACAC,SAAS;gBACTH,OAAOX;YACT;QACF,IACA;QACJC,QAAQA,SACJ;YACEI,OAAOC,2BAAe,CAACC,QAAQ;YAC/BL,MAAMM,0BAAc,CAACC,cAAc;YACnCC,OAAO;YACPC,OAAO;gBACLT,MAAM;oBACJU,IAAI;oBACJC,WAAW;gBACb;gBACAC,SAAS;gBACTH,OAAOV;YACT;QACF,IACA;IACN;AACF"}
@@ -0,0 +1,21 @@
1
+ import { Member } from '../types/cube-types/query';
2
+ import { Measure, TableSchema } from '../types/cube-types/table';
3
+ export declare const cubeMeasureToSQLSelectString: (measures: Member[], tableSchema: TableSchema) => string;
4
+ export declare const getSelectReplacedSql: (sql: string, selectString: string) => string;
5
+ /**
6
+ * Get all the columns used in the measures.
7
+ * This is used for extracting the columns used in the measures needed for the projection.
8
+ * Example: The joins implementation uses this to get the columns used in the measures to join the tables.
9
+ * like the SQL for the measure is `SUM(table.total)` and the table name is `table`, then the column used is `total`
10
+ * table cannot be used directly here because the joined table would have column name ambiguity.
11
+ * Thus these columns are projected and directly used in the join.
12
+ */
13
+ export declare const getAllColumnUsedInMeasures: (measures: Measure[], tableSchema: TableSchema) => string[];
14
+ /**
15
+ * Replace the first SELECT * from the sqlToReplace with the cube measure
16
+ * @param measures
17
+ * @param tableSchema
18
+ * @param sqlToReplace
19
+ * @returns
20
+ */
21
+ export declare const applyProjectionToSQLQuery: (dimensions: Member[], measures: Member[], tableSchema: TableSchema, sqlToReplace: string) => string;
@@ -0,0 +1,126 @@
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
+ cubeMeasureToSQLSelectString: function() {
10
+ return cubeMeasureToSQLSelectString;
11
+ },
12
+ getSelectReplacedSql: function() {
13
+ return getSelectReplacedSql;
14
+ },
15
+ getAllColumnUsedInMeasures: function() {
16
+ return getAllColumnUsedInMeasures;
17
+ },
18
+ applyProjectionToSQLQuery: function() {
19
+ return applyProjectionToSQLQuery;
20
+ }
21
+ });
22
+ const _meerkatplaceholderreplacer = require("../utils/meerkat-placeholder-replacer");
23
+ const _memberkeytosafekey = require("../utils/member-key-to-safe-key");
24
+ const cubeMeasureToSQLSelectString = (measures, tableSchema)=>{
25
+ let base = 'SELECT';
26
+ for(let i = 0; i < measures.length; i++){
27
+ const measure = measures[i];
28
+ if (measure === '*') {
29
+ base += ` ${tableSchema.name}.*`;
30
+ continue;
31
+ }
32
+ const [tableSchemaName, measureKeyWithoutTable] = measure.split('.');
33
+ const aliasKey = (0, _memberkeytosafekey.memberKeyToSafeKey)(measure);
34
+ const measureSchema = tableSchema.measures.find((m)=>m.name === measureKeyWithoutTable);
35
+ if (!measureSchema) {
36
+ continue;
37
+ }
38
+ if (i > 0) {
39
+ base += ', ';
40
+ }
41
+ let meerkatReplacedSqlString = (0, _meerkatplaceholderreplacer.meerkatPlaceholderReplacer)(measureSchema.sql, tableSchema.name);
42
+ /**
43
+ * Here we extract the columns used in the measure and replace them with the safeKey.
44
+ * We need to do this because the columns used in the measure are not directly available in the joined table.
45
+ * Thus we need to project them and use them in the join.
46
+ */ const columnsUsedInMeasure = getColumnsFromSQL(meerkatReplacedSqlString, tableSchemaName);
47
+ //Replace all the columnsUsedInMeasure with safeKey
48
+ columnsUsedInMeasure == null ? void 0 : columnsUsedInMeasure.forEach((measureKey)=>{
49
+ const column = measureKey.split('.')[1];
50
+ const memberKey = `${tableSchemaName}.${column}`;
51
+ const columnKey = (0, _memberkeytosafekey.memberKeyToSafeKey)(memberKey);
52
+ meerkatReplacedSqlString = meerkatReplacedSqlString.replace(memberKey, columnKey);
53
+ });
54
+ base += ` ${meerkatReplacedSqlString} AS ${aliasKey} `;
55
+ }
56
+ return base;
57
+ };
58
+ const addDimensionToSQLProjection = (dimensions, selectString, tableSchema)=>{
59
+ if (dimensions.length === 0) {
60
+ return selectString;
61
+ }
62
+ let newSelectString = selectString;
63
+ for(let i = 0; i < dimensions.length; i++){
64
+ const dimension = dimensions[i];
65
+ const dimensionKeyWithoutTable = dimension.split('.')[1];
66
+ const dimensionSchema = tableSchema.dimensions.find((m)=>m.name === dimensionKeyWithoutTable);
67
+ const aliasKey = (0, _memberkeytosafekey.memberKeyToSafeKey)(dimension);
68
+ if (!dimensionSchema) {
69
+ continue;
70
+ }
71
+ if (i > 0) {
72
+ newSelectString += ',';
73
+ }
74
+ // since alias key is expected to have been unfurled in the base query, we can just use it as is.
75
+ newSelectString += ` ${aliasKey}`;
76
+ }
77
+ return newSelectString;
78
+ };
79
+ const getSelectReplacedSql = (sql, selectString)=>{
80
+ /*
81
+ ** Replaces the select portion of a SQL string with the selectString passed.
82
+ */ const selectRegex = /SELECT\s\*/;
83
+ const match = sql.match(selectRegex);
84
+ if (!match) {
85
+ return sql;
86
+ }
87
+ const selectIndex = match.index;
88
+ if (selectIndex === undefined) {
89
+ throw new Error('SELECT * not found in SQL string');
90
+ }
91
+ const selectLength = match[0].length;
92
+ const beforeSelect = sql.substring(0, selectIndex);
93
+ const afterSelect = sql.substring(selectIndex + selectLength);
94
+ return `${beforeSelect}${selectString}${afterSelect}`;
95
+ };
96
+ const getAllColumnUsedInMeasures = (measures, tableSchema)=>{
97
+ let columns = [];
98
+ measures.forEach((measure)=>{
99
+ const columnMatch = getColumnsFromSQL(measure.sql, tableSchema.name);
100
+ if (columnMatch && columnMatch.length > 0) {
101
+ columns = [
102
+ ...columns,
103
+ ...columnMatch
104
+ ];
105
+ }
106
+ });
107
+ // Remove duplicates
108
+ return [
109
+ ...new Set(columns)
110
+ ];
111
+ };
112
+ const getColumnsFromSQL = (sql, tableName)=>{
113
+ const regex = new RegExp(`(${tableName}\\.[a-zA-Z0-9_]+)`, 'g');
114
+ const columnMatch = sql.match(regex);
115
+ return columnMatch;
116
+ };
117
+ const applyProjectionToSQLQuery = (dimensions, measures, tableSchema, sqlToReplace)=>{
118
+ let measureSelectString = cubeMeasureToSQLSelectString(measures, tableSchema);
119
+ if (measures.length > 0 && dimensions.length > 0) {
120
+ measureSelectString += ', ';
121
+ }
122
+ const selectString = addDimensionToSQLProjection(dimensions, measureSelectString, tableSchema);
123
+ return getSelectReplacedSql(sqlToReplace, selectString);
124
+ };
125
+
126
+ //# sourceMappingURL=cube-measure-transformer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../meerkat-core/src/cube-measure-transformer/cube-measure-transformer.ts"],"sourcesContent":["import { Member } from '../types/cube-types/query';\nimport { Measure, TableSchema } from '../types/cube-types/table';\nimport { meerkatPlaceholderReplacer } from '../utils/meerkat-placeholder-replacer';\nimport { memberKeyToSafeKey } from '../utils/member-key-to-safe-key';\n\nexport const cubeMeasureToSQLSelectString = (\n measures: Member[],\n tableSchema: TableSchema\n) => {\n let base = 'SELECT';\n for (let i = 0; i < measures.length; i++) {\n const measure = measures[i];\n if (measure === '*') {\n base += ` ${tableSchema.name}.*`;\n continue;\n }\n const [tableSchemaName, measureKeyWithoutTable] = measure.split('.');\n\n const aliasKey = memberKeyToSafeKey(measure);\n const measureSchema = tableSchema.measures.find(\n (m) => m.name === measureKeyWithoutTable\n );\n if (!measureSchema) {\n continue;\n }\n if (i > 0) {\n base += ', ';\n }\n let meerkatReplacedSqlString = meerkatPlaceholderReplacer(\n measureSchema.sql,\n tableSchema.name\n );\n\n /**\n * Here we extract the columns used in the measure and replace them with the safeKey.\n * We need to do this because the columns used in the measure are not directly available in the joined table.\n * Thus we need to project them and use them in the join.\n */\n\n const columnsUsedInMeasure = getColumnsFromSQL(\n meerkatReplacedSqlString,\n tableSchemaName\n );\n\n //Replace all the columnsUsedInMeasure with safeKey\n columnsUsedInMeasure?.forEach((measureKey) => {\n const column = measureKey.split('.')[1];\n const memberKey = `${tableSchemaName}.${column}`;\n const columnKey = memberKeyToSafeKey(memberKey);\n meerkatReplacedSqlString = meerkatReplacedSqlString.replace(\n memberKey,\n columnKey\n );\n });\n\n base += ` ${meerkatReplacedSqlString} AS ${aliasKey} `;\n }\n return base;\n};\n\nconst addDimensionToSQLProjection = (\n dimensions: Member[],\n selectString: string,\n tableSchema: TableSchema\n) => {\n if (dimensions.length === 0) {\n return selectString;\n }\n let newSelectString = selectString;\n for (let i = 0; i < dimensions.length; i++) {\n const dimension = dimensions[i];\n const dimensionKeyWithoutTable = dimension.split('.')[1];\n const dimensionSchema = tableSchema.dimensions.find(\n (m) => m.name === dimensionKeyWithoutTable\n );\n const aliasKey = memberKeyToSafeKey(dimension);\n\n if (!dimensionSchema) {\n continue;\n }\n if (i > 0) {\n newSelectString += ',';\n }\n // since alias key is expected to have been unfurled in the base query, we can just use it as is.\n newSelectString += ` ${aliasKey}`;\n }\n return newSelectString;\n};\n\nexport const getSelectReplacedSql = (sql: string, selectString: string) => {\n /*\n ** Replaces the select portion of a SQL string with the selectString passed.\n */\n const selectRegex = /SELECT\\s\\*/;\n const match = sql.match(selectRegex);\n if (!match) {\n return sql;\n }\n const selectIndex = match.index;\n if (selectIndex === undefined) {\n throw new Error('SELECT * not found in SQL string');\n }\n const selectLength = match[0].length;\n const beforeSelect = sql.substring(0, selectIndex);\n const afterSelect = sql.substring(selectIndex + selectLength);\n return `${beforeSelect}${selectString}${afterSelect}`;\n};\n\n/**\n * Get all the columns used in the measures.\n * This is used for extracting the columns used in the measures needed for the projection.\n * Example: The joins implementation uses this to get the columns used in the measures to join the tables.\n * like the SQL for the measure is `SUM(table.total)` and the table name is `table`, then the column used is `total`\n * table cannot be used directly here because the joined table would have column name ambiguity.\n * Thus these columns are projected and directly used in the join.\n */\nexport const getAllColumnUsedInMeasures = (\n measures: Measure[],\n tableSchema: TableSchema\n) => {\n let columns: string[] = [];\n measures.forEach((measure) => {\n const columnMatch = getColumnsFromSQL(measure.sql, tableSchema.name);\n if (columnMatch && columnMatch.length > 0) {\n columns = [...columns, ...columnMatch];\n }\n });\n // Remove duplicates\n return [...new Set(columns)];\n};\n\nconst getColumnsFromSQL = (sql: string, tableName: string) => {\n const regex = new RegExp(`(${tableName}\\\\.[a-zA-Z0-9_]+)`, 'g');\n const columnMatch = sql.match(regex);\n return columnMatch;\n};\n\n/**\n * Replace the first SELECT * from the sqlToReplace with the cube measure\n * @param measures\n * @param tableSchema\n * @param sqlToReplace\n * @returns\n */\nexport const applyProjectionToSQLQuery = (\n dimensions: Member[],\n measures: Member[],\n tableSchema: TableSchema,\n sqlToReplace: string\n) => {\n let measureSelectString = cubeMeasureToSQLSelectString(measures, tableSchema);\n\n if (measures.length > 0 && dimensions.length > 0) {\n measureSelectString += ', ';\n }\n const selectString = addDimensionToSQLProjection(\n dimensions,\n measureSelectString,\n tableSchema\n );\n\n return getSelectReplacedSql(sqlToReplace, selectString);\n};\n"],"names":["cubeMeasureToSQLSelectString","getSelectReplacedSql","getAllColumnUsedInMeasures","applyProjectionToSQLQuery","measures","tableSchema","base","i","length","measure","name","tableSchemaName","measureKeyWithoutTable","split","aliasKey","memberKeyToSafeKey","measureSchema","find","m","meerkatReplacedSqlString","meerkatPlaceholderReplacer","sql","columnsUsedInMeasure","getColumnsFromSQL","forEach","measureKey","column","memberKey","columnKey","replace","addDimensionToSQLProjection","dimensions","selectString","newSelectString","dimension","dimensionKeyWithoutTable","dimensionSchema","selectRegex","match","selectIndex","index","undefined","Error","selectLength","beforeSelect","substring","afterSelect","columns","columnMatch","Set","tableName","regex","RegExp","sqlToReplace","measureSelectString"],"mappings":";;;;;;;;IAKaA,4BAA4B;eAA5BA;;IAoFAC,oBAAoB;eAApBA;;IA2BAC,0BAA0B;eAA1BA;;IA4BAC,yBAAyB;eAAzBA;;;4CA9I8B;oCACR;AAE5B,MAAMH,+BAA+B,CAC1CI,UACAC;IAEA,IAAIC,OAAO;IACX,IAAK,IAAIC,IAAI,GAAGA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AAE;IAC3D,MAAMF,cAAc3B,IAAIiB,KAAK,CAACa;IAC9B,OAAOH;AACT;AASO,MAAM7C,4BAA4B,CACvC4B,YACA3B,UACAC,aACAgD;IAEA,IAAIC,sBAAsBtD,6BAA6BI,UAAUC;IAEjE,IAAID,SAASI,MAAM,GAAG,KAAKuB,WAAWvB,MAAM,GAAG,GAAG;QAChD8C,uBAAuB;IACzB;IACA,MAAMtB,eAAeF,4BACnBC,YACAuB,qBACAjD;IAGF,OAAOJ,qBAAqBoD,cAAcrB;AAC5C"}
@@ -0,0 +1,21 @@
1
+ import { ExpressionClass, ExpressionType } from '../types/duckdb-serialization-types/serialization/Expression';
2
+ import { OrderType } from '../types/duckdb-serialization-types/serialization/Nodes';
3
+ import { ResultModifierType } from '../types/duckdb-serialization-types/serialization/ResultModifier';
4
+ export declare const cubeOrderByToAST: (order: {
5
+ [key: string]: "asc" | "desc";
6
+ }) => {
7
+ type: ResultModifierType;
8
+ orders: {
9
+ type: OrderType;
10
+ null_order: OrderType;
11
+ expression: {
12
+ class: ExpressionClass;
13
+ type: ExpressionType;
14
+ alias: string;
15
+ /**
16
+ * We need to convert the key in the __ format as they are being projected in this format
17
+ */
18
+ column_names: string[];
19
+ };
20
+ }[];
21
+ };
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "cubeOrderByToAST", {
3
+ enumerable: true,
4
+ get: function() {
5
+ return cubeOrderByToAST;
6
+ }
7
+ });
8
+ const _Expression = require("../types/duckdb-serialization-types/serialization/Expression");
9
+ const _Nodes = require("../types/duckdb-serialization-types/serialization/Nodes");
10
+ const _ResultModifier = require("../types/duckdb-serialization-types/serialization/ResultModifier");
11
+ const _memberkeytosafekey = require("../utils/member-key-to-safe-key");
12
+ const cubeOrderByToAST = (order)=>{
13
+ const orderArr = [];
14
+ for(const key in order){
15
+ const value = order[key];
16
+ const astOrderBy = value === 'asc' ? _Nodes.OrderType.ASCENDING : _Nodes.OrderType.DESCENDING;
17
+ const orderByAST = {
18
+ type: astOrderBy,
19
+ null_order: _Nodes.OrderType.ORDER_DEFAULT,
20
+ expression: {
21
+ class: _Expression.ExpressionClass.COLUMN_REF,
22
+ type: _Expression.ExpressionType.COLUMN_REF,
23
+ alias: '',
24
+ /**
25
+ * We need to convert the key in the __ format as they are being projected in this format
26
+ */ column_names: [
27
+ (0, _memberkeytosafekey.memberKeyToSafeKey)(key)
28
+ ]
29
+ }
30
+ };
31
+ orderArr.push(orderByAST);
32
+ }
33
+ return {
34
+ type: _ResultModifier.ResultModifierType.ORDER_MODIFIER,
35
+ orders: orderArr
36
+ };
37
+ };
38
+
39
+ //# sourceMappingURL=cube-order-by-transformer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../meerkat-core/src/cube-order-by-transformer/cube-order-by-transformer.ts"],"sourcesContent":["import {\n ExpressionClass,\n ExpressionType,\n} from '../types/duckdb-serialization-types/serialization/Expression';\nimport { OrderType } from '../types/duckdb-serialization-types/serialization/Nodes';\nimport { ResultModifierType } from '../types/duckdb-serialization-types/serialization/ResultModifier';\nimport { memberKeyToSafeKey } from '../utils/member-key-to-safe-key';\n\nexport const cubeOrderByToAST = (order: { [key: string]: 'asc' | 'desc' }) => {\n const orderArr = [];\n for (const key in order) {\n const value = order[key];\n const astOrderBy =\n value === 'asc' ? OrderType.ASCENDING : OrderType.DESCENDING;\n const orderByAST = {\n type: astOrderBy,\n null_order: OrderType.ORDER_DEFAULT,\n expression: {\n class: ExpressionClass.COLUMN_REF,\n type: ExpressionType.COLUMN_REF,\n alias: '',\n /**\n * We need to convert the key in the __ format as they are being projected in this format\n */\n column_names: [memberKeyToSafeKey(key)],\n },\n };\n orderArr.push(orderByAST);\n }\n return {\n type: ResultModifierType.ORDER_MODIFIER,\n orders: orderArr,\n };\n};\n"],"names":["cubeOrderByToAST","order","orderArr","key","value","astOrderBy","OrderType","ASCENDING","DESCENDING","orderByAST","type","null_order","ORDER_DEFAULT","expression","class","ExpressionClass","COLUMN_REF","ExpressionType","alias","column_names","memberKeyToSafeKey","push","ResultModifierType","ORDER_MODIFIER","orders"],"mappings":";+BAQaA;;;eAAAA;;;4BALN;uBACmB;gCACS;oCACA;AAE5B,MAAMA,mBAAmB,CAACC;IAC/B,MAAMC,WAAW,EAAE;IACnB,IAAK,MAAMC,OAAOF,MAAO;QACvB,MAAMG,QAAQH,KAAK,CAACE,IAAI;QACxB,MAAME,aACJD,UAAU,QAAQE,gBAAS,CAACC,SAAS,GAAGD,gBAAS,CAACE,UAAU;QAC9D,MAAMC,aAAa;YACjBC,MAAML;YACNM,YAAYL,gBAAS,CAACM,aAAa;YACnCC,YAAY;gBACVC,OAAOC,2BAAe,CAACC,UAAU;gBACjCN,MAAMO,0BAAc,CAACD,UAAU;gBAC/BE,OAAO;gBACP;;SAEC,GACDC,cAAc;oBAACC,IAAAA,sCAAkB,EAACjB;iBAAK;YACzC;QACF;QACAD,SAASmB,IAAI,CAACZ;IAChB;IACA,OAAO;QACLC,MAAMY,kCAAkB,CAACC,cAAc;QACvCC,QAAQtB;IACV;AACF"}
@@ -0,0 +1,16 @@
1
+ import { QueryFilter } from '../types/cube-types/query';
2
+ import { Dimension, Measure } from '../types/cube-types/table';
3
+ export type QueryOperatorsWithInfo = QueryFilter & {
4
+ memberInfo: Measure | Dimension;
5
+ };
6
+ export type LogicalAndFilterWithInfo = {
7
+ and: (QueryOperatorsWithInfo | {
8
+ or: (QueryOperatorsWithInfo | LogicalAndFilterWithInfo)[];
9
+ })[];
10
+ };
11
+ export type LogicalOrFilterWithInfo = {
12
+ or: (QueryOperatorsWithInfo | LogicalAndFilterWithInfo)[];
13
+ };
14
+ export type QueryFilterWithInfo = (QueryOperatorsWithInfo | LogicalAndFilterWithInfo | LogicalOrFilterWithInfo) | (QueryOperatorsWithInfo | LogicalAndFilterWithInfo | LogicalOrFilterWithInfo)[];
15
+ export type QueryFiltersWithInfoSingular = QueryOperatorsWithInfo | LogicalAndFilterWithInfo | LogicalOrFilterWithInfo;
16
+ export type QueryFiltersWithInfo = QueryFiltersWithInfoSingular[];
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+
3
+ //# sourceMappingURL=cube-filter-to-duckdb.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../meerkat-core/src/cube-to-duckdb/cube-filter-to-duckdb.ts"],"names":[],"mappings":""}
@@ -0,0 +1,33 @@
1
+ import { FilterType, MeerkatQueryFilter, Query, QueryFilter, TableSchema } from '../types/cube-types';
2
+ import { SelectStatement } from '../types/duckdb-serialization-types/serialization/Statement';
3
+ /**
4
+ * Get the query filter with only where filterKey matches
5
+ */
6
+ export declare const traverseAndFilter: (filter: MeerkatQueryFilter, callback: (value: QueryFilter) => boolean) => MeerkatQueryFilter | null;
7
+ export declare const getFilterByMemberKey: (filters: MeerkatQueryFilter[] | undefined, memberKey: string) => MeerkatQueryFilter[];
8
+ /**
9
+ * Syntax for filter params in SQL:
10
+ * FILTER_PARAMS.cube_name.member_name.filter(sql_expression)
11
+ * Example:
12
+ * SELECT *
13
+ * FROM orders
14
+ * WHERE ${FILTER_PARAMS.order_facts.date.filter('date')}
15
+ * @param sql
16
+ */
17
+ export declare const detectAllFilterParamsFromSQL: (sql: string) => {
18
+ memberKey: string;
19
+ filterExpression: string;
20
+ matchKey: string;
21
+ }[];
22
+ export declare const getFilterParamsAST: (query: Query, tableSchema: TableSchema, filterType?: FilterType) => {
23
+ memberKey: string;
24
+ ast: SelectStatement | null;
25
+ matchKey: string;
26
+ }[];
27
+ type FilterParamsSQL = {
28
+ memberKey: string;
29
+ sql: string;
30
+ matchKey: string;
31
+ };
32
+ export declare const applyFilterParamsToBaseSQL: (baseSQL: string, filterParamsSQL: FilterParamsSQL[]) => string;
33
+ export {};
@@ -0,0 +1,115 @@
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
+ traverseAndFilter: function() {
10
+ return traverseAndFilter;
11
+ },
12
+ getFilterByMemberKey: function() {
13
+ return getFilterByMemberKey;
14
+ },
15
+ detectAllFilterParamsFromSQL: function() {
16
+ return detectAllFilterParamsFromSQL;
17
+ },
18
+ getFilterParamsAST: function() {
19
+ return getFilterParamsAST;
20
+ },
21
+ applyFilterParamsToBaseSQL: function() {
22
+ return applyFilterParamsToBaseSQL;
23
+ }
24
+ });
25
+ const _astbuilder = require("../ast-builder/ast-builder");
26
+ const traverseAndFilter = (filter, callback)=>{
27
+ if ('member' in filter) {
28
+ return callback(filter) ? filter : null;
29
+ }
30
+ if ('and' in filter) {
31
+ const filteredAndFilters = filter.and.map((subFilter)=>traverseAndFilter(subFilter, callback)).filter(Boolean);
32
+ const obj = filteredAndFilters.length > 0 ? {
33
+ and: filteredAndFilters
34
+ } : null;
35
+ return obj;
36
+ }
37
+ if ('or' in filter) {
38
+ const filteredOrFilters = filter.or.map((subFilter)=>traverseAndFilter(subFilter, callback)).filter(Boolean);
39
+ const obj = filteredOrFilters.length > 0 ? {
40
+ or: filteredOrFilters
41
+ } : null;
42
+ return obj;
43
+ }
44
+ return null;
45
+ };
46
+ const getFilterByMemberKey = (filters, memberKey)=>{
47
+ if (!filters) return [];
48
+ return filters.map((filter)=>traverseAndFilter(filter, (value)=>value.member === memberKey)).filter(Boolean);
49
+ };
50
+ const detectAllFilterParamsFromSQL = (sql)=>{
51
+ const regex = /\${FILTER_PARAMS\.(\w+\.\w+)\.filter\('(\w+)'\)}/g;
52
+ const matches = [];
53
+ let match;
54
+ while((match = regex.exec(sql)) !== null){
55
+ matches.push({
56
+ memberKey: match[1],
57
+ filterExpression: match[2],
58
+ matchKey: match[0]
59
+ });
60
+ }
61
+ return matches;
62
+ };
63
+ const getFilterParamsAST = (query, tableSchema, filterType = 'PROJECTION_FILTER')=>{
64
+ const filterParamKeys = detectAllFilterParamsFromSQL(tableSchema.sql);
65
+ const filterParamsAST = [];
66
+ for (const filterParamKey of filterParamKeys){
67
+ const filters = getFilterByMemberKey(query.filters, filterParamKey.memberKey);
68
+ if (filters && filters.length > 0) {
69
+ filterParamsAST.push({
70
+ memberKey: filterParamKey.memberKey,
71
+ matchKey: filterParamKey.matchKey,
72
+ ast: (0, _astbuilder.cubeToDuckdbAST)({
73
+ filters,
74
+ measures: [],
75
+ dimensions: []
76
+ }, tableSchema, {
77
+ filterType
78
+ })
79
+ });
80
+ }
81
+ }
82
+ return filterParamsAST;
83
+ };
84
+ const replaceWhereClauseWithFiltersParamsSQL = (baseSQL, filterParamsSQL)=>{
85
+ let finalSQL = baseSQL;
86
+ for (const filterParam of filterParamsSQL){
87
+ /**
88
+ * Get SQL expression after WHERE clause
89
+ */ const whereClause = filterParam.sql.split('WHERE')[1];
90
+ /**
91
+ * Replace filter param with SQL expression
92
+ */ finalSQL = finalSQL.replace(filterParam.matchKey, whereClause);
93
+ }
94
+ return finalSQL;
95
+ };
96
+ const applyFilterParamsToBaseSQL = (baseSQL, filterParamsSQL)=>{
97
+ let finalSQL = replaceWhereClauseWithFiltersParamsSQL(baseSQL, filterParamsSQL);
98
+ for (const filterParam of filterParamsSQL){
99
+ /**
100
+ * Get SQL expression after WHERE clause
101
+ */ const whereClause = filterParam.sql.split('WHERE')[1];
102
+ /**
103
+ * Replace filter param with SQL expression
104
+ */ finalSQL = finalSQL.replace(filterParam.matchKey, whereClause);
105
+ }
106
+ /**
107
+ * Find all remaining filter params and replace them with TRUE
108
+ */ const remainingFilterParams = detectAllFilterParamsFromSQL(finalSQL);
109
+ for (const filterParam of remainingFilterParams){
110
+ finalSQL = finalSQL.replace(filterParam.matchKey, 'TRUE');
111
+ }
112
+ return finalSQL;
113
+ };
114
+
115
+ //# sourceMappingURL=filter-params-ast.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../meerkat-core/src/filter-params/filter-params-ast.ts"],"sourcesContent":["import { cubeToDuckdbAST } from '../ast-builder/ast-builder';\nimport {\n FilterType,\n LogicalAndFilter,\n LogicalOrFilter,\n MeerkatQueryFilter,\n Query,\n QueryFilter,\n TableSchema\n} from '../types/cube-types';\nimport { SelectStatement } from '../types/duckdb-serialization-types/serialization/Statement';\n\n/**\n * Get the query filter with only where filterKey matches\n */\n\nexport const traverseAndFilter = (\n filter: MeerkatQueryFilter,\n callback: (value: QueryFilter) => boolean\n): MeerkatQueryFilter | null => {\n if ('member' in filter) {\n return callback(filter) ? filter : null;\n }\n\n if ('and' in filter) {\n const filteredAndFilters = filter.and\n .map((subFilter) => traverseAndFilter(subFilter, callback))\n .filter(Boolean) as MeerkatQueryFilter[];\n const obj =\n filteredAndFilters.length > 0 ? { and: filteredAndFilters } : null;\n return obj as LogicalAndFilter;\n }\n\n if ('or' in filter) {\n const filteredOrFilters = filter.or\n .map((subFilter) => traverseAndFilter(subFilter, callback))\n .filter(Boolean);\n const obj = filteredOrFilters.length > 0 ? { or: filteredOrFilters } : null;\n return obj as LogicalOrFilter;\n }\n\n return null;\n};\n\n\nexport const getFilterByMemberKey = (\n filters: MeerkatQueryFilter[] | undefined,\n memberKey: string\n): MeerkatQueryFilter[] => {\n if (!filters) return [];\n return filters\n .map((filter) => traverseAndFilter(filter, (value) => value.member === memberKey))\n .filter(Boolean) as MeerkatQueryFilter[];\n};\n\n/**\n * Syntax for filter params in SQL:\n * FILTER_PARAMS.cube_name.member_name.filter(sql_expression)\n * Example:\n * SELECT *\n * FROM orders\n * WHERE ${FILTER_PARAMS.order_facts.date.filter('date')}\n * @param sql\n */\nexport const detectAllFilterParamsFromSQL = (\n sql: string\n): {\n memberKey: string;\n filterExpression: string;\n matchKey: string;\n}[] => {\n const regex = /\\${FILTER_PARAMS\\.(\\w+\\.\\w+)\\.filter\\('(\\w+)'\\)}/g;\n const matches = [];\n let match;\n while ((match = regex.exec(sql)) !== null) {\n matches.push({\n memberKey: match[1],\n filterExpression: match[2],\n matchKey: match[0],\n });\n }\n return matches;\n};\n\n\n\nexport const getFilterParamsAST = (\n query: Query,\n tableSchema: TableSchema,\n filterType: FilterType = 'PROJECTION_FILTER'\n): {\n memberKey: string;\n ast: SelectStatement | null;\n matchKey: string;\n}[] => {\n const filterParamKeys = detectAllFilterParamsFromSQL(tableSchema.sql);\n const filterParamsAST = [];\n \n for (const filterParamKey of filterParamKeys) {\n const filters = getFilterByMemberKey(\n query.filters,\n filterParamKey.memberKey\n );\n \n if (filters && filters.length > 0) {\n filterParamsAST.push({\n memberKey: filterParamKey.memberKey,\n matchKey: filterParamKey.matchKey,\n ast: cubeToDuckdbAST(\n { filters, measures: [], dimensions: [] },\n tableSchema,\n {\n filterType\n }\n ),\n });\n }\n }\n\n return filterParamsAST;\n};\n\ntype FilterParamsSQL = {\n memberKey: string;\n sql: string;\n matchKey: string;\n}\n\nconst replaceWhereClauseWithFiltersParamsSQL = (baseSQL: string, filterParamsSQL: FilterParamsSQL[]) => {\n let finalSQL = baseSQL;\n\n for (const filterParam of filterParamsSQL) {\n /**\n * Get SQL expression after WHERE clause\n */\n const whereClause = filterParam.sql.split('WHERE')[1];\n /**\n * Replace filter param with SQL expression\n */\n finalSQL = finalSQL.replace(filterParam.matchKey, whereClause);\n }\n return finalSQL\n}\n\nexport const applyFilterParamsToBaseSQL = (\n baseSQL: string,\n filterParamsSQL: FilterParamsSQL[]\n) => {\n let finalSQL = replaceWhereClauseWithFiltersParamsSQL(baseSQL, filterParamsSQL);\n for (const filterParam of filterParamsSQL) {\n /**\n * Get SQL expression after WHERE clause\n */\n const whereClause = filterParam.sql.split('WHERE')[1];\n /**\n * Replace filter param with SQL expression\n */\n finalSQL = finalSQL.replace(filterParam.matchKey, whereClause);\n }\n /**\n * Find all remaining filter params and replace them with TRUE\n */\n const remainingFilterParams = detectAllFilterParamsFromSQL(finalSQL);\n\n for (const filterParam of remainingFilterParams) {\n finalSQL = finalSQL.replace(filterParam.matchKey, 'TRUE');\n }\n return finalSQL;\n};\n"],"names":["traverseAndFilter","getFilterByMemberKey","detectAllFilterParamsFromSQL","getFilterParamsAST","applyFilterParamsToBaseSQL","filter","callback","filteredAndFilters","and","map","subFilter","Boolean","obj","length","filteredOrFilters","or","filters","memberKey","value","member","sql","regex","matches","match","exec","push","filterExpression","matchKey","query","tableSchema","filterType","filterParamKeys","filterParamsAST","filterParamKey","ast","cubeToDuckdbAST","measures","dimensions","replaceWhereClauseWithFiltersParamsSQL","baseSQL","filterParamsSQL","finalSQL","filterParam","whereClause","split","replace","remainingFilterParams"],"mappings":";;;;;;;;IAgBaA,iBAAiB;eAAjBA;;IA6BAC,oBAAoB;eAApBA;;IAmBAC,4BAA4B;eAA5BA;;IAsBAC,kBAAkB;eAAlBA;;IA0DAC,0BAA0B;eAA1BA;;;4BAhJmB;AAgBzB,MAAMJ,oBAAoB,CAC/BK,QACAC;IAEA,IAAI,YAAYD,QAAQ;QACtB,OAAOC,SAASD,UAAUA,SAAS;IACrC;IAEA,IAAI,SAASA,QAAQ;QACnB,MAAME,qBAAqBF,OAAOG,GAAG,CAClCC,GAAG,CAAC,CAACC,YAAcV,kBAAkBU,WAAWJ,WAChDD,MAAM,CAACM;QACV,MAAMC,MACJL,mBAAmBM,MAAM,GAAG,IAAI;YAAEL,KAAKD;QAAmB,IAAI;QAChE,OAAOK;IACT;IAEA,IAAI,QAAQP,QAAQ;QAClB,MAAMS,oBAAoBT,OAAOU,EAAE,CAChCN,GAAG,CAAC,CAACC,YAAcV,kBAAkBU,WAAWJ,WAChDD,MAAM,CAACM;QACV,MAAMC,MAAME,kBAAkBD,MAAM,GAAG,IAAI;YAAEE,IAAID;QAAkB,IAAI;QACvE,OAAOF;IACT;IAEA,OAAO;AACT;AAGO,MAAMX,uBAAuB,CAClCe,SACAC;IAEA,IAAI,CAACD,SAAS,OAAO,EAAE;IACvB,OAAOA,QACJP,GAAG,CAAC,CAACJ,SAAWL,kBAAkBK,QAAQ,CAACa,QAAWA,MAAMC,MAAM,KAAKF,YACvEZ,MAAM,CAACM;AACZ;AAWO,MAAMT,+BAA+B,CAC1CkB;IAMA,MAAMC,QAAQ;IACd,MAAMC,UAAU,EAAE;IAClB,I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AEC,GACDH,WAAWA,SAASI,OAAO,CAACH,YAAYf,QAAQ,EAAEgB;IACpD;IACA;;GAEC,GACD,MAAMG,wBAAwB5C,6BAA6BuC;IAE3D,KAAK,MAAMC,eAAeI,sBAAuB;QAC/CL,WAAWA,SAASI,OAAO,CAACH,YAAYf,QAAQ,EAAE;IACpD;IACA,OAAOc;AACT"}
@@ -0,0 +1,27 @@
1
+ import { TableSchema } from '../types/cube-types';
2
+ export declare const getFilterMeasureProjection: ({ key, tableSchema, measures, }: {
3
+ key: string;
4
+ tableSchema: TableSchema;
5
+ measures: string[];
6
+ }) => {
7
+ sql: undefined;
8
+ foundMember: undefined;
9
+ aliasKey: undefined;
10
+ } | {
11
+ sql: string;
12
+ foundMember: import("../types/cube-types").Measure;
13
+ aliasKey: string;
14
+ };
15
+ export declare const getDimensionProjection: ({ key, tableSchema, }: {
16
+ key: string;
17
+ tableSchema: TableSchema;
18
+ }) => {
19
+ sql: undefined;
20
+ foundMember: undefined;
21
+ aliasKey: undefined;
22
+ } | {
23
+ sql: string;
24
+ foundMember: import("../types/cube-types").Dimension;
25
+ aliasKey: string;
26
+ };
27
+ export declare const getProjectionClause: (measures: string[], dimensions: string[], tableSchema: TableSchema, aliasedColumnSet: Set<string>) => string;
@@ -0,0 +1,135 @@
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
+ getFilterMeasureProjection: function() {
10
+ return getFilterMeasureProjection;
11
+ },
12
+ getDimensionProjection: function() {
13
+ return getDimensionProjection;
14
+ },
15
+ getProjectionClause: function() {
16
+ return getProjectionClause;
17
+ }
18
+ });
19
+ const _cubemeasuretransformer = require("../cube-measure-transformer/cube-measure-transformer");
20
+ const _findintableschema = require("../utils/find-in-table-schema");
21
+ const _memberkeytosafekey = require("../utils/member-key-to-safe-key");
22
+ const getFilterMeasureProjection = ({ key, tableSchema, measures })=>{
23
+ const tableName = key.split('.')[0];
24
+ const measureWithoutTable = key.split('.')[1];
25
+ const foundMember = (0, _findintableschema.findInMeasureSchema)(measureWithoutTable, tableSchema);
26
+ const isMeasure = measures.includes(key);
27
+ if (!foundMember || isMeasure || tableName !== tableSchema.name) {
28
+ // If the selected member is not found in the table schema or if it is already selected, continue.
29
+ // If the selected member is a measure, don't create an alias. Since measure computation is done in the outermost level of the query
30
+ // If the selected member is not from the current table, don't create an alias.
31
+ return {
32
+ sql: undefined,
33
+ foundMember: undefined,
34
+ aliasKey: undefined
35
+ };
36
+ }
37
+ const aliasKey = (0, _memberkeytosafekey.memberKeyToSafeKey)(key);
38
+ return {
39
+ sql: `${key} AS ${aliasKey}`,
40
+ foundMember,
41
+ aliasKey
42
+ };
43
+ };
44
+ const getDimensionProjection = ({ key, tableSchema })=>{
45
+ // Find the table access key
46
+ const measureWithoutTable = key.split('.')[1];
47
+ const tableName = key.split('.')[0];
48
+ const foundMember = (0, _findintableschema.findInDimensionSchema)(measureWithoutTable, tableSchema);
49
+ if (!foundMember || tableName !== tableSchema.name) {
50
+ // If the selected member is not found in the table schema or if it is already selected, continue.
51
+ // If the selected member is not from the current table, don't create an alias.
52
+ return {
53
+ sql: undefined,
54
+ foundMember: undefined,
55
+ aliasKey: undefined
56
+ };
57
+ }
58
+ const aliasKey = (0, _memberkeytosafekey.memberKeyToSafeKey)(key);
59
+ // Add the alias key to the set. So we have a reference to all the previously selected members.
60
+ return {
61
+ sql: `${foundMember.sql} AS ${aliasKey}`,
62
+ foundMember,
63
+ aliasKey
64
+ };
65
+ };
66
+ const aggregator = ({ member, aliasedColumnSet, acc, sql })=>{
67
+ if (aliasedColumnSet.has(member) || !sql) {
68
+ return acc;
69
+ }
70
+ aliasedColumnSet.add(member);
71
+ acc.push(sql);
72
+ return acc;
73
+ };
74
+ const getProjectionClause = (measures, dimensions, tableSchema, aliasedColumnSet)=>{
75
+ const filteredDimensions = dimensions.filter((dimension)=>{
76
+ return dimension.split('.')[0] === tableSchema.name;
77
+ });
78
+ const filteredMeasures = measures.filter((measure)=>{
79
+ return measure.split('.')[0] === tableSchema.name;
80
+ });
81
+ const dimensionsProjectionsArr = filteredDimensions.reduce((acc, member, currentIndex, members)=>{
82
+ const { sql: memberSql } = getDimensionProjection({
83
+ key: member,
84
+ tableSchema
85
+ });
86
+ return aggregator({
87
+ member,
88
+ aliasedColumnSet,
89
+ acc,
90
+ currentIndex,
91
+ members,
92
+ sql: memberSql
93
+ });
94
+ }, []);
95
+ const dimensionsProjections = dimensionsProjectionsArr.join(', ');
96
+ const measureProjectionsArr = filteredMeasures.reduce((acc, member, currentIndex, members)=>{
97
+ const { sql: memberSql } = getFilterMeasureProjection({
98
+ key: member,
99
+ tableSchema,
100
+ measures
101
+ });
102
+ return aggregator({
103
+ member,
104
+ aliasedColumnSet,
105
+ acc,
106
+ currentIndex,
107
+ members,
108
+ sql: memberSql
109
+ });
110
+ }, []);
111
+ const measureProjections = measureProjectionsArr.join(', ');
112
+ const usedMeasureObjects = tableSchema.measures.filter((measure)=>{
113
+ return measures.findIndex((key)=>{
114
+ const keyWithoutTable = key.split('.')[1];
115
+ return keyWithoutTable === measure.name;
116
+ }) !== -1;
117
+ });
118
+ const columnsUsedInMeasures = (0, _cubemeasuretransformer.getAllColumnUsedInMeasures)(usedMeasureObjects, tableSchema);
119
+ let columnsUsedInMeasuresInProjection = '';
120
+ columnsUsedInMeasures.forEach((column, index)=>{
121
+ const safeKey = (0, _memberkeytosafekey.memberKeyToSafeKey)(column);
122
+ columnsUsedInMeasuresInProjection += `${column} AS ${safeKey}`;
123
+ if (index !== columnsUsedInMeasures.length - 1) {
124
+ columnsUsedInMeasuresInProjection += ', ';
125
+ }
126
+ });
127
+ const combinedStr = [
128
+ dimensionsProjections,
129
+ measureProjections,
130
+ columnsUsedInMeasuresInProjection
131
+ ];
132
+ return combinedStr.filter((str)=>str.length > 0).join(', ');
133
+ };
134
+
135
+ //# sourceMappingURL=get-projection-clause.js.map