@devrev/meerkat-core 0.0.97 → 0.0.99

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 (370) hide show
  1. package/package.json +2 -2
  2. package/src/ast-builder/ast-builder.js +97 -0
  3. package/src/ast-builder/ast-builder.js.map +1 -0
  4. package/src/ast-deserializer/ast-deserializer.js +17 -0
  5. package/src/ast-deserializer/ast-deserializer.js.map +1 -0
  6. package/src/ast-serializer/ast-serializer.js +8 -0
  7. package/src/ast-serializer/ast-serializer.js.map +1 -0
  8. package/src/ast-validator/dimension-validator.js +49 -0
  9. package/src/ast-validator/dimension-validator.js.map +1 -0
  10. package/src/ast-validator/index.js +12 -0
  11. package/src/ast-validator/index.js.map +1 -0
  12. package/src/ast-validator/measure-validator.js +155 -0
  13. package/src/ast-validator/measure-validator.js.map +1 -0
  14. package/{ast-validator → src/ast-validator}/tests/test-data.js +692 -890
  15. package/src/ast-validator/tests/test-data.js.map +1 -0
  16. package/src/ast-validator/types.js +3 -0
  17. package/src/ast-validator/types.js.map +1 -0
  18. package/src/ast-validator/utils.js +24 -0
  19. package/src/ast-validator/utils.js.map +1 -0
  20. package/src/context-params/context-params-ast.js +42 -0
  21. package/src/context-params/context-params-ast.js.map +1 -0
  22. package/src/cube-filter-transformer/and/and.js +14 -0
  23. package/src/cube-filter-transformer/and/and.js.map +1 -0
  24. package/src/cube-filter-transformer/base-condition-builder/base-condition-builder.js +145 -0
  25. package/src/cube-filter-transformer/base-condition-builder/base-condition-builder.js.map +1 -0
  26. package/src/cube-filter-transformer/contains/contains.js +62 -0
  27. package/src/cube-filter-transformer/contains/contains.js.map +1 -0
  28. package/src/cube-filter-transformer/equals/equals-array.js +71 -0
  29. package/src/cube-filter-transformer/equals/equals-array.js.map +1 -0
  30. package/src/cube-filter-transformer/equals/equals.js +36 -0
  31. package/src/cube-filter-transformer/equals/equals.js.map +1 -0
  32. package/src/cube-filter-transformer/factory.js +120 -0
  33. package/src/cube-filter-transformer/factory.js.map +1 -0
  34. package/src/cube-filter-transformer/gt/gt.js +28 -0
  35. package/src/cube-filter-transformer/gt/gt.js.map +1 -0
  36. package/src/cube-filter-transformer/gte/gte.js +28 -0
  37. package/src/cube-filter-transformer/gte/gte.js.map +1 -0
  38. package/src/cube-filter-transformer/in/in.js +69 -0
  39. package/src/cube-filter-transformer/in/in.js.map +1 -0
  40. package/src/cube-filter-transformer/in-date-range/in-date-range.js +21 -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.js +28 -0
  43. package/src/cube-filter-transformer/lt/lt.js.map +1 -0
  44. package/src/cube-filter-transformer/lte/lte.js +28 -0
  45. package/src/cube-filter-transformer/lte/lte.js.map +1 -0
  46. package/src/cube-filter-transformer/not/not.js +14 -0
  47. package/src/cube-filter-transformer/not/not.js.map +1 -0
  48. package/src/cube-filter-transformer/not-In-date-range/not-In-date-range.js +21 -0
  49. package/src/cube-filter-transformer/not-In-date-range/not-In-date-range.js.map +1 -0
  50. package/src/cube-filter-transformer/not-contains/not-contains.js +62 -0
  51. package/src/cube-filter-transformer/not-contains/not-contains.js.map +1 -0
  52. package/src/cube-filter-transformer/not-equals/not-equals-array.js +21 -0
  53. package/src/cube-filter-transformer/not-equals/not-equals-array.js.map +1 -0
  54. package/src/cube-filter-transformer/not-equals/not-equals.js +36 -0
  55. package/src/cube-filter-transformer/not-equals/not-equals.js.map +1 -0
  56. package/src/cube-filter-transformer/not-in/not-in.js +76 -0
  57. package/src/cube-filter-transformer/not-in/not-in.js.map +1 -0
  58. package/src/cube-filter-transformer/not-set/not-set.js +23 -0
  59. package/src/cube-filter-transformer/not-set/not-set.js.map +1 -0
  60. package/src/cube-filter-transformer/or/or.js +14 -0
  61. package/src/cube-filter-transformer/or/or.js.map +1 -0
  62. package/src/cube-filter-transformer/set/set.js +23 -0
  63. package/src/cube-filter-transformer/set/set.js.map +1 -0
  64. package/src/cube-group-by-transformer/cube-group-by-transformer.d.ts +2 -1
  65. package/src/cube-group-by-transformer/cube-group-by-transformer.js +25 -0
  66. package/src/cube-group-by-transformer/cube-group-by-transformer.js.map +1 -0
  67. package/src/cube-limit-offset-transformer/cube-limit-offset-transformer.js +42 -0
  68. package/src/cube-limit-offset-transformer/cube-limit-offset-transformer.js.map +1 -0
  69. package/src/cube-measure-transformer/cube-measure-transformer.js +142 -0
  70. package/src/cube-measure-transformer/cube-measure-transformer.js.map +1 -0
  71. package/src/cube-order-by-transformer/cube-order-by-transformer.d.ts +2 -1
  72. package/src/cube-order-by-transformer/cube-order-by-transformer.js +40 -0
  73. package/src/cube-order-by-transformer/cube-order-by-transformer.js.map +1 -0
  74. package/src/cube-to-duckdb/cube-filter-to-duckdb.js +3 -0
  75. package/src/cube-to-duckdb/cube-filter-to-duckdb.js.map +1 -0
  76. package/src/filter-params/filter-params-ast.js +114 -0
  77. package/src/filter-params/filter-params-ast.js.map +1 -0
  78. package/src/get-filter-params-sql/get-filter-params-sql.js +25 -0
  79. package/src/get-filter-params-sql/get-filter-params-sql.js.map +1 -0
  80. package/src/get-final-base-sql/get-final-base-sql.js +28 -0
  81. package/src/get-final-base-sql/get-final-base-sql.js.map +1 -0
  82. package/{get-wrapped-base-query-with-projections → src/get-wrapped-base-query-with-projections}/get-aliased-columns-from-filters.js +48 -61
  83. package/src/get-wrapped-base-query-with-projections/get-aliased-columns-from-filters.js.map +1 -0
  84. package/src/get-wrapped-base-query-with-projections/get-projection-clause.js +91 -0
  85. package/src/get-wrapped-base-query-with-projections/get-projection-clause.js.map +1 -0
  86. package/src/get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections.js +32 -0
  87. package/src/get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections.js.map +1 -0
  88. package/src/get-wrapped-base-query-with-projections/sql-expression-modifiers.js +32 -0
  89. package/src/get-wrapped-base-query-with-projections/sql-expression-modifiers.js.map +1 -0
  90. package/src/index.js +37 -0
  91. package/src/index.js.map +1 -0
  92. package/src/joins/joins.js +162 -0
  93. package/src/joins/joins.js.map +1 -0
  94. package/src/member-formatters/constants.js +6 -0
  95. package/src/member-formatters/constants.js.map +1 -0
  96. package/src/member-formatters/get-alias.d.ts +15 -0
  97. package/src/member-formatters/get-alias.js +42 -0
  98. package/src/member-formatters/get-alias.js.map +1 -0
  99. package/src/member-formatters/get-namespaced-key.d.ts +1 -0
  100. package/src/member-formatters/get-namespaced-key.js +6 -0
  101. package/src/member-formatters/get-namespaced-key.js.map +1 -0
  102. package/src/member-formatters/index.d.ts +2 -0
  103. package/src/member-formatters/index.js +15 -0
  104. package/src/member-formatters/index.js.map +1 -0
  105. package/src/member-formatters/member-key-to-safe-key.js +9 -0
  106. package/src/member-formatters/member-key-to-safe-key.js.map +1 -0
  107. package/src/member-formatters/split-into-data-source-and-fields.js +10 -0
  108. package/src/member-formatters/split-into-data-source-and-fields.js.map +1 -0
  109. package/src/resolution/resolution.d.ts +4 -3
  110. package/src/resolution/resolution.js +141 -0
  111. package/src/resolution/resolution.js.map +1 -0
  112. package/src/resolution/types.js +5 -0
  113. package/src/resolution/types.js.map +1 -0
  114. package/src/types/cube-types/index.js +6 -0
  115. package/src/types/cube-types/index.js.map +1 -0
  116. package/src/types/cube-types/query.js +8 -0
  117. package/src/types/cube-types/query.js.map +1 -0
  118. package/src/types/cube-types/table.d.ts +2 -0
  119. package/src/types/cube-types/table.js +3 -0
  120. package/src/types/cube-types/table.js.map +1 -0
  121. package/src/types/duckdb-serialization-types/index.js +11 -0
  122. package/src/types/duckdb-serialization-types/index.js.map +1 -0
  123. package/{types → src/types}/duckdb-serialization-types/serialization/Constraint.js +6 -19
  124. package/src/types/duckdb-serialization-types/serialization/Constraint.js.map +1 -0
  125. package/{types → src/types}/duckdb-serialization-types/serialization/CreateInfo.js +10 -29
  126. package/src/types/duckdb-serialization-types/serialization/CreateInfo.js.map +1 -0
  127. package/{types → src/types}/duckdb-serialization-types/serialization/Expression.js +6 -19
  128. package/src/types/duckdb-serialization-types/serialization/Expression.js.map +1 -0
  129. package/src/types/duckdb-serialization-types/serialization/LogicalOperator.js +28 -0
  130. package/src/types/duckdb-serialization-types/serialization/LogicalOperator.js.map +1 -0
  131. package/src/types/duckdb-serialization-types/serialization/MacroFunction.js +10 -0
  132. package/src/types/duckdb-serialization-types/serialization/MacroFunction.js.map +1 -0
  133. package/src/types/duckdb-serialization-types/serialization/Misc.js +3 -0
  134. package/src/types/duckdb-serialization-types/serialization/Misc.js.map +1 -0
  135. package/{types → src/types}/duckdb-serialization-types/serialization/Nodes.js +17 -45
  136. package/src/types/duckdb-serialization-types/serialization/Nodes.js.map +1 -0
  137. package/{types → src/types}/duckdb-serialization-types/serialization/ParseInfo.js +20 -54
  138. package/src/types/duckdb-serialization-types/serialization/ParseInfo.js.map +1 -0
  139. package/{types → src/types}/duckdb-serialization-types/serialization/ParsedExpression.js +6 -19
  140. package/src/types/duckdb-serialization-types/serialization/ParsedExpression.js.map +1 -0
  141. package/{types → src/types}/duckdb-serialization-types/serialization/QueryNode.js +8 -24
  142. package/src/types/duckdb-serialization-types/serialization/QueryNode.js.map +1 -0
  143. package/{types → src/types}/duckdb-serialization-types/serialization/ResultModifier.js +4 -9
  144. package/src/types/duckdb-serialization-types/serialization/ResultModifier.js.map +1 -0
  145. package/src/types/duckdb-serialization-types/serialization/Statement.js +3 -0
  146. package/src/types/duckdb-serialization-types/serialization/Statement.js.map +1 -0
  147. package/{types → src/types}/duckdb-serialization-types/serialization/TableFilter.js +4 -9
  148. package/src/types/duckdb-serialization-types/serialization/TableFilter.js.map +1 -0
  149. package/{types → src/types}/duckdb-serialization-types/serialization/TableRef.js +8 -24
  150. package/src/types/duckdb-serialization-types/serialization/TableRef.js.map +1 -0
  151. package/{types → src/types}/duckdb-serialization-types/serialization/Types.js +4 -9
  152. package/src/types/duckdb-serialization-types/serialization/Types.js.map +1 -0
  153. package/src/types/duckdb-serialization-types/serialization/example.js +109 -0
  154. package/src/types/duckdb-serialization-types/serialization/example.js.map +1 -0
  155. package/src/types/utils.js +69 -0
  156. package/src/types/utils.js.map +1 -0
  157. package/{utils → src/utils}/__fixtures__/joins.fixtures.js +228 -316
  158. package/src/utils/__fixtures__/joins.fixtures.js.map +1 -0
  159. package/src/utils/base-ast.js +49 -0
  160. package/src/utils/base-ast.js.map +1 -0
  161. package/src/utils/cube-filter-enrichment.js +53 -0
  162. package/src/utils/cube-filter-enrichment.js.map +1 -0
  163. package/{utils → src/utils}/cube-to-table-schema.js +25 -38
  164. package/src/utils/cube-to-table-schema.js.map +1 -0
  165. package/src/utils/cube-type-to-duckdb-type.js +12 -0
  166. package/src/utils/cube-type-to-duckdb-type.js.map +1 -0
  167. package/src/utils/find-in-table-schema.d.ts +3 -1
  168. package/src/utils/find-in-table-schema.js +55 -0
  169. package/src/utils/find-in-table-schema.js.map +1 -0
  170. package/src/utils/get-column-names-from-ast.js +45 -0
  171. package/src/utils/get-column-names-from-ast.js.map +1 -0
  172. package/src/utils/get-possible-nodes.js +146 -0
  173. package/src/utils/get-possible-nodes.js.map +1 -0
  174. package/src/utils/get-type-info.js +34 -0
  175. package/src/utils/get-type-info.js.map +1 -0
  176. package/src/utils/is-array-member-type.js +8 -0
  177. package/src/utils/is-array-member-type.js.map +1 -0
  178. package/src/utils/key-from-measures-dimension.js +32 -0
  179. package/src/utils/key-from-measures-dimension.js.map +1 -0
  180. package/src/utils/meerkat-placeholder-replacer.js +10 -0
  181. package/src/utils/meerkat-placeholder-replacer.js.map +1 -0
  182. package/src/utils/modify-meerkat-filter.d.ts +2 -3
  183. package/src/utils/modify-meerkat-filter.js +24 -0
  184. package/src/utils/modify-meerkat-filter.js.map +1 -0
  185. package/{utils → src/utils}/type-guards.js +10 -28
  186. package/src/utils/type-guards.js.map +1 -0
  187. package/ast-builder/ast-builder.js +0 -90
  188. package/ast-builder/ast-builder.js.map +0 -1
  189. package/ast-deserializer/ast-deserializer.js +0 -30
  190. package/ast-deserializer/ast-deserializer.js.map +0 -1
  191. package/ast-serializer/ast-serializer.js +0 -12
  192. package/ast-serializer/ast-serializer.js.map +0 -1
  193. package/ast-validator/dimension-validator.js +0 -54
  194. package/ast-validator/dimension-validator.js.map +0 -1
  195. package/ast-validator/index.js +0 -25
  196. package/ast-validator/index.js.map +0 -1
  197. package/ast-validator/measure-validator.js +0 -163
  198. package/ast-validator/measure-validator.js.map +0 -1
  199. package/ast-validator/tests/test-data.js.map +0 -1
  200. package/ast-validator/types.js +0 -3
  201. package/ast-validator/types.js.map +0 -1
  202. package/ast-validator/utils.js +0 -35
  203. package/ast-validator/utils.js.map +0 -1
  204. package/context-params/context-params-ast.js +0 -55
  205. package/context-params/context-params-ast.js.map +0 -1
  206. package/cube-filter-transformer/and/and.js +0 -18
  207. package/cube-filter-transformer/and/and.js.map +0 -1
  208. package/cube-filter-transformer/base-condition-builder/base-condition-builder.js +0 -160
  209. package/cube-filter-transformer/base-condition-builder/base-condition-builder.js.map +0 -1
  210. package/cube-filter-transformer/contains/contains.js +0 -71
  211. package/cube-filter-transformer/contains/contains.js.map +0 -1
  212. package/cube-filter-transformer/equals/equals-array.js +0 -77
  213. package/cube-filter-transformer/equals/equals-array.js.map +0 -1
  214. package/cube-filter-transformer/equals/equals.js +0 -37
  215. package/cube-filter-transformer/equals/equals.js.map +0 -1
  216. package/cube-filter-transformer/factory.js +0 -124
  217. package/cube-filter-transformer/factory.js.map +0 -1
  218. package/cube-filter-transformer/gt/gt.js +0 -30
  219. package/cube-filter-transformer/gt/gt.js.map +0 -1
  220. package/cube-filter-transformer/gte/gte.js +0 -30
  221. package/cube-filter-transformer/gte/gte.js.map +0 -1
  222. package/cube-filter-transformer/in/in.js +0 -78
  223. package/cube-filter-transformer/in/in.js.map +0 -1
  224. package/cube-filter-transformer/in-date-range/in-date-range.js +0 -24
  225. package/cube-filter-transformer/in-date-range/in-date-range.js.map +0 -1
  226. package/cube-filter-transformer/lt/lt.js +0 -30
  227. package/cube-filter-transformer/lt/lt.js.map +0 -1
  228. package/cube-filter-transformer/lte/lte.js +0 -30
  229. package/cube-filter-transformer/lte/lte.js.map +0 -1
  230. package/cube-filter-transformer/not/not.js +0 -18
  231. package/cube-filter-transformer/not/not.js.map +0 -1
  232. package/cube-filter-transformer/not-In-date-range/not-In-date-range.js +0 -24
  233. package/cube-filter-transformer/not-In-date-range/not-In-date-range.js.map +0 -1
  234. package/cube-filter-transformer/not-contains/not-contains.js +0 -71
  235. package/cube-filter-transformer/not-contains/not-contains.js.map +0 -1
  236. package/cube-filter-transformer/not-equals/not-equals-array.js +0 -26
  237. package/cube-filter-transformer/not-equals/not-equals-array.js.map +0 -1
  238. package/cube-filter-transformer/not-equals/not-equals.js +0 -37
  239. package/cube-filter-transformer/not-equals/not-equals.js.map +0 -1
  240. package/cube-filter-transformer/not-in/not-in.js +0 -85
  241. package/cube-filter-transformer/not-in/not-in.js.map +0 -1
  242. package/cube-filter-transformer/not-set/not-set.js +0 -27
  243. package/cube-filter-transformer/not-set/not-set.js.map +0 -1
  244. package/cube-filter-transformer/or/or.js +0 -18
  245. package/cube-filter-transformer/or/or.js.map +0 -1
  246. package/cube-filter-transformer/set/set.js +0 -27
  247. package/cube-filter-transformer/set/set.js.map +0 -1
  248. package/cube-group-by-transformer/cube-group-by-transformer.js +0 -25
  249. package/cube-group-by-transformer/cube-group-by-transformer.js.map +0 -1
  250. package/cube-limit-offset-transformer/cube-limit-offset-transformer.js +0 -42
  251. package/cube-limit-offset-transformer/cube-limit-offset-transformer.js.map +0 -1
  252. package/cube-measure-transformer/cube-measure-transformer.js +0 -127
  253. package/cube-measure-transformer/cube-measure-transformer.js.map +0 -1
  254. package/cube-order-by-transformer/cube-order-by-transformer.js +0 -39
  255. package/cube-order-by-transformer/cube-order-by-transformer.js.map +0 -1
  256. package/cube-to-duckdb/cube-filter-to-duckdb.js +0 -3
  257. package/cube-to-duckdb/cube-filter-to-duckdb.js.map +0 -1
  258. package/filter-params/filter-params-ast.js +0 -115
  259. package/filter-params/filter-params-ast.js.map +0 -1
  260. package/get-filter-params-sql/get-filter-params-sql.js +0 -28
  261. package/get-filter-params-sql/get-filter-params-sql.js.map +0 -1
  262. package/get-final-base-sql/get-final-base-sql.js +0 -30
  263. package/get-final-base-sql/get-final-base-sql.js.map +0 -1
  264. package/get-wrapped-base-query-with-projections/get-aliased-columns-from-filters.js.map +0 -1
  265. package/get-wrapped-base-query-with-projections/get-projection-clause.js +0 -87
  266. package/get-wrapped-base-query-with-projections/get-projection-clause.js.map +0 -1
  267. package/get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections.js +0 -33
  268. package/get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections.js.map +0 -1
  269. package/get-wrapped-base-query-with-projections/sql-expression-modifiers.js +0 -60
  270. package/get-wrapped-base-query-with-projections/sql-expression-modifiers.js.map +0 -1
  271. package/index.js +0 -66
  272. package/index.js.map +0 -1
  273. package/joins/joins.js +0 -170
  274. package/joins/joins.js.map +0 -1
  275. package/member-formatters/constants.js +0 -19
  276. package/member-formatters/constants.js.map +0 -1
  277. package/member-formatters/index.js +0 -23
  278. package/member-formatters/index.js.map +0 -1
  279. package/member-formatters/member-key-to-safe-key.js +0 -13
  280. package/member-formatters/member-key-to-safe-key.js.map +0 -1
  281. package/member-formatters/split-into-data-source-and-fields.js +0 -17
  282. package/member-formatters/split-into-data-source-and-fields.js.map +0 -1
  283. package/resolution/resolution.js +0 -128
  284. package/resolution/resolution.js.map +0 -1
  285. package/resolution/types.js +0 -10
  286. package/resolution/types.js.map +0 -1
  287. package/types/cube-types/index.d.js +0 -6
  288. package/types/cube-types/index.d.js.map +0 -1
  289. package/types/cube-types/index.js +0 -6
  290. package/types/cube-types/index.js.map +0 -1
  291. package/types/cube-types/query.d.js +0 -5
  292. package/types/cube-types/query.d.js.map +0 -1
  293. package/types/cube-types/query.js +0 -14
  294. package/types/cube-types/query.js.map +0 -1
  295. package/types/cube-types/table.d.js +0 -3
  296. package/types/cube-types/table.d.js.map +0 -1
  297. package/types/cube-types/table.js +0 -3
  298. package/types/cube-types/table.js.map +0 -1
  299. package/types/duckdb-serialization-types/index.d.js +0 -11
  300. package/types/duckdb-serialization-types/index.d.js.map +0 -1
  301. package/types/duckdb-serialization-types/index.js +0 -11
  302. package/types/duckdb-serialization-types/index.js.map +0 -1
  303. package/types/duckdb-serialization-types/serialization/Constraint.js.map +0 -1
  304. package/types/duckdb-serialization-types/serialization/CreateInfo.js.map +0 -1
  305. package/types/duckdb-serialization-types/serialization/Expression.d.js +0 -3
  306. package/types/duckdb-serialization-types/serialization/Expression.d.js.map +0 -1
  307. package/types/duckdb-serialization-types/serialization/Expression.js.map +0 -1
  308. package/types/duckdb-serialization-types/serialization/LogicalOperator.js +0 -47
  309. package/types/duckdb-serialization-types/serialization/LogicalOperator.js.map +0 -1
  310. package/types/duckdb-serialization-types/serialization/MacroFunction.js +0 -15
  311. package/types/duckdb-serialization-types/serialization/MacroFunction.js.map +0 -1
  312. package/types/duckdb-serialization-types/serialization/Misc.d.js +0 -3
  313. package/types/duckdb-serialization-types/serialization/Misc.d.js.map +0 -1
  314. package/types/duckdb-serialization-types/serialization/Misc.js +0 -3
  315. package/types/duckdb-serialization-types/serialization/Misc.js.map +0 -1
  316. package/types/duckdb-serialization-types/serialization/Nodes.d.js +0 -3
  317. package/types/duckdb-serialization-types/serialization/Nodes.d.js.map +0 -1
  318. package/types/duckdb-serialization-types/serialization/Nodes.js.map +0 -1
  319. package/types/duckdb-serialization-types/serialization/ParseInfo.js.map +0 -1
  320. package/types/duckdb-serialization-types/serialization/ParsedExpression.d.js +0 -3
  321. package/types/duckdb-serialization-types/serialization/ParsedExpression.d.js.map +0 -1
  322. package/types/duckdb-serialization-types/serialization/ParsedExpression.js.map +0 -1
  323. package/types/duckdb-serialization-types/serialization/QueryNode.d.js +0 -3
  324. package/types/duckdb-serialization-types/serialization/QueryNode.d.js.map +0 -1
  325. package/types/duckdb-serialization-types/serialization/QueryNode.js.map +0 -1
  326. package/types/duckdb-serialization-types/serialization/ResultModifier.d.js +0 -3
  327. package/types/duckdb-serialization-types/serialization/ResultModifier.d.js.map +0 -1
  328. package/types/duckdb-serialization-types/serialization/ResultModifier.js.map +0 -1
  329. package/types/duckdb-serialization-types/serialization/Statement.d.js +0 -3
  330. package/types/duckdb-serialization-types/serialization/Statement.d.js.map +0 -1
  331. package/types/duckdb-serialization-types/serialization/Statement.js +0 -3
  332. package/types/duckdb-serialization-types/serialization/Statement.js.map +0 -1
  333. package/types/duckdb-serialization-types/serialization/TableFilter.d.js +0 -3
  334. package/types/duckdb-serialization-types/serialization/TableFilter.d.js.map +0 -1
  335. package/types/duckdb-serialization-types/serialization/TableFilter.js.map +0 -1
  336. package/types/duckdb-serialization-types/serialization/TableRef.d.js +0 -3
  337. package/types/duckdb-serialization-types/serialization/TableRef.d.js.map +0 -1
  338. package/types/duckdb-serialization-types/serialization/TableRef.js.map +0 -1
  339. package/types/duckdb-serialization-types/serialization/Types.d.js +0 -3
  340. package/types/duckdb-serialization-types/serialization/Types.d.js.map +0 -1
  341. package/types/duckdb-serialization-types/serialization/Types.js.map +0 -1
  342. package/types/duckdb-serialization-types/serialization/example.js +0 -131
  343. package/types/duckdb-serialization-types/serialization/example.js.map +0 -1
  344. package/types/utils.js +0 -108
  345. package/types/utils.js.map +0 -1
  346. package/utils/__fixtures__/joins.fixtures.js.map +0 -1
  347. package/utils/base-ast.js +0 -63
  348. package/utils/base-ast.js.map +0 -1
  349. package/utils/cube-filter-enrichment.js +0 -63
  350. package/utils/cube-filter-enrichment.js.map +0 -1
  351. package/utils/cube-to-table-schema.js.map +0 -1
  352. package/utils/cube-type-to-duckdb-type.js +0 -17
  353. package/utils/cube-type-to-duckdb-type.js.map +0 -1
  354. package/utils/find-in-table-schema.js +0 -40
  355. package/utils/find-in-table-schema.js.map +0 -1
  356. package/utils/get-column-names-from-ast.js +0 -45
  357. package/utils/get-column-names-from-ast.js.map +0 -1
  358. package/utils/get-possible-nodes.js +0 -152
  359. package/utils/get-possible-nodes.js.map +0 -1
  360. package/utils/get-type-info.js +0 -44
  361. package/utils/get-type-info.js.map +0 -1
  362. package/utils/is-array-member-type.js +0 -12
  363. package/utils/is-array-member-type.js.map +0 -1
  364. package/utils/key-from-measures-dimension.js +0 -35
  365. package/utils/key-from-measures-dimension.js.map +0 -1
  366. package/utils/meerkat-placeholder-replacer.js +0 -14
  367. package/utils/meerkat-placeholder-replacer.js.map +0 -1
  368. package/utils/modify-meerkat-filter.js +0 -30
  369. package/utils/modify-meerkat-filter.js.map +0 -1
  370. package/utils/type-guards.js.map +0 -1
@@ -1,56 +1,42 @@
1
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
- getAliasedColumnsFromFilters: function() {
10
- return getAliasedColumnsFromFilters;
11
- },
12
- getDimensionProjection: function() {
13
- return getDimensionProjection;
14
- },
15
- getFilterMeasureProjection: function() {
16
- return getFilterMeasureProjection;
17
- }
18
- });
19
- const _memberkeytosafekey = require("../member-formatters/member-key-to-safe-key");
20
- const _splitintodatasourceandfields = require("../member-formatters/split-into-data-source-and-fields");
21
- const _findintableschema = require("../utils/find-in-table-schema");
22
- const _sqlexpressionmodifiers = require("./sql-expression-modifiers");
23
- const getDimensionProjection = ({ key, tableSchema, modifiers, query })=>{
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAliasedColumnsFromFilters = exports.getFilterMeasureProjection = exports.getDimensionProjection = void 0;
4
+ const get_alias_1 = require("../member-formatters/get-alias");
5
+ const split_into_data_source_and_fields_1 = require("../member-formatters/split-into-data-source-and-fields");
6
+ const find_in_table_schema_1 = require("../utils/find-in-table-schema");
7
+ const sql_expression_modifiers_1 = require("./sql-expression-modifiers");
8
+ const getDimensionProjection = ({ key, tableSchema, modifiers, query, }) => {
24
9
  // Find the table access key
25
- const [tableName, measureWithoutTable] = (0, _splitintodatasourceandfields.splitIntoDataSourceAndFields)(key);
26
- const foundMember = (0, _findintableschema.findInDimensionSchema)(measureWithoutTable, tableSchema);
10
+ const [tableName, measureWithoutTable] = (0, split_into_data_source_and_fields_1.splitIntoDataSourceAndFields)(key);
11
+ const foundMember = (0, find_in_table_schema_1.findInDimensionSchema)(measureWithoutTable, tableSchema);
27
12
  if (!foundMember || tableName !== tableSchema.name) {
28
13
  // If the selected member is not found in the table schema or if it is already selected, continue.
29
14
  // If the selected member is not from the current table, don't create an alias.
30
15
  return {
31
16
  sql: undefined,
32
17
  foundMember: undefined,
33
- aliasKey: undefined
18
+ aliasKey: undefined,
34
19
  };
35
20
  }
36
- const modifiedSql = (0, _sqlexpressionmodifiers.getModifiedSqlExpression)({
21
+ const modifiedSql = (0, sql_expression_modifiers_1.getModifiedSqlExpression)({
37
22
  dimension: foundMember,
38
23
  key: key,
39
24
  modifiers: modifiers,
40
25
  sqlExpression: foundMember.sql,
41
- query
26
+ query,
27
+ });
28
+ const aliasKey = (0, get_alias_1.getAliasFromSchema)({
29
+ name: key,
30
+ tableSchema,
31
+ aliasContext: { isAstIdentifier: false },
42
32
  });
43
- const aliasKey = (0, _memberkeytosafekey.memberKeyToSafeKey)(key);
44
33
  // Add the alias key to the set. So we have a reference to all the previously selected members.
45
- return {
46
- sql: `${modifiedSql} AS ${aliasKey}`,
47
- foundMember,
48
- aliasKey
49
- };
34
+ return { sql: `${modifiedSql} AS ${aliasKey}`, foundMember, aliasKey };
50
35
  };
51
- const getFilterMeasureProjection = ({ key, tableSchema, measures })=>{
52
- const [tableName, measureWithoutTable] = (0, _splitintodatasourceandfields.splitIntoDataSourceAndFields)(key);
53
- const foundMember = (0, _findintableschema.findInMeasureSchema)(measureWithoutTable, tableSchema);
36
+ exports.getDimensionProjection = getDimensionProjection;
37
+ const getFilterMeasureProjection = ({ key, tableSchema, measures, }) => {
38
+ const [tableName, measureWithoutTable] = (0, split_into_data_source_and_fields_1.splitIntoDataSourceAndFields)(key);
39
+ const foundMember = (0, find_in_table_schema_1.findInMeasureSchema)(measureWithoutTable, tableSchema);
54
40
  const isMeasure = measures.includes(key);
55
41
  if (!foundMember || isMeasure || tableName !== tableSchema.name) {
56
42
  // If the selected member is not found in the table schema or if it is already selected, continue.
@@ -59,71 +45,72 @@ const getFilterMeasureProjection = ({ key, tableSchema, measures })=>{
59
45
  return {
60
46
  sql: undefined,
61
47
  foundMember: undefined,
62
- aliasKey: undefined
48
+ aliasKey: undefined,
63
49
  };
64
50
  }
65
- const aliasKey = (0, _memberkeytosafekey.memberKeyToSafeKey)(key);
66
- return {
67
- sql: `${key} AS ${aliasKey}`,
68
- foundMember,
69
- aliasKey
70
- };
51
+ const aliasKey = (0, get_alias_1.getAliasFromSchema)({
52
+ name: key,
53
+ tableSchema,
54
+ aliasContext: { isAstIdentifier: false },
55
+ });
56
+ return { sql: `${key} AS ${aliasKey}`, foundMember, aliasKey };
71
57
  };
72
- const getFilterProjections = ({ member, tableSchema, measures, query })=>{
73
- const [, memberWithoutTable] = (0, _splitintodatasourceandfields.splitIntoDataSourceAndFields)(member);
74
- const isDimension = (0, _findintableschema.findInDimensionSchema)(memberWithoutTable, tableSchema);
58
+ exports.getFilterMeasureProjection = getFilterMeasureProjection;
59
+ const getFilterProjections = ({ member, tableSchema, measures, query, }) => {
60
+ const [, memberWithoutTable] = (0, split_into_data_source_and_fields_1.splitIntoDataSourceAndFields)(member);
61
+ const isDimension = (0, find_in_table_schema_1.findInDimensionSchema)(memberWithoutTable, tableSchema);
75
62
  if (isDimension) {
76
- return getDimensionProjection({
63
+ return (0, exports.getDimensionProjection)({
77
64
  key: member,
78
65
  tableSchema,
79
66
  modifiers: [],
80
- query
67
+ query,
81
68
  });
82
69
  }
83
- const isMeasure = (0, _findintableschema.findInMeasureSchema)(memberWithoutTable, tableSchema);
70
+ const isMeasure = (0, find_in_table_schema_1.findInMeasureSchema)(memberWithoutTable, tableSchema);
84
71
  if (isMeasure) {
85
- return getFilterMeasureProjection({
72
+ return (0, exports.getFilterMeasureProjection)({
86
73
  key: member,
87
74
  tableSchema,
88
- measures
75
+ measures,
89
76
  });
90
77
  }
91
78
  return {
92
79
  sql: undefined,
93
80
  foundMember: undefined,
94
- aliasKey: undefined
81
+ aliasKey: undefined,
95
82
  };
96
83
  };
97
- const getAliasedColumnsFromFilters = ({ baseSql, meerkatFilters, tableSchema, aliasedColumnSet, query })=>{
84
+ const getAliasedColumnsFromFilters = ({ baseSql, meerkatFilters, tableSchema, aliasedColumnSet, query, }) => {
98
85
  let sql = baseSql;
99
86
  const { measures } = query;
100
- meerkatFilters == null ? void 0 : meerkatFilters.forEach((filter)=>{
87
+ meerkatFilters === null || meerkatFilters === void 0 ? void 0 : meerkatFilters.forEach((filter) => {
101
88
  if ('and' in filter) {
102
89
  // Traverse through the passed 'and' filters
103
- sql += getAliasedColumnsFromFilters({
90
+ sql += (0, exports.getAliasedColumnsFromFilters)({
104
91
  baseSql: '',
105
92
  meerkatFilters: filter.and,
106
93
  tableSchema,
107
94
  aliasedColumnSet,
108
- query
95
+ query,
109
96
  });
110
97
  }
111
98
  if ('or' in filter) {
112
99
  // Traverse through the passed 'or' filters
113
- sql += getAliasedColumnsFromFilters({
100
+ sql += (0, exports.getAliasedColumnsFromFilters)({
114
101
  baseSql: '',
115
102
  tableSchema,
116
103
  meerkatFilters: filter.or,
117
104
  aliasedColumnSet,
118
- query
105
+ query,
119
106
  });
120
107
  }
121
108
  if ('member' in filter) {
122
- const { aliasKey, foundMember, sql: memberSql } = getFilterProjections({
109
+ const { aliasKey, foundMember, sql: memberSql, } = getFilterProjections({
123
110
  member: filter.member,
124
111
  tableSchema,
125
112
  measures,
126
- query
113
+ query,
127
114
  });
128
115
  if (!foundMember || aliasedColumnSet.has(aliasKey)) {
129
116
  // If the selected member is not found in the table schema or if it is already selected, continue.
@@ -138,5 +125,5 @@ const getAliasedColumnsFromFilters = ({ baseSql, meerkatFilters, tableSchema, al
138
125
  });
139
126
  return sql;
140
127
  };
141
-
128
+ exports.getAliasedColumnsFromFilters = getAliasedColumnsFromFilters;
142
129
  //# sourceMappingURL=get-aliased-columns-from-filters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-aliased-columns-from-filters.js","sourceRoot":"","sources":["../../../../meerkat-core/src/get-wrapped-base-query-with-projections/get-aliased-columns-from-filters.ts"],"names":[],"mappings":";;;AAAA,8DAAoE;AACpE,8GAAsG;AAEtG,wEAGuC;AACvC,yEAAgF;AAEzE,MAAM,sBAAsB,GAAG,CAAC,EACrC,GAAG,EACH,WAAW,EACX,SAAS,EACT,KAAK,GAMN,EAAE,EAAE;IACH,4BAA4B;IAC5B,MAAM,CAAC,SAAS,EAAE,mBAAmB,CAAC,GAAG,IAAA,gEAA4B,EAAC,GAAG,CAAC,CAAC;IAE3E,MAAM,WAAW,GAAG,IAAA,4CAAqB,EAAC,mBAAmB,EAAE,WAAW,CAAC,CAAC;IAC5E,IAAI,CAAC,WAAW,IAAI,SAAS,KAAK,WAAW,CAAC,IAAI,EAAE;QAClD,kGAAkG;QAClG,+EAA+E;QAC/E,OAAO;YACL,GAAG,EAAE,SAAS;YACd,WAAW,EAAE,SAAS;YACtB,QAAQ,EAAE,SAAS;SACpB,CAAC;KACH;IAED,MAAM,WAAW,GAAG,IAAA,mDAAwB,EAAC;QAC3C,SAAS,EAAE,WAAW;QACtB,GAAG,EAAE,GAAG;QACR,SAAS,EAAE,SAAS;QACpB,aAAa,EAAE,WAAW,CAAC,GAAG;QAC9B,KAAK;KACN,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,IAAA,8BAAkB,EAAC;QAClC,IAAI,EAAE,GAAG;QACT,WAAW;QACX,YAAY,EAAE,EAAE,eAAe,EAAE,KAAK,EAAE;KACzC,CAAC,CAAC;IACH,+FAA+F;IAC/F,OAAO,EAAE,GAAG,EAAE,GAAG,WAAW,OAAO,QAAQ,EAAE,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;AACzE,CAAC,CAAC;AAxCW,QAAA,sBAAsB,0BAwCjC;AAEK,MAAM,0BAA0B,GAAG,CAAC,EACzC,GAAG,EACH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AC,GAAG,CAAC,QAAQ,CAAC,EAAE;gBAClD,kGAAkG;gBAClG,OAAO;aACR;YACD,IAAI,QAAQ,EAAE;gBACZ,gBAAgB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;aAChC;YACD,+FAA+F;YAC/F,GAAG,IAAI,KAAK,SAAS,EAAE,CAAC;SACzB;IACH,CAAC,CAAC,CAAC;IACH,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AA3DW,QAAA,4BAA4B,gCA2DvC"}
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getProjectionClause = void 0;
4
+ const cube_measure_transformer_1 = require("../cube-measure-transformer/cube-measure-transformer");
5
+ const get_alias_1 = require("../member-formatters/get-alias");
6
+ const split_into_data_source_and_fields_1 = require("../member-formatters/split-into-data-source-and-fields");
7
+ const get_aliased_columns_from_filters_1 = require("./get-aliased-columns-from-filters");
8
+ const sql_expression_modifiers_1 = require("./sql-expression-modifiers");
9
+ const memberClauseAggregator = ({ member, aliasedColumnSet, acc, sql, }) => {
10
+ if (aliasedColumnSet.has(member) || !sql) {
11
+ return acc;
12
+ }
13
+ aliasedColumnSet.add(member);
14
+ acc.push(sql);
15
+ return acc;
16
+ };
17
+ const getProjectionClause = (query, tableSchema, aliasedColumnSet) => {
18
+ const { measures, dimensions = [] } = query;
19
+ const filteredDimensions = dimensions.filter((dimension) => {
20
+ const [dimensionDataSource] = (0, split_into_data_source_and_fields_1.splitIntoDataSourceAndFields)(dimension);
21
+ return dimensionDataSource === tableSchema.name;
22
+ });
23
+ const filteredMeasures = measures.filter((measure) => {
24
+ const [measureDataSource] = (0, split_into_data_source_and_fields_1.splitIntoDataSourceAndFields)(measure);
25
+ return measureDataSource === tableSchema.name;
26
+ });
27
+ const dimensionsProjectionsArr = filteredDimensions.reduce((acc, member, currentIndex, members) => {
28
+ const { sql: memberSql } = (0, get_aliased_columns_from_filters_1.getDimensionProjection)({
29
+ key: member,
30
+ tableSchema,
31
+ modifiers: sql_expression_modifiers_1.MODIFIERS,
32
+ query,
33
+ });
34
+ return memberClauseAggregator({
35
+ member: (0, get_alias_1.getAliasFromSchema)({
36
+ name: member,
37
+ tableSchema,
38
+ aliasContext: { isAstIdentifier: false },
39
+ }),
40
+ aliasedColumnSet,
41
+ acc,
42
+ currentIndex,
43
+ members,
44
+ sql: memberSql,
45
+ });
46
+ }, []);
47
+ const dimensionsProjections = dimensionsProjectionsArr.join(', ');
48
+ const measureProjectionsArr = filteredMeasures.reduce((acc, member, currentIndex, members) => {
49
+ const { sql: memberSql } = (0, get_aliased_columns_from_filters_1.getFilterMeasureProjection)({
50
+ key: member,
51
+ tableSchema,
52
+ measures,
53
+ });
54
+ return memberClauseAggregator({
55
+ member,
56
+ aliasedColumnSet,
57
+ acc,
58
+ currentIndex,
59
+ members,
60
+ sql: memberSql,
61
+ });
62
+ }, []);
63
+ const measureProjections = measureProjectionsArr.join(', ');
64
+ const usedMeasureObjects = tableSchema.measures.filter((measure) => {
65
+ return (measures.findIndex((key) => {
66
+ const [, keyWithoutTable] = (0, split_into_data_source_and_fields_1.splitIntoDataSourceAndFields)(key);
67
+ return keyWithoutTable === measure.name;
68
+ }) !== -1);
69
+ });
70
+ const columnsUsedInMeasures = (0, cube_measure_transformer_1.getAllColumnUsedInMeasures)(usedMeasureObjects, tableSchema);
71
+ let columnsUsedInMeasuresInProjection = '';
72
+ columnsUsedInMeasures.forEach((column, index) => {
73
+ const safeKey = (0, get_alias_1.getAliasFromSchema)({
74
+ name: column,
75
+ tableSchema,
76
+ aliasContext: { isAstIdentifier: false },
77
+ });
78
+ columnsUsedInMeasuresInProjection += `${column} AS ${safeKey}`;
79
+ if (index !== columnsUsedInMeasures.length - 1) {
80
+ columnsUsedInMeasuresInProjection += ', ';
81
+ }
82
+ });
83
+ const combinedStr = [
84
+ dimensionsProjections,
85
+ measureProjections,
86
+ columnsUsedInMeasuresInProjection,
87
+ ];
88
+ return combinedStr.filter((str) => str.length > 0).join(', ');
89
+ };
90
+ exports.getProjectionClause = getProjectionClause;
91
+ //# sourceMappingURL=get-projection-clause.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-projection-clause.js","sourceRoot":"","sources":["../../../../meerkat-core/src/get-wrapped-base-query-with-projections/get-projection-clause.ts"],"names":[],"mappings":";;;AAAA,mGAAkG;AAClG,8DAAoE;AACpE,8GAAsG;AAEtG,yFAG4C;AAC5C,yEAAuD;AAEvD,MAAM,sBAAsB,GAAG,CAAC,EAC9B,MAAM,EACN,gBAAgB,EAChB,GAAG,EACH,GAAG,GAQJ,EAAE,EAAE;IACH,IAAI,gBAAgB,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE;QACxC,OAAO,GAAG,CAAC;KACZ;IACD,gBAAgB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC7B,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACd,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAEK,MAAM,mBAAmB,GAAG,CACjC,KAAY,EACZ,WAAwB,EACxB,gBAA6B,EAC7B,EAAE;IACF,MAAM,EAAE,QAAQ,EAAE,UAAU,GAAG,EAAE,EAAE,GAAG,KAAK,CAAC;IAC5C,MAAM,kBAAkB,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE;QACzD,MAAM,CAAC,mBAAmB,CAAC,GAAG,IAAA,gEAA4B,EAAC,SAAS,CAAC,CAAC;QACtE,OAAO,mBAAmB,KAAK,WAAW,CAAC,IAAI,CAAC;IAClD,CAAC,CAAC,CAAC;IACH,MAAM,gBAAgB,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE;QACnD,MAAM,CAAC,iBAAiB,CAAC,GAAG,IAAA,gEAA4B,EAAC,OAAO,CAAC,CAAC;QAClE,OAAO,iBAAiB,KAAK,WAAW,CAAC,IAAI,CAAC;IAChD,CAAC,CAAC,CAAC;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C,GAAG,EAAE,EAAE;YACzB,MAAM,CAAC,EAAE,eAAe,CAAC,GAAG,IAAA,gEAA4B,EAAC,GAAG,CAAC,CAAC;YAC9D,OAAO,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC;QAC1C,CAAC,CAAC,KAAK,CAAC,CAAC,CACV,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,MAAM,qBAAqB,GAAG,IAAA,qDAA0B,EACtD,kBAAkB,EAClB,WAAW,CACZ,CAAC;IAEF,IAAI,iCAAiC,GAAG,EAAE,CAAC;IAC3C,qBAAqB,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;QAC9C,MAAM,OAAO,GAAG,IAAA,8BAAkB,EAAC;YACjC,IAAI,EAAE,MAAM;YACZ,WAAW;YACX,YAAY,EAAE,EAAE,eAAe,EAAE,KAAK,EAAE;SACzC,CAAC,CAAC;QACH,iCAAiC,IAAI,GAAG,MAAM,OAAO,OAAO,EAAE,CAAC;QAC/D,IAAI,KAAK,KAAK,qBAAqB,CAAC,MAAM,GAAG,CAAC,EAAE;YAC9C,iCAAiC,IAAI,IAAI,CAAC;SAC3C;IACH,CAAC,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG;QAClB,qBAAqB;QACrB,kBAAkB;QAClB,iCAAiC;KAClC,CAAC;IAEF,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAChE,CAAC,CAAC;AA7FW,QAAA,mBAAmB,uBA6F9B"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getWrappedBaseQueryWithProjections = void 0;
4
+ const cube_measure_transformer_1 = require("../cube-measure-transformer/cube-measure-transformer");
5
+ const get_aliased_columns_from_filters_1 = require("./get-aliased-columns-from-filters");
6
+ const get_projection_clause_1 = require("./get-projection-clause");
7
+ const getWrappedBaseQueryWithProjections = ({ baseQuery, tableSchema, query, }) => {
8
+ /*
9
+ * Im order to be able to filter on computed metric from a query, we need to project the computed metric in the base query.
10
+ * If theres filters supplied, we can safely return the original base query. Since nothing need to be projected and filtered in this case
11
+ */
12
+ // 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
13
+ const newBaseSql = `SELECT * FROM (${baseQuery}) AS ${tableSchema.name}`;
14
+ const aliasedColumnSet = new Set();
15
+ const memberProjections = (0, get_projection_clause_1.getProjectionClause)(query, tableSchema, aliasedColumnSet);
16
+ const aliasFromFilters = (0, get_aliased_columns_from_filters_1.getAliasedColumnsFromFilters)({
17
+ aliasedColumnSet,
18
+ baseSql: 'SELECT *',
19
+ // setting measures to empty array, since we don't want to project measures present in the filters in the base query
20
+ tableSchema: tableSchema,
21
+ query,
22
+ meerkatFilters: query.filters,
23
+ });
24
+ const formattedMemberProjection = memberProjections
25
+ ? `, ${memberProjections}`
26
+ : '';
27
+ const finalAliasedColumnsClause = aliasFromFilters + formattedMemberProjection;
28
+ const sqlWithFilterProjects = (0, cube_measure_transformer_1.getSelectReplacedSql)(newBaseSql, finalAliasedColumnsClause);
29
+ return sqlWithFilterProjects;
30
+ };
31
+ exports.getWrappedBaseQueryWithProjections = getWrappedBaseQueryWithProjections;
32
+ //# sourceMappingURL=get-wrapped-base-query-with-projections.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-wrapped-base-query-with-projections.js","sourceRoot":"","sources":["../../../../meerkat-core/src/get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections.ts"],"names":[],"mappings":";;;AAAA,mGAA4F;AAE5F,yFAAkF;AAClF,mEAEiC;AAQ1B,MAAM,kCAAkC,GAAG,CAAC,EACjD,SAAS,EACT,WAAW,EACX,KAAK,GACoC,EAAE,EAAE;IAC7C;;;OAGG;IACH,kLAAkL;IAClL,MAAM,UAAU,GAAG,kBAAkB,SAAS,QAAQ,WAAW,CAAC,IAAI,EAAE,CAAC;IACzE,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;IAE3C,MAAM,iBAAiB,GAAG,IAAA,2CAAmB,EAC3C,KAAK,EACL,WAAW,EACX,gBAAgB,CACjB,CAAC;IAEF,MAAM,gBAAgB,GAAG,IAAA,+DAA4B,EAAC;QACpD,gBAAgB;QAChB,OAAO,EAAE,UAAU;QACnB,oHAAoH;QACpH,WAAW,EAAE,WAAW;QACxB,KAAK;QACL,cAAc,EAAE,KAAK,CAAC,OAAO;KAC9B,CAAC,CAAC;IAEH,MAAM,yBAAyB,GAAG,iBAAiB;QACjD,CAAC,CAAC,KAAK,iBAAiB,EAAE;QAC1B,CAAC,CAAC,EAAE,CAAC;IAEP,MAAM,yBAAyB,GAC7B,gBAAgB,GAAG,yBAAyB,CAAC;IAE/C,MAAM,qBAAqB,GAAG,IAAA,+CAAoB,EAChD,UAAU,EACV,yBAAyB,CAC1B,CAAC;IACF,OAAO,qBAAqB,CAAC;AAC/B,CAAC,CAAC;AAxCW,QAAA,kCAAkC,sCAwC7C"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getModifiedSqlExpression = exports.MODIFIERS = exports.shouldUnnest = exports.arrayFieldUnNestModifier = void 0;
4
+ const is_array_member_type_1 = require("../utils/is-array-member-type");
5
+ const arrayFieldUnNestModifier = ({ sqlExpression }) => {
6
+ return `array[unnest(${sqlExpression})]`;
7
+ };
8
+ exports.arrayFieldUnNestModifier = arrayFieldUnNestModifier;
9
+ const shouldUnnest = ({ dimension, query }) => {
10
+ var _a;
11
+ const isArrayType = (0, is_array_member_type_1.isArrayTypeMember)(dimension.type);
12
+ const hasUnNestedGroupBy = (_a = dimension.modifier) === null || _a === void 0 ? void 0 : _a.shouldUnnestGroupBy;
13
+ return !!(isArrayType && hasUnNestedGroupBy && query.measures.length > 0);
14
+ };
15
+ exports.shouldUnnest = shouldUnnest;
16
+ exports.MODIFIERS = [{
17
+ name: 'shouldUnnestGroupBy',
18
+ matcher: exports.shouldUnnest,
19
+ modifier: exports.arrayFieldUnNestModifier
20
+ }];
21
+ const getModifiedSqlExpression = ({ sqlExpression, dimension, key, modifiers, query }) => {
22
+ let finalDimension = sqlExpression;
23
+ modifiers.forEach(({ modifier, matcher }) => {
24
+ const shouldModify = matcher({ sqlExpression: finalDimension, dimension, key, query });
25
+ if (shouldModify) {
26
+ finalDimension = modifier({ sqlExpression: finalDimension, dimension, key, query });
27
+ }
28
+ });
29
+ return finalDimension;
30
+ };
31
+ exports.getModifiedSqlExpression = getModifiedSqlExpression;
32
+ //# sourceMappingURL=sql-expression-modifiers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql-expression-modifiers.js","sourceRoot":"","sources":["../../../../meerkat-core/src/get-wrapped-base-query-with-projections/sql-expression-modifiers.ts"],"names":[],"mappings":";;;AACA,wEAAkE;AAS3D,MAAM,wBAAwB,GAAG,CAAC,EAAE,aAAa,EAAqB,EAAU,EAAE;IACxF,OAAO,gBAAgB,aAAa,IAAI,CAAC;AAC1C,CAAC,CAAA;AAFY,QAAA,wBAAwB,4BAEpC;AAEM,MAAM,YAAY,GAAG,CAAC,EAAE,SAAS,EAAE,KAAK,EAAqB,EAAW,EAAE;;IAC/E,MAAM,WAAW,GAAI,IAAA,wCAAiB,EAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACvD,MAAM,kBAAkB,GAAG,MAAA,SAAS,CAAC,QAAQ,0CAAE,mBAAmB,CAAC;IACnE,OAAO,CAAC,CAAC,CAAC,WAAW,IAAI,kBAAkB,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAC5E,CAAC,CAAA;AAJY,QAAA,YAAY,gBAIxB;AASY,QAAA,SAAS,GAAe,CAAC;QACpC,IAAI,EAAE,qBAAqB;QAC3B,OAAO,EAAE,oBAAY;QACrB,QAAQ,EAAE,gCAAwB;KACnC,CAAC,CAAA;AAGK,MAAM,wBAAwB,GAAG,CAAC,EAAE,aAAa,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAEzF,EAAE,EAAE;IACH,IAAI,cAAc,GAAW,aAAa,CAAC;IAC3C,SAAS,CAAC,OAAO,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE;QAC1C,MAAM,YAAY,GAAG,OAAO,CAAC,EAAE,aAAa,EAAE,cAAc,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;QACvF,IAAI,YAAY,EAAE;YAChB,cAAc,GAAG,QAAQ,CAAC,EAAE,aAAa,EAAE,cAAc,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;SACrF;IACH,CAAC,CAAC,CAAA;IACF,OAAO,cAAc,CAAC;AACxB,CAAC,CAAA;AAXY,QAAA,wBAAwB,4BAWpC"}
package/src/index.js ADDED
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.meerkatPlaceholderReplacer = exports.BASE_TABLE_NAME = exports.getWrappedBaseQueryWithProjections = exports.getFinalBaseSQL = exports.getFilterParamsSQL = exports.getFilterParamsAST = exports.detectAllFilterParamsFromSQL = exports.applyFilterParamsToBaseSQL = exports.detectApplyContextParamsToBaseSQL = void 0;
4
+ const tslib_1 = require("tslib");
5
+ tslib_1.__exportStar(require("./ast-builder/ast-builder"), exports);
6
+ tslib_1.__exportStar(require("./ast-deserializer/ast-deserializer"), exports);
7
+ tslib_1.__exportStar(require("./ast-serializer/ast-serializer"), exports);
8
+ tslib_1.__exportStar(require("./ast-validator"), exports);
9
+ var context_params_ast_1 = require("./context-params/context-params-ast");
10
+ Object.defineProperty(exports, "detectApplyContextParamsToBaseSQL", { enumerable: true, get: function () { return context_params_ast_1.detectApplyContextParamsToBaseSQL; } });
11
+ tslib_1.__exportStar(require("./cube-measure-transformer/cube-measure-transformer"), exports);
12
+ tslib_1.__exportStar(require("./cube-to-duckdb/cube-filter-to-duckdb"), exports);
13
+ var filter_params_ast_1 = require("./filter-params/filter-params-ast");
14
+ Object.defineProperty(exports, "applyFilterParamsToBaseSQL", { enumerable: true, get: function () { return filter_params_ast_1.applyFilterParamsToBaseSQL; } });
15
+ Object.defineProperty(exports, "detectAllFilterParamsFromSQL", { enumerable: true, get: function () { return filter_params_ast_1.detectAllFilterParamsFromSQL; } });
16
+ Object.defineProperty(exports, "getFilterParamsAST", { enumerable: true, get: function () { return filter_params_ast_1.getFilterParamsAST; } });
17
+ var get_filter_params_sql_1 = require("./get-filter-params-sql/get-filter-params-sql");
18
+ Object.defineProperty(exports, "getFilterParamsSQL", { enumerable: true, get: function () { return get_filter_params_sql_1.getFilterParamsSQL; } });
19
+ var get_final_base_sql_1 = require("./get-final-base-sql/get-final-base-sql");
20
+ Object.defineProperty(exports, "getFinalBaseSQL", { enumerable: true, get: function () { return get_final_base_sql_1.getFinalBaseSQL; } });
21
+ var get_wrapped_base_query_with_projections_1 = require("./get-wrapped-base-query-with-projections/get-wrapped-base-query-with-projections");
22
+ Object.defineProperty(exports, "getWrappedBaseQueryWithProjections", { enumerable: true, get: function () { return get_wrapped_base_query_with_projections_1.getWrappedBaseQueryWithProjections; } });
23
+ tslib_1.__exportStar(require("./joins/joins"), exports);
24
+ tslib_1.__exportStar(require("./member-formatters"), exports);
25
+ tslib_1.__exportStar(require("./resolution/resolution"), exports);
26
+ tslib_1.__exportStar(require("./resolution/types"), exports);
27
+ tslib_1.__exportStar(require("./types/cube-types/index"), exports);
28
+ tslib_1.__exportStar(require("./types/duckdb-serialization-types/index"), exports);
29
+ tslib_1.__exportStar(require("./types/utils"), exports);
30
+ var base_ast_1 = require("./utils/base-ast");
31
+ Object.defineProperty(exports, "BASE_TABLE_NAME", { enumerable: true, get: function () { return base_ast_1.BASE_TABLE_NAME; } });
32
+ tslib_1.__exportStar(require("./utils/cube-to-table-schema"), exports);
33
+ tslib_1.__exportStar(require("./utils/get-column-names-from-ast"), exports);
34
+ tslib_1.__exportStar(require("./utils/get-possible-nodes"), exports);
35
+ var meerkat_placeholder_replacer_1 = require("./utils/meerkat-placeholder-replacer");
36
+ Object.defineProperty(exports, "meerkatPlaceholderReplacer", { enumerable: true, get: function () { return meerkat_placeholder_replacer_1.meerkatPlaceholderReplacer; } });
37
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../meerkat-core/src/index.ts"],"names":[],"mappings":";;;;AAAA,oEAA0C;AAC1C,8EAAoD;AACpD,0EAAgD;AAChD,0DAAgC;AAChC,0EAAwF;AAA/E,uIAAA,iCAAiC,OAAA;AAC1C,8FAAoE;AACpE,iFAAuD;AACvD,uEAI2C;AAHzC,+HAAA,0BAA0B,OAAA;AAC1B,iIAAA,4BAA4B,OAAA;AAC5B,uHAAA,kBAAkB,OAAA;AAEpB,uFAAmF;AAA1E,2HAAA,kBAAkB,OAAA;AAC3B,8EAA0E;AAAjE,qHAAA,eAAe,OAAA;AACxB,6IAAuI;AAA9H,6JAAA,kCAAkC,OAAA;AAC3C,wDAA8B;AAC9B,8DAAoC;AACpC,kEAAwC;AACxC,6DAAmC;AAEnC,mEAAyC;AACzC,mFAAyD;AACzD,wDAA8B;AAC9B,6CAAmD;AAA1C,2GAAA,eAAe,OAAA;AACxB,uEAA6C;AAC7C,4EAAkD;AAClD,qEAA2C;AAC3C,qFAAkF;AAAzE,0IAAA,0BAA0B,OAAA"}
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCombinedTableSchema = exports.checkLoopInJoinPath = exports.createDirectedGraph = exports.generateSqlQuery = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const cube_types_1 = require("../types/cube-types");
6
+ function generateSqlQuery(path, tableSchemaSqlMap, directedGraph) {
7
+ if (path.length === 0) {
8
+ throw new Error('Invalid path, multiple data sources are present without a join path.');
9
+ }
10
+ const startingNode = path[0][0].left;
11
+ let query = `${tableSchemaSqlMap[startingNode]}`;
12
+ /**
13
+ * If the starting node is not a join node, then return the query as is.
14
+ * It means that the query is a single node query.
15
+ */
16
+ if (!(0, cube_types_1.isJoinNode)(path[0][0])) {
17
+ return query;
18
+ }
19
+ const visitedNodes = new Map();
20
+ for (let i = 0; i < path.length; i++) {
21
+ if (path[i][0].left !== startingNode) {
22
+ throw new Error('Invalid path, starting node is not the same for all paths.');
23
+ }
24
+ for (let j = 0; j < path[i].length; j++) {
25
+ const currentEdge = path[i][j];
26
+ if (!(0, cube_types_1.isJoinNode)(currentEdge)) {
27
+ continue;
28
+ }
29
+ const visitedFrom = visitedNodes.get(currentEdge.right);
30
+ // If node is already visited from the same edge, continue to next iteration
31
+ if (visitedFrom && visitedFrom.left === currentEdge.left) {
32
+ continue;
33
+ }
34
+ // If node is already visited from a different edge, throw ambiguity error
35
+ if (visitedFrom) {
36
+ throw new Error(`Path ambiguity, node ${currentEdge.right} visited from different sources`);
37
+ }
38
+ // If visitedFrom is undefined, this is the first visit to the node
39
+ visitedNodes.set(currentEdge.right, currentEdge);
40
+ query += ` LEFT JOIN (${tableSchemaSqlMap[currentEdge.right]}) AS ${currentEdge.right} ON ${directedGraph[currentEdge.left][currentEdge.right][currentEdge.on]}`;
41
+ }
42
+ }
43
+ return query;
44
+ }
45
+ exports.generateSqlQuery = generateSqlQuery;
46
+ const createDirectedGraph = (tableSchema, tableSchemaSqlMap) => {
47
+ const directedGraph = {};
48
+ function addEdge(table1, table2, joinOn, joinCondition) {
49
+ if (table1 === table2 ||
50
+ (directedGraph[table1] &&
51
+ directedGraph[table1][table2] &&
52
+ directedGraph[table1][table2][joinOn])) {
53
+ throw new Error('An invalid path was detected.');
54
+ }
55
+ if (!directedGraph[table1])
56
+ directedGraph[table1] = {};
57
+ if (!directedGraph[table1][table2])
58
+ directedGraph[table1][table2] = {};
59
+ directedGraph[table1][table2][joinOn] = joinCondition;
60
+ }
61
+ /**
62
+ * Iterate through the table schema and add the edges to the directed graph.
63
+ * The edges are added based on the join conditions provided in the table schema.
64
+ * The SQL is split by the '=' sign and the tables columns involved in the joins are extracted.
65
+ * The tables are then added as edges to the directed graph.
66
+ */
67
+ tableSchema.forEach((schema) => {
68
+ var _a;
69
+ (_a = schema === null || schema === void 0 ? void 0 : schema.joins) === null || _a === void 0 ? void 0 : _a.forEach((join) => {
70
+ const tables = join.sql.split('=').map((str) => str.split('.')[0].trim());
71
+ const conditions = join.sql
72
+ .split('=')
73
+ .map((str) => str.split('.')[1].trim());
74
+ /**
75
+ * If the join SQL does not contain exactly 2 tables, then the join is invalid.
76
+ */
77
+ if (tables.length !== 2) {
78
+ throw new Error(`Invalid join SQL: ${join.sql}`);
79
+ }
80
+ /**
81
+ * If the tables are the same, then the join is invalid.
82
+ */
83
+ if (tables[0] === tables[1]) {
84
+ throw new Error(`Invalid join SQL: ${join.sql}`);
85
+ }
86
+ /**
87
+ * If the tables are not found in the table schema, then the join is invalid.
88
+ */
89
+ if (tables[0] !== schema.name && tables[1] !== schema.name) {
90
+ throw new Error(`Table "${schema.name}" not found in provided join SQL: ${join.sql}`);
91
+ }
92
+ /**
93
+ * Check if the tables are found in the table schema SQL map.
94
+ */
95
+ if (!tableSchemaSqlMap[tables[0]] || !tableSchemaSqlMap[tables[1]]) {
96
+ return;
97
+ }
98
+ /**
99
+ * If the table is the source table, then add the edge from the source to the target.
100
+ * Thus find which table is the source and which is the target and add the edge accordingly.
101
+ */
102
+ if (tables[0] === schema.name) {
103
+ addEdge(tables[0], tables[1], conditions[0], join.sql);
104
+ }
105
+ else {
106
+ addEdge(tables[1], tables[0], conditions[1], join.sql);
107
+ }
108
+ });
109
+ });
110
+ return directedGraph;
111
+ };
112
+ exports.createDirectedGraph = createDirectedGraph;
113
+ const checkLoopInJoinPath = (joinPath) => {
114
+ for (let i = 0; i < joinPath.length; i++) {
115
+ const visitedNodes = new Set();
116
+ const currentJoinPath = joinPath[i];
117
+ visitedNodes.add(currentJoinPath[0].left);
118
+ for (let j = 0; j < currentJoinPath.length; j++) {
119
+ const currentEdge = currentJoinPath[j];
120
+ if ((0, cube_types_1.isJoinNode)(currentEdge) && visitedNodes.has(currentEdge.right)) {
121
+ if (visitedNodes.has(currentEdge.right)) {
122
+ return true;
123
+ }
124
+ visitedNodes.add(currentEdge.right);
125
+ }
126
+ }
127
+ }
128
+ return false;
129
+ };
130
+ exports.checkLoopInJoinPath = checkLoopInJoinPath;
131
+ const getCombinedTableSchema = (tableSchema, cubeQuery) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
132
+ if (tableSchema.length === 1) {
133
+ return tableSchema[0];
134
+ }
135
+ const tableSchemaSqlMap = tableSchema.reduce((acc, schema) => {
136
+ return Object.assign(Object.assign({}, acc), { [schema.name]: schema.sql });
137
+ }, {});
138
+ const directedGraph = (0, exports.createDirectedGraph)(tableSchema, tableSchemaSqlMap);
139
+ const hasLoop = (0, exports.checkLoopInJoinPath)(cubeQuery.joinPaths || []);
140
+ if (hasLoop) {
141
+ throw new Error(`A loop was detected in the joins. ${JSON.stringify(cubeQuery.joinPaths || [])}`);
142
+ }
143
+ const baseSql = generateSqlQuery(cubeQuery.joinPaths || [], tableSchemaSqlMap, directedGraph);
144
+ const combinedTableSchema = tableSchema.reduce((acc, schema) => {
145
+ return {
146
+ name: 'MEERKAT_GENERATED_TABLE',
147
+ sql: baseSql,
148
+ measures: [...acc.measures, ...schema.measures],
149
+ dimensions: [...acc.dimensions, ...schema.dimensions],
150
+ joins: [],
151
+ };
152
+ }, {
153
+ name: '',
154
+ sql: '',
155
+ measures: [],
156
+ dimensions: [],
157
+ joins: [],
158
+ });
159
+ return combinedTableSchema;
160
+ });
161
+ exports.getCombinedTableSchema = getCombinedTableSchema;
162
+ //# sourceMappingURL=joins.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"joins.js","sourceRoot":"","sources":["../../../../meerkat-core/src/joins/joins.ts"],"names":[],"m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AC;IACJ,CAAC,EACD;QACE,IAAI,EAAE,EAAE;QACR,GAAG,EAAE,EAAE;QACP,QAAQ,EAAE,EAAE;QACZ,UAAU,EAAE,EAAE;QACd,KAAK,EAAE,EAAE;KACV,CACF,CAAC;IACF,OAAO,mBAAmB,CAAC;AAC7B,CAAC,CAAA,CAAC;AAlDW,QAAA,sBAAsB,0BAkDjC"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MEERKAT_OUTPUT_DELIMITER = exports.COLUMN_NAME_DELIMITER = void 0;
4
+ exports.COLUMN_NAME_DELIMITER = '.';
5
+ exports.MEERKAT_OUTPUT_DELIMITER = '__';
6
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../meerkat-core/src/member-formatters/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,qBAAqB,GAAG,GAAG,CAAC;AAC5B,QAAA,wBAAwB,GAAG,IAAI,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { TableSchema } from '../types/cube-types';
2
+ export interface AliasContext {
3
+ isAstIdentifier?: boolean;
4
+ isTableSchemaAlias?: boolean;
5
+ }
6
+ export declare const getAliasFromSchema: ({ name, tableSchema, aliasContext, }: {
7
+ name: string;
8
+ tableSchema: TableSchema;
9
+ aliasContext: AliasContext;
10
+ }) => string;
11
+ export declare const constructAlias: ({ name, alias, aliasContext, }: {
12
+ name: string;
13
+ alias?: string | undefined;
14
+ aliasContext: AliasContext;
15
+ }) => string;