@cubejs-backend/schema-compiler 1.8.8 → 1.8.9

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 (196) hide show
  1. package/dist/src/adapter/BaseDimension.d.ts +3 -3
  2. package/dist/src/adapter/BaseDimension.d.ts.map +1 -1
  3. package/dist/src/adapter/BaseDimension.js.map +1 -1
  4. package/dist/src/adapter/BaseFilter.d.ts +39 -39
  5. package/dist/src/adapter/BaseFilter.d.ts.map +1 -1
  6. package/dist/src/adapter/BaseFilter.js.map +1 -1
  7. package/dist/src/adapter/BaseGroupFilter.d.ts +1 -1
  8. package/dist/src/adapter/BaseGroupFilter.d.ts.map +1 -1
  9. package/dist/src/adapter/BaseGroupFilter.js +5 -5
  10. package/dist/src/adapter/BaseGroupFilter.js.map +1 -1
  11. package/dist/src/adapter/BaseMeasure.d.ts +10 -10
  12. package/dist/src/adapter/BaseMeasure.d.ts.map +1 -1
  13. package/dist/src/adapter/BaseMeasure.js +15 -12
  14. package/dist/src/adapter/BaseMeasure.js.map +1 -1
  15. package/dist/src/adapter/BaseQuery.d.ts +429 -714
  16. package/dist/src/adapter/BaseQuery.d.ts.map +1 -1
  17. package/dist/src/adapter/BaseQuery.js +182 -507
  18. package/dist/src/adapter/BaseQuery.js.map +1 -1
  19. package/dist/src/adapter/BaseSegment.d.ts +2 -2
  20. package/dist/src/adapter/BaseTimeDimension.d.ts +7 -7
  21. package/dist/src/adapter/BaseTimeDimension.d.ts.map +1 -1
  22. package/dist/src/adapter/BaseTimeDimension.js.map +1 -1
  23. package/dist/src/adapter/BigqueryQuery.d.ts +26 -22
  24. package/dist/src/adapter/BigqueryQuery.d.ts.map +1 -1
  25. package/dist/src/adapter/BigqueryQuery.js +2 -2
  26. package/dist/src/adapter/BigqueryQuery.js.map +1 -1
  27. package/dist/src/adapter/ClickHouseQuery.d.ts +20 -13
  28. package/dist/src/adapter/ClickHouseQuery.d.ts.map +1 -1
  29. package/dist/src/adapter/ClickHouseQuery.js +40 -0
  30. package/dist/src/adapter/ClickHouseQuery.js.map +1 -1
  31. package/dist/src/adapter/CrateQuery.d.ts +2 -2
  32. package/dist/src/adapter/CrateQuery.d.ts.map +1 -1
  33. package/dist/src/adapter/CrateQuery.js.map +1 -1
  34. package/dist/src/adapter/CubeStoreQuery.d.ts +21 -21
  35. package/dist/src/adapter/CubeStoreQuery.d.ts.map +1 -1
  36. package/dist/src/adapter/CubeStoreQuery.js +3 -7
  37. package/dist/src/adapter/CubeStoreQuery.js.map +1 -1
  38. package/dist/src/adapter/HiveQuery.d.ts +13 -11
  39. package/dist/src/adapter/HiveQuery.d.ts.map +1 -1
  40. package/dist/src/adapter/HiveQuery.js.map +1 -1
  41. package/dist/src/adapter/MemberSqlTemplateCompiler.d.ts +32 -13
  42. package/dist/src/adapter/MemberSqlTemplateCompiler.d.ts.map +1 -1
  43. package/dist/src/adapter/MemberSqlTemplateCompiler.js +8 -7
  44. package/dist/src/adapter/MemberSqlTemplateCompiler.js.map +1 -1
  45. package/dist/src/adapter/MssqlQuery.d.ts +20 -15
  46. package/dist/src/adapter/MssqlQuery.d.ts.map +1 -1
  47. package/dist/src/adapter/MssqlQuery.js.map +1 -1
  48. package/dist/src/adapter/MysqlQuery.d.ts +9 -7
  49. package/dist/src/adapter/MysqlQuery.d.ts.map +1 -1
  50. package/dist/src/adapter/MysqlQuery.js.map +1 -1
  51. package/dist/src/adapter/OracleQuery.d.ts +11 -9
  52. package/dist/src/adapter/OracleQuery.d.ts.map +1 -1
  53. package/dist/src/adapter/OracleQuery.js +6 -0
  54. package/dist/src/adapter/OracleQuery.js.map +1 -1
  55. package/dist/src/adapter/ParamAllocator.d.ts +2 -2
  56. package/dist/src/adapter/ParamAllocator.d.ts.map +1 -1
  57. package/dist/src/adapter/ParamAllocator.js.map +1 -1
  58. package/dist/src/adapter/PostgresQuery.d.ts +5 -5
  59. package/dist/src/adapter/PostgresQuery.d.ts.map +1 -1
  60. package/dist/src/adapter/PostgresQuery.js.map +1 -1
  61. package/dist/src/adapter/PreAggregations.d.ts +26 -15
  62. package/dist/src/adapter/PreAggregations.d.ts.map +1 -1
  63. package/dist/src/adapter/PreAggregations.js +36 -32
  64. package/dist/src/adapter/PreAggregations.js.map +1 -1
  65. package/dist/src/adapter/PrestodbQuery.d.ts +14 -12
  66. package/dist/src/adapter/PrestodbQuery.d.ts.map +1 -1
  67. package/dist/src/adapter/PrestodbQuery.js +5 -0
  68. package/dist/src/adapter/PrestodbQuery.js.map +1 -1
  69. package/dist/src/adapter/QueryBuilder.d.ts +12 -2
  70. package/dist/src/adapter/QueryBuilder.d.ts.map +1 -1
  71. package/dist/src/adapter/QueryBuilder.js +13 -8
  72. package/dist/src/adapter/QueryBuilder.js.map +1 -1
  73. package/dist/src/adapter/QueryCache.d.ts +1 -1
  74. package/dist/src/adapter/QueryCache.d.ts.map +1 -1
  75. package/dist/src/adapter/QueryCache.js.map +1 -1
  76. package/dist/src/adapter/QueryFactory.d.ts +6 -7
  77. package/dist/src/adapter/QueryFactory.d.ts.map +1 -1
  78. package/dist/src/adapter/QueryFactory.js +3 -2
  79. package/dist/src/adapter/QueryFactory.js.map +1 -1
  80. package/dist/src/adapter/QueryPlanner.d.ts +16 -0
  81. package/dist/src/adapter/QueryPlanner.d.ts.map +1 -0
  82. package/dist/src/adapter/QueryPlanner.js +34 -0
  83. package/dist/src/adapter/QueryPlanner.js.map +1 -0
  84. package/dist/src/adapter/QueryTypes.d.ts +153 -0
  85. package/dist/src/adapter/QueryTypes.d.ts.map +1 -0
  86. package/dist/src/adapter/QueryTypes.js +3 -0
  87. package/dist/src/adapter/QueryTypes.js.map +1 -0
  88. package/dist/src/adapter/RedshiftQuery.d.ts +2 -1
  89. package/dist/src/adapter/RedshiftQuery.d.ts.map +1 -1
  90. package/dist/src/adapter/RedshiftQuery.js.map +1 -1
  91. package/dist/src/adapter/SnowflakeQuery.d.ts +8 -7
  92. package/dist/src/adapter/SnowflakeQuery.d.ts.map +1 -1
  93. package/dist/src/adapter/SnowflakeQuery.js.map +1 -1
  94. package/dist/src/adapter/SqliteQuery.d.ts +12 -10
  95. package/dist/src/adapter/SqliteQuery.d.ts.map +1 -1
  96. package/dist/src/adapter/SqliteQuery.js.map +1 -1
  97. package/dist/src/adapter/TrinoQuery.d.ts +1 -1
  98. package/dist/src/adapter/TrinoQuery.d.ts.map +1 -1
  99. package/dist/src/adapter/TrinoQuery.js.map +1 -1
  100. package/dist/src/adapter/VerticaQuery.d.ts +4 -3
  101. package/dist/src/adapter/VerticaQuery.d.ts.map +1 -1
  102. package/dist/src/adapter/VerticaQuery.js.map +1 -1
  103. package/dist/src/adapter/index.d.ts +2 -0
  104. package/dist/src/adapter/index.d.ts.map +1 -1
  105. package/dist/src/adapter/index.js +2 -0
  106. package/dist/src/adapter/index.js.map +1 -1
  107. package/dist/src/compiler/CompilerCache.d.ts +2 -2
  108. package/dist/src/compiler/CompilerCache.d.ts.map +1 -1
  109. package/dist/src/compiler/CompilerCache.js +1 -1
  110. package/dist/src/compiler/CompilerCache.js.map +1 -1
  111. package/dist/src/compiler/CubeEvaluator.d.ts +84 -4
  112. package/dist/src/compiler/CubeEvaluator.d.ts.map +1 -1
  113. package/dist/src/compiler/CubeEvaluator.js +15 -15
  114. package/dist/src/compiler/CubeEvaluator.js.map +1 -1
  115. package/dist/src/compiler/CubeSymbols.d.ts +50 -14
  116. package/dist/src/compiler/CubeSymbols.d.ts.map +1 -1
  117. package/dist/src/compiler/CubeSymbols.js +17 -7
  118. package/dist/src/compiler/CubeSymbols.js.map +1 -1
  119. package/dist/src/compiler/CubeToMetaTransformer.d.ts +2 -1
  120. package/dist/src/compiler/CubeToMetaTransformer.d.ts.map +1 -1
  121. package/dist/src/compiler/CubeToMetaTransformer.js.map +1 -1
  122. package/dist/src/compiler/CubeValidator.d.ts +3 -2
  123. package/dist/src/compiler/CubeValidator.d.ts.map +1 -1
  124. package/dist/src/compiler/CubeValidator.js +2 -0
  125. package/dist/src/compiler/CubeValidator.js.map +1 -1
  126. package/dist/src/compiler/DataSchemaCompiler.d.ts +7 -3
  127. package/dist/src/compiler/DataSchemaCompiler.d.ts.map +1 -1
  128. package/dist/src/compiler/DataSchemaCompiler.js +10 -0
  129. package/dist/src/compiler/DataSchemaCompiler.js.map +1 -1
  130. package/dist/src/compiler/JoinGraph.d.ts +2 -1
  131. package/dist/src/compiler/JoinGraph.d.ts.map +1 -1
  132. package/dist/src/compiler/JoinGraph.js +24 -34
  133. package/dist/src/compiler/JoinGraph.js.map +1 -1
  134. package/dist/src/compiler/PrepareCompiler.d.ts +19 -3
  135. package/dist/src/compiler/PrepareCompiler.d.ts.map +1 -1
  136. package/dist/src/compiler/PrepareCompiler.js +33 -4
  137. package/dist/src/compiler/PrepareCompiler.js.map +1 -1
  138. package/dist/src/compiler/StringInterning.js.map +1 -1
  139. package/dist/src/compiler/YamlCompiler.d.ts.map +1 -1
  140. package/dist/src/compiler/YamlCompiler.js +1 -0
  141. package/dist/src/compiler/YamlCompiler.js.map +1 -1
  142. package/dist/src/compiler/index.d.ts +1 -1
  143. package/dist/src/compiler/index.d.ts.map +1 -1
  144. package/dist/src/compiler/index.js.map +1 -1
  145. package/dist/src/compiler/transpilers/CubePropContextTranspiler.d.ts +1 -1
  146. package/dist/src/compiler/transpilers/CubePropContextTranspiler.d.ts.map +1 -1
  147. package/dist/src/compiler/transpilers/CubePropContextTranspiler.js +2 -2
  148. package/dist/src/compiler/transpilers/CubePropContextTranspiler.js.map +1 -1
  149. package/dist/src/compiler/transpilers/LightweightSymbolResolver.d.ts +2 -2
  150. package/dist/src/compiler/transpilers/LightweightSymbolResolver.d.ts.map +1 -1
  151. package/dist/src/compiler/transpilers/LightweightSymbolResolver.js +1 -1
  152. package/dist/src/compiler/transpilers/LightweightSymbolResolver.js.map +1 -1
  153. package/dist/src/compiler/transpilers/transpiler_worker.js.map +1 -1
  154. package/dist/src/compiler/utils.d.ts.map +1 -1
  155. package/dist/src/compiler/utils.js +5 -4
  156. package/dist/src/compiler/utils.js.map +1 -1
  157. package/dist/src/extensions/Funnels.d.ts +22 -6
  158. package/dist/src/extensions/Funnels.d.ts.map +1 -1
  159. package/dist/src/extensions/Funnels.js +4 -2
  160. package/dist/src/extensions/Funnels.js.map +1 -1
  161. package/dist/src/extensions/Reflection.d.ts.map +1 -1
  162. package/dist/src/extensions/Reflection.js +1 -0
  163. package/dist/src/extensions/Reflection.js.map +1 -1
  164. package/dist/src/extensions/RefreshKeys.d.ts +3 -2
  165. package/dist/src/extensions/RefreshKeys.d.ts.map +1 -1
  166. package/dist/src/extensions/RefreshKeys.js.map +1 -1
  167. package/dist/src/parser/PythonParser.d.ts.map +1 -1
  168. package/dist/src/parser/PythonParser.js.map +1 -1
  169. package/dist/src/parser/SqlParser.d.ts +2 -2
  170. package/dist/src/parser/SqlParser.d.ts.map +1 -1
  171. package/dist/src/parser/SqlParser.js.map +1 -1
  172. package/dist/src/scaffolding/ScaffoldingSchema.d.ts +4 -3
  173. package/dist/src/scaffolding/ScaffoldingSchema.d.ts.map +1 -1
  174. package/dist/src/scaffolding/ScaffoldingSchema.js +27 -18
  175. package/dist/src/scaffolding/ScaffoldingSchema.js.map +1 -1
  176. package/dist/src/scaffolding/ScaffoldingTemplate.d.ts +1 -1
  177. package/dist/src/scaffolding/ScaffoldingTemplate.d.ts.map +1 -1
  178. package/dist/src/scaffolding/ScaffoldingTemplate.js +3 -1
  179. package/dist/src/scaffolding/ScaffoldingTemplate.js.map +1 -1
  180. package/dist/src/scaffolding/descriptors/MemberReference.d.ts +2 -2
  181. package/dist/src/scaffolding/descriptors/MemberReference.d.ts.map +1 -1
  182. package/dist/src/scaffolding/descriptors/MemberReference.js.map +1 -1
  183. package/dist/src/scaffolding/formatters/BaseSchemaFormatter.d.ts +9 -5
  184. package/dist/src/scaffolding/formatters/BaseSchemaFormatter.d.ts.map +1 -1
  185. package/dist/src/scaffolding/formatters/BaseSchemaFormatter.js +2 -5
  186. package/dist/src/scaffolding/formatters/BaseSchemaFormatter.js.map +1 -1
  187. package/dist/src/scaffolding/formatters/JavaScriptSchemaFormatter.js.map +1 -1
  188. package/dist/src/scaffolding/formatters/YamlSchemaFormatter.d.ts +2 -1
  189. package/dist/src/scaffolding/formatters/YamlSchemaFormatter.d.ts.map +1 -1
  190. package/dist/src/scaffolding/formatters/YamlSchemaFormatter.js +14 -4
  191. package/dist/src/scaffolding/formatters/YamlSchemaFormatter.js.map +1 -1
  192. package/dist/src/scaffolding/utils.d.ts +1 -0
  193. package/dist/src/scaffolding/utils.d.ts.map +1 -1
  194. package/dist/src/scaffolding/utils.js +7 -1
  195. package/dist/src/scaffolding/utils.js.map +1 -1
  196. package/package.json +9 -9
@@ -28,6 +28,7 @@ const BaseTimeDimension_1 = require("./BaseTimeDimension");
28
28
  const Granularity_1 = require("./Granularity");
29
29
  const ParamAllocator_1 = require("./ParamAllocator");
30
30
  const PreAggregations_1 = require("./PreAggregations");
31
+ const MemberSqlTemplateCompiler_1 = require("./MemberSqlTemplateCompiler");
31
32
  const DEFAULT_PREAGGREGATIONS_SCHEMA = 'stb_pre_aggregations';
32
33
  const standardGranularitiesParents = {
33
34
  year: ['year', 'quarter', 'month', 'day', 'hour', 'minute', 'second'],
@@ -46,31 +47,6 @@ const SecondsDurations = {
46
47
  minute: 60,
47
48
  second: 1
48
49
  };
49
- /**
50
- * Set of the schema compilers.
51
- * @typedef {Object} Compilers
52
- * @property {import('../compiler/DataSchemaCompiler').DataSchemaCompiler} compiler
53
- * @property {import('../compiler/CubeToMetaTransformer').CubeToMetaTransformer} metaTransformer
54
- * @property {import('../compiler/CubeEvaluator').CubeEvaluator} cubeEvaluator
55
- * @property {import('../compiler/ContextEvaluator').ContextEvaluator} contextEvaluator
56
- * @property {import('../compiler/JoinGraph').JoinGraph} joinGraph
57
- * @property {import('../compiler/CompilerCache').CompilerCache} compilerCache
58
- * @property {*} headCommitId
59
- */
60
- /**
61
- * @typedef {Object} JoinRoot
62
- * @property {string} sql
63
- * @property {string} alias
64
- */
65
- /**
66
- * @typedef {Object} JoinItem
67
- * @property {string} sql
68
- * @property {string} alias
69
- * @property {string} on
70
- */
71
- /**
72
- * @typedef {[JoinRoot, ...JoinItem]} JoinChain
73
- */
74
50
  /**
75
51
  * BaseQuery class. BaseQuery object encapsulates the logic of
76
52
  * transforming an incoming to a specific cube request to the
@@ -85,41 +61,61 @@ const SecondsDurations = {
85
61
  * and {@code CompilerApi} configuration.
86
62
  */
87
63
  class BaseQuery {
88
- /** @type {import('./PreAggregations').PreAggregations} */
89
64
  preAggregations;
90
- /** @type {import('./BaseMeasure').BaseMeasure[]} */
91
65
  measures;
92
- /** @type {import('./BaseDimension').BaseDimension[]} */
93
66
  dimensions;
94
- /** @type {import('./BaseDimension').BaseDimension[]} */
95
67
  multiStageDimensions;
96
- /** @type {import('./BaseTimeDimension').BaseTimeDimension[]} */
97
68
  multiStageTimeDimensions;
98
- /** @type {import('./BaseSegment').BaseSegment[]} */
99
69
  segments;
100
- /** @type {(BaseFilter|BaseGroupFilter)[]} */
101
70
  filters;
102
- /** @type {(BaseFilter|BaseGroupFilter)[]} */
103
71
  measureFilters;
104
- /** @type {import('./BaseTimeDimension').BaseTimeDimension[]} */
105
72
  timeDimensions;
106
- /** @type {import('../compiler/JoinGraph').FinishedJoinTree} */
107
- join;
73
+ join = null;
74
+ compilers;
75
+ cubeEvaluator;
76
+ joinGraph;
77
+ options;
78
+ paramAllocator;
79
+ contextSymbols;
80
+ maskedMembers;
81
+ memberMaskFilters;
82
+ compilerCache;
83
+ queryCache;
84
+ from;
85
+ multiStageQuery;
86
+ timezone;
87
+ rowLimit;
88
+ offset;
89
+ allFilters;
108
90
  /**
109
- * BaseQuery class constructor.
110
- * @param {Compilers|*} compilers
111
- * @param {*} options
91
+ * For now this might come only from SQL API, it might be some queries that uses measures and filters to
92
+ * get the dimensions that are then used as join conditions to get the final results.
93
+ * As consequence - if there are such sub query joins - pre-aggregations can't be used.
112
94
  */
95
+ customSubQueryJoins;
96
+ useNativeSqlPlanner;
97
+ canUseNativeSqlPlannerPreAggregation;
98
+ localRefreshKey;
99
+ queryLevelJoinHints;
100
+ cubeAliasPrefix;
101
+ preAggregationsSchemaOption;
102
+ externalQueryClass;
103
+ order;
104
+ joinGraphPaths = null;
105
+ collectedCubeNames = null;
106
+ collectedJoinHints = null;
107
+ ungrouped;
108
+ _subQueryDimensions;
109
+ filtersWithoutSubQueriesValue;
110
+ evaluateSymbolContext;
111
+ parametrizedContextSymbolsValue;
113
112
  constructor(compilers, options) {
114
113
  this.compilers = compilers;
115
- /** @type {import('../compiler/CubeEvaluator').CubeEvaluator} */
116
114
  this.cubeEvaluator = compilers.cubeEvaluator;
117
- /** @type {import('../compiler/JoinGraph').JoinGraph} */
118
115
  this.joinGraph = compilers.joinGraph;
119
116
  this.options = options || {};
120
117
  this.orderHashToString = this.orderHashToString.bind(this);
121
118
  this.defaultOrder = this.defaultOrder.bind(this);
122
- /** @type {ParamAllocator} */
123
119
  this.paramAllocator = this.options.paramAllocator || this.newParamAllocator(this.options.expressionParams);
124
120
  this.initFromOptions();
125
121
  }
@@ -148,7 +144,8 @@ class BaseQuery {
148
144
  return allFilters;
149
145
  }
150
146
  keepFilters(filters = [], fn) {
151
- return filters.map(f => {
147
+ // `any`: the member guard below can't narrow `f.member || f.dimension` to a string
148
+ return filters.map((f) => {
152
149
  if (f.and) {
153
150
  return { and: this.keepFilters(f.and, fn) };
154
151
  }
@@ -161,13 +158,14 @@ class BaseQuery {
161
158
  else {
162
159
  return fn(f.member || f.dimension || f.measure) ? f : null;
163
160
  }
164
- }).filter(f => !!f);
161
+ }).filter((f) => !!f);
165
162
  }
166
163
  extractFiltersAsTree(filters = []) {
167
164
  if (!filters) {
168
165
  return [];
169
166
  }
170
- return filters.map(f => {
167
+ // `any`: the member guard below can't narrow `f.member || f.dimension` to a string
168
+ return filters.map((f) => {
171
169
  if (f.and || f.or) {
172
170
  let operator = 'or';
173
171
  if (f.and) {
@@ -215,9 +213,6 @@ class BaseQuery {
215
213
  });
216
214
  });
217
215
  }
218
- /**
219
- * @protected
220
- */
221
216
  initFromOptions() {
222
217
  this.contextSymbols = {
223
218
  securityContext: {},
@@ -279,26 +274,17 @@ class BaseQuery {
279
274
  }
280
275
  this.rowLimit = this.options.rowLimit;
281
276
  this.offset = this.options.offset;
282
- /** @type {import('./PreAggregations').PreAggregations} */
283
277
  this.preAggregations = this.newPreAggregations();
284
- /** @type {import('./BaseMeasure').BaseMeasure[]} */
285
278
  this.measures = (this.options.measures || []).map(this.newMeasure.bind(this));
286
- /** @type {import('./BaseDimension').BaseDimension[]} */
287
279
  this.dimensions = (this.options.dimensions || []).map(this.newDimension.bind(this));
288
- /** @type {import('./BaseDimension').BaseDimension[]} */
289
280
  this.multiStageDimensions = (this.options.multiStageDimensions || []).map(this.newDimension.bind(this));
290
- /** @type {import('./BaseTimeDimension').BaseTimeDimension[]} */
291
281
  this.multiStageTimeDimensions = (this.options.multiStageTimeDimensions || []).map(this.newTimeDimension.bind(this));
292
- /** @type {import('./BaseSegment').BaseSegment[]} */
293
282
  this.segments = (this.options.segments || []).map(this.newSegment.bind(this));
294
283
  const filters = this.extractFiltersAsTree(this.options.filters || []);
295
284
  // measure_filter (the one extracted from filters parameter on measure and
296
285
  // used in drill-downs) should go to WHERE instead of HAVING
297
- /** @type {(BaseFilter|BaseGroupFilter)[]} */
298
286
  this.filters = filters.filter(f => f.dimensionGroup || f.dimension || f.operator === 'measure_filter' || f.operator === 'measureFilter').map(this.initFilter.bind(this));
299
- /** @type {(BaseFilter|BaseGroupFilter)[]} */
300
287
  this.measureFilters = filters.filter(f => (f.measureGroup || f.measure) && f.operator !== 'measure_filter' && f.operator !== 'measureFilter').map(this.initFilter.bind(this));
301
- /** @type {import('./BaseTimeDimension').BaseTimeDimension[]} */
302
288
  this.timeDimensions = (this.options.timeDimensions || []).map(dimension => {
303
289
  if (!dimension.dimension) {
304
290
  const join = this.joinGraph.buildJoin(this.collectJoinHints(true));
@@ -314,12 +300,6 @@ class BaseQuery {
314
300
  return dimension;
315
301
  }).filter(ramda_1.default.identity).map(this.newTimeDimension.bind(this));
316
302
  this.allFilters = this.timeDimensions.concat(this.segments).concat(this.filters);
317
- /**
318
- * For now this might come only from SQL API, it might be some queries that uses measures and filters to
319
- * get the dimensions that are then used as join conditions to get the final results.
320
- * As consequence - if there are such sub query joins - pre-aggregations can't be used.
321
- * @type {Array<{sql: string, on: {expression: Function}, joinType: 'LEFT' | 'INNER', alias: string}>}
322
- */
323
303
  this.customSubQueryJoins = this.options.subqueryJoins ?? [];
324
304
  this.useNativeSqlPlanner = this.options.useNativeSqlPlanner ?? (0, shared_1.getEnv)('nativeSqlPlanner');
325
305
  // Tesseract pre-aggregation planning always follows the SQL planner and can't be
@@ -330,7 +310,15 @@ class BaseQuery {
330
310
  // byte-identical and nothing downstream re-hashes to a new cache key.
331
311
  this.localRefreshKey = this.options.localRefreshKey ?? (0, shared_1.getEnv)('refreshKeyLocalTime');
332
312
  this.queryLevelJoinHints = this.options.joinHints ?? [];
333
- this.prebuildJoin();
313
+ if (this.options.plan) {
314
+ this.collectedJoinHints = this.options.plan.joinHints;
315
+ this.join = this.options.plan.join;
316
+ this.joinGraphPaths = this.options.plan.joinGraphPaths;
317
+ this.collectedCubeNames = this.options.plan.cubeNames;
318
+ }
319
+ else {
320
+ this.prebuildJoin();
321
+ }
334
322
  this.cubeAliasPrefix = this.options.cubeAliasPrefix;
335
323
  this.preAggregationsSchemaOption = this.options.preAggregationsSchema ?? DEFAULT_PREAGGREGATIONS_SCHEMA;
336
324
  this.externalQueryClass = this.options.externalQueryClass;
@@ -347,9 +335,6 @@ class BaseQuery {
347
335
  try {
348
336
  // TODO allJoinHints should contain join hints form pre-agg
349
337
  this.join = this.joinGraph.buildJoin(this.allJoinHints);
350
- /**
351
- * @type {Record<string, string[]>}
352
- */
353
338
  const queryJoinGraph = {};
354
339
  for (const { originalFrom, originalTo } of (this.join?.joins || [])) {
355
340
  if (!queryJoinGraph[originalFrom]) {
@@ -373,9 +358,6 @@ class BaseQuery {
373
358
  * Same as joinTreeForHints(), but returns an empty list instead of throwing when the join graph
374
359
  * has no path covering the hints, and a single-element list otherwise. An exception thrown into
375
360
  * the native planner stays pending there, so it can't probe hint sets by catching.
376
- * @public
377
- * @param {Array<(Array<string> | string)>} hints
378
- * @return {Array<import('../compiler/JoinGraph').FinishedJoinTree>}
379
361
  */
380
362
  tryJoinTreeForHints(hints) {
381
363
  try {
@@ -391,10 +373,6 @@ class BaseQuery {
391
373
  /**
392
374
  * This function follows the same logic as in this.collectJoinHints()
393
375
  * skipQueryJoinMap is used by PreAggregations to build join tree without user's query all members map
394
- * @public
395
- * @param {Array<(Array<string> | string)>} hints
396
- * @param { boolean } skipQueryJoinMap
397
- * @return {import('../compiler/JoinGraph').FinishedJoinTree}
398
376
  */
399
377
  joinTreeForHints(hints, skipQueryJoinMap = false) {
400
378
  const queryJoinMaps = skipQueryJoinMap ? {} : this.queryJoinMap();
@@ -469,20 +447,12 @@ class BaseQuery {
469
447
  }
470
448
  return this.collectedCubeNames;
471
449
  }
472
- /**
473
- *
474
- * @returns {Array<string | Array<string>>}
475
- */
476
450
  get allJoinHints() {
477
451
  if (!this.collectedJoinHints) {
478
452
  this.collectedJoinHints = this.collectJoinHints();
479
453
  }
480
454
  return this.collectedJoinHints;
481
455
  }
482
- /**
483
- * @private
484
- * @return { Record<string, string[][]>}
485
- */
486
456
  queryJoinMap() {
487
457
  const queryMembers = this.allMembersConcat(false);
488
458
  const joinMaps = {};
@@ -494,12 +464,6 @@ class BaseQuery {
494
464
  }
495
465
  return joinMaps;
496
466
  }
497
- /**
498
- * @protected
499
- * @param { import('../compiler/JoinGraph').FinishedJoinTree } joinTree
500
- * @param { string[] } joinHints
501
- * @return { (string|string[])[] }
502
- */
503
467
  enrichedJoinHintsFromJoinTree(joinTree, joinHints) {
504
468
  // The tree can hold two edges into one cube. The later edge wins so the next pass follows the
505
469
  // later hint (e.g. a view's join path), unless it closes a cycle (hint `c -> b` when `c` is
@@ -514,11 +478,9 @@ class BaseQuery {
514
478
  this.joinPathsToRoot(this.acyclicJoinsMap(joinTree), joinHints, maxPathLength);
515
479
  }
516
480
  /**
517
- * @private
518
- * @param { Record<string, string> } joinsMap cube -> the cube it is joined from
519
- * @param { string[] } joinHints
520
- * @param { number } maxPathLength a longer chain must have looped
521
- * @return { (string|string[])[] | null } null when the chain of some hint loops
481
+ * @param joinsMap cube -> the cube it is joined from
482
+ * @param maxPathLength a longer chain must have looped
483
+ * @return null when the chain of some hint loops
522
484
  */
523
485
  joinPathsToRoot(joinsMap, joinHints, maxPathLength) {
524
486
  const paths = [];
@@ -536,11 +498,6 @@ class BaseQuery {
536
498
  }
537
499
  return paths;
538
500
  }
539
- /**
540
- * @private
541
- * @param { import('../compiler/JoinGraph').FinishedJoinTree } joinTree
542
- * @return { Record<string, string> }
543
- */
544
501
  acyclicJoinsMap(joinTree) {
545
502
  const joinsMap = {};
546
503
  for (const j of joinTree.joins) {
@@ -554,12 +511,6 @@ class BaseQuery {
554
511
  }
555
512
  return joinsMap;
556
513
  }
557
- /**
558
- * @private
559
- * @param { (string|string[])[] } hints
560
- * @param { Record<string, string[][]>} joinMap
561
- * @return {(string|string[])[]}
562
- */
563
514
  enrichHintsWithJoinMap(hints, joinMap) {
564
515
  // Potentially, if joins between views would take place, we need to distinguish
565
516
  // join maps on per view basis.
@@ -577,7 +528,19 @@ class BaseQuery {
577
528
  return hint;
578
529
  });
579
530
  }
531
+ plan() {
532
+ return {
533
+ joinHints: this.collectedJoinHints,
534
+ join: this.join,
535
+ joinGraphPaths: this.joinGraphPaths,
536
+ cubeNames: this.allCubeNames,
537
+ dataSource: this.detectDataSource() ?? null,
538
+ };
539
+ }
580
540
  get dataSource() {
541
+ return this.options.dataSource ?? this.detectDataSource();
542
+ }
543
+ detectDataSource() {
581
544
  const dataSources = ramda_1.default.uniq(this.allCubeNames.map(c => this.cubeDataSource(c)));
582
545
  if (dataSources.length > 1 && !this.externalPreAggregationQuery()) {
583
546
  throw new UserError_1.UserError(`To join across data sources use rollupJoin with Cube Store. If rollupJoin is defined, this error indicates it doesn't match the query. Please use Rollup Designer to verify it's definition. Found data sources: ${dataSources.join(', ')}`);
@@ -588,15 +551,13 @@ class BaseQuery {
588
551
  return this.cubeEvaluator.cubeDataSource(cube);
589
552
  }
590
553
  get aliasNameToMember() {
591
- return ramda_1.default.fromPairs(this.measures.map(m => [m.unescapedAliasName(), m.memberPath()]).concat(this.dimensions.map(m => [m.unescapedAliasName(), m.memberPath()])).concat(this.timeDimensions.filter(m => !!m.granularity)
592
- .map(m => [m.unescapedAliasName(), `${m.memberPath()}.${m.granularity}`])));
554
+ return ramda_1.default.fromPairs(this.measures.map((m) => [m.unescapedAliasName(), m.memberPath()]).concat(this.dimensions.map((m) => [m.unescapedAliasName(), m.memberPath()])).concat(this.timeDimensions.filter(m => !!m.granularity)
555
+ .map((m) => [m.unescapedAliasName(), `${m.memberPath()}.${m.granularity}`])));
593
556
  }
594
557
  /**
595
558
  * Splits a member path into the data-model member and the join hint to it.
596
559
  * Through a join alias the model knows the member by its target path, and the
597
560
  * path itself names the member's output.
598
- * @param {string} path
599
- * @returns {{ path: string, joinHint: string[], aliasPath?: string }}
600
561
  */
601
562
  memberPathForModel(path) {
602
563
  const resolved = this.cubeEvaluator.resolveMemberPath(path);
@@ -669,19 +630,9 @@ class BaseQuery {
669
630
  }
670
631
  return res;
671
632
  }
672
- /**
673
- *
674
- * @param measurePath
675
- * @returns {BaseMeasure}
676
- */
677
633
  newMeasure(measurePath) {
678
634
  return new BaseMeasure_1.BaseMeasure(this, measurePath);
679
635
  }
680
- /**
681
- *
682
- * @param dimensionPath
683
- * @returns {BaseDimension}
684
- */
685
636
  newDimension(dimensionPath) {
686
637
  if (typeof dimensionPath === 'string') {
687
638
  const memberArr = dimensionPath.split('.');
@@ -696,17 +647,10 @@ class BaseQuery {
696
647
  }
697
648
  return new BaseDimension_1.BaseDimension(this, dimensionPath);
698
649
  }
699
- /**
700
- *
701
- * @param segmentPath
702
- * @returns {BaseSegment}
703
- */
704
650
  newSegment(segmentPath) {
705
651
  return new BaseSegment_1.BaseSegment(this, segmentPath);
706
652
  }
707
- /**
708
- * @returns {BaseGroupFilter|BaseFilter}
709
- */
653
+ // `any`: a group's `values` holds tree items until they are replaced in place with initialized filters
710
654
  initFilter(filter) {
711
655
  if (filter.operator === 'and' || filter.operator === 'or') {
712
656
  filter.values = filter.values.map(this.initFilter.bind(this));
@@ -714,53 +658,29 @@ class BaseQuery {
714
658
  }
715
659
  return this.newFilter(filter);
716
660
  }
717
- /**
718
- * @returns {BaseFilter}
719
- */
720
661
  newFilter(filter) {
721
662
  return new BaseFilter_1.BaseFilter(this, filter);
722
663
  }
723
- /**
724
- *
725
- * @param filter
726
- * @returns {BaseGroupFilter}
727
- */
728
664
  newGroupFilter(filter) {
729
665
  return new BaseGroupFilter_1.BaseGroupFilter(filter);
730
666
  }
731
- /**
732
- * @param timeDimension
733
- * @return {BaseTimeDimension}
734
- */
735
667
  newTimeDimension(timeDimension) {
736
668
  return new BaseTimeDimension_1.BaseTimeDimension(this, timeDimension);
737
669
  }
738
- /**
739
- *
740
- * @param expressionParams
741
- * @returns {ParamAllocator}
742
- */
743
670
  newParamAllocator(expressionParams) {
744
671
  return new ParamAllocator_1.ParamAllocator(expressionParams);
745
672
  }
746
- /**
747
- *
748
- * @returns {PreAggregations}
749
- */
750
673
  newPreAggregations() {
751
674
  return new PreAggregations_1.PreAggregations(this, this.options.historyQueries || [], this.options.cubeLatticeCache);
752
675
  }
753
676
  /**
754
677
  * Wrap specified column/table name with the double quote.
755
- * @param {string} name
756
- * @returns {string}
757
678
  */
758
679
  escapeColumnName(name) {
759
680
  return `"${name}"`;
760
681
  }
761
682
  /**
762
683
  * Returns SQL query string.
763
- * @returns {string}
764
684
  */
765
685
  buildParamAnnotatedSql() {
766
686
  let sql;
@@ -796,8 +716,6 @@ class BaseQuery {
796
716
  /**
797
717
  * Generate SQL query to calculate total number of rows of the
798
718
  * specified SQL query.
799
- * @param {string} sql
800
- * @returns {string}
801
719
  */
802
720
  countAllQuery(sql) {
803
721
  return `select count(*) ${this.escapeColumnName(shared_1.QueryAlias.TOTAL_COUNT)} from (\n${sql}\n) ${this.escapeColumnName(shared_1.QueryAlias.ORIGINAL_QUERY)}`;
@@ -823,13 +741,13 @@ class BaseQuery {
823
741
  return false;
824
742
  }
825
743
  newQueryWithoutNative() {
826
- const QueryClass = this.constructor;
827
- return new QueryClass(this.compilers, { ...this.options, useNativeSqlPlanner: false });
744
+ // A Tesseract plan may have no join (prebuildJoin() swallows the error for it),
745
+ // and the legacy planner needs one, so it builds its own
746
+ return this.compilers.createQuery(this.constructor, { ...this.options, useNativeSqlPlanner: false, plan: undefined });
828
747
  }
829
748
  /**
830
749
  * Returns a pair of SQL query string and parameter values for the query.
831
- * @param {boolean} [exportAnnotatedSql] - returns annotated sql with not rendered params if true
832
- * @returns {[string, Array<unknown>]}
750
+ * @param exportAnnotatedSql - returns annotated sql with not rendered params if true
833
751
  */
834
752
  buildSqlAndParams(exportAnnotatedSql) {
835
753
  if (this.useNativeSqlPlanner) {
@@ -906,11 +824,12 @@ class BaseQuery {
906
824
  maskedMembers: this.options.maskedMembers,
907
825
  memberToAlias: this.options.memberToAlias,
908
826
  subqueryJoins: this.options.subqueryJoins,
827
+ dataSource: this.options.dataSource ?? null,
909
828
  };
910
829
  try {
911
830
  // Establish the current query context, JS extensions like Funnels/RefreshKeys can resolve compiler.contextQuery()
912
831
  // during the member-SQL callbacks the native planner makes back into JS.
913
- const buildResult = this.compilers.compiler.withQuery(this, () => (0, native_1.buildSqlAndParams)(queryParams));
832
+ const buildResult = this.compilers.compiler.withQuery(this, () => (0, native_1.buildSqlAndParams)(queryParams, this.compilers.compiler.modelContext));
914
833
  const [query, params, preAggResult] = buildResult;
915
834
  const paramsArray = [...params];
916
835
  this.applyNativePreAggResult(preAggResult);
@@ -924,7 +843,6 @@ class BaseQuery {
924
843
  }
925
844
  }
926
845
  // FIXME Temporary solution
927
- /** @returns {import('./PreAggregations').PreAggregationForQuery | undefined} */
928
846
  findPreAggregationForQueryRust() {
929
847
  let optionsOrder = this.options.order;
930
848
  if (optionsOrder && !Array.isArray(optionsOrder)) {
@@ -967,8 +885,9 @@ class BaseQuery {
967
885
  // must see the same masked members as the SQL build.
968
886
  maskedMembers: this.options.maskedMembers,
969
887
  subqueryJoins: this.options.subqueryJoins,
888
+ dataSource: this.options.dataSource ?? null,
970
889
  };
971
- const buildResult = (0, native_1.buildSqlAndParams)(queryParams);
890
+ const buildResult = (0, native_1.buildSqlAndParams)(queryParams, this.compilers.compiler.modelContext);
972
891
  const [, , preAggResult] = buildResult;
973
892
  return this.applyNativePreAggResult(preAggResult);
974
893
  }
@@ -1005,7 +924,6 @@ class BaseQuery {
1005
924
  }
1006
925
  /**
1007
926
  * Returns a dictionary mapping each preagregation to its corresponding query fragment.
1008
- * @returns {Record<string, Array<string>>}
1009
927
  */
1010
928
  buildLambdaQuery() {
1011
929
  const preAggForQuery = this.preAggregations.findPreAggregationForQuery();
@@ -1055,10 +973,11 @@ class BaseQuery {
1055
973
  return result;
1056
974
  }
1057
975
  externalQuery() {
1058
- const ExternalQuery = this.externalQueryClass;
1059
- return new ExternalQuery(this.compilers, {
976
+ return this.compilers.createQuery(this.externalQueryClass, {
1060
977
  ...this.options,
1061
- externalQueryClass: null
978
+ externalQueryClass: null,
979
+ // Renders the same data source in another dialect
980
+ dataSource: undefined,
1062
981
  });
1063
982
  }
1064
983
  rollingWindowToDateJoinCondition(granularity) {
@@ -1071,7 +990,7 @@ class BaseQuery {
1071
990
  acc[key] = td;
1072
991
  }
1073
992
  return acc;
1074
- }, {})).map(d => [
993
+ }, {})).map((d) => [
1075
994
  d,
1076
995
  (dateFrom, dateTo, dateField, _dimensionDateFrom, _dimensionDateTo, _isFromStartToEnd) => `${dateField} >= ${this.timeGroupedColumn(granularity, dateFrom)} AND ${dateField} <= ${dateTo}`
1077
996
  ]);
@@ -1088,7 +1007,7 @@ class BaseQuery {
1088
1007
  }
1089
1008
  return acc;
1090
1009
  }, {}))
1091
- .map(d => [d, (dateFrom, dateTo, dateField, _dimensionDateFrom, _dimensionDateTo, isFromStartToEnd) => {
1010
+ .map((d) => [d, (dateFrom, dateTo, dateField, _dimensionDateFrom, _dimensionDateTo, isFromStartToEnd) => {
1092
1011
  // dateFrom based window
1093
1012
  const conditions = [];
1094
1013
  if (trailingInterval !== 'unbounded') {
@@ -1106,20 +1025,10 @@ class BaseQuery {
1106
1025
  return conditions.length ? conditions.join(' AND ') : '1 = 1';
1107
1026
  }]);
1108
1027
  }
1109
- /**
1110
- * @param {string} date
1111
- * @param {string} interval
1112
- * @returns {string}
1113
- */
1114
1028
  subtractInterval(date, interval) {
1115
1029
  const intervalStr = this.intervalString(interval);
1116
1030
  return `${date} - interval ${intervalStr}`;
1117
1031
  }
1118
- /**
1119
- * @param {string} date
1120
- * @param {string} interval
1121
- * @returns {string}
1122
- */
1123
1032
  addInterval(date, interval) {
1124
1033
  const intervalStr = this.intervalString(interval);
1125
1034
  return `${date} + interval ${intervalStr}`;
@@ -1128,26 +1037,12 @@ class BaseQuery {
1128
1037
  supportGeneratedSeriesForCustomTd() {
1129
1038
  return false;
1130
1039
  }
1131
- /**
1132
- * @param {string} interval
1133
- * @returns {string}
1134
- */
1135
1040
  intervalString(interval) {
1136
1041
  return `'${interval}'`;
1137
1042
  }
1138
- /**
1139
- * @param {string} timestamp
1140
- * @param {string} interval
1141
- * @returns {string}
1142
- */
1143
1043
  addTimestampInterval(timestamp, interval) {
1144
1044
  return this.addInterval(timestamp, interval);
1145
1045
  }
1146
- /**
1147
- * @param {string} timestamp
1148
- * @param {string} interval
1149
- * @returns {string}
1150
- */
1151
1046
  subtractTimestampInterval(timestamp, interval) {
1152
1047
  return this.subtractInterval(timestamp, interval);
1153
1048
  }
@@ -1172,7 +1067,6 @@ class BaseQuery {
1172
1067
  }
1173
1068
  /**
1174
1069
  * Returns SQL query string.
1175
- * @returns {string}
1176
1070
  */
1177
1071
  fullKeyQueryAggregate() {
1178
1072
  if (this.from) {
@@ -1194,14 +1088,14 @@ class BaseQuery {
1194
1088
  toJoin = (allRegular.length ? [
1195
1089
  this.withCubeAliasPrefix('main', () => this.regularMeasuresSubQuery(allRegular))
1196
1090
  ] : [])
1197
- .concat(ramda_1.default.pipe(ramda_1.default.groupBy(m => m.cube().name), ramda_1.default.toPairs, ramda_1.default.map(([keyCubeName, measures]) => this.withCubeAliasPrefix(`${keyCubeName}_key`, () => this.aggregateSubQuery(keyCubeName, measures))))(allMultiplied));
1091
+ .concat(ramda_1.default.pipe(ramda_1.default.groupBy((m) => m.cube().name), ramda_1.default.toPairs, ramda_1.default.map(([keyCubeName, measures]) => this.withCubeAliasPrefix(`${keyCubeName}_key`, () => this.aggregateSubQuery(keyCubeName, measures))))(allMultiplied));
1198
1092
  }
1199
1093
  else {
1200
1094
  toJoin =
1201
1095
  (regularMeasures.length ? [
1202
1096
  this.withCubeAliasPrefix('main', () => this.regularMeasuresSubQuery(regularMeasures)),
1203
1097
  ] : [])
1204
- .concat(ramda_1.default.pipe(ramda_1.default.groupBy(m => m.cube().name), ramda_1.default.toPairs, ramda_1.default.map(([keyCubeName, measures]) => this
1098
+ .concat(ramda_1.default.pipe(ramda_1.default.groupBy((m) => m.cube().name), ramda_1.default.toPairs, ramda_1.default.map(([keyCubeName, measures]) => this
1205
1099
  .withCubeAliasPrefix(`${this.aliasName(keyCubeName)}_key`, () => this.aggregateSubQuery(keyCubeName, measures))))(multipliedMeasures)).concat(ramda_1.default.map(([multiplied, measure]) => this.withCubeAliasPrefix(`${this.aliasName(measure.measure.replace('.', '_'))}_cumulative`, () => this.overTimeSeriesQuery(multiplied
1206
1100
  ? (measures, filters) => this.aggregateSubQuery(measures[0].cube().name, measures, filters)
1207
1101
  : this.regularMeasuresSubQuery.bind(this), measure, false)))(cumulativeMeasures)
@@ -1214,7 +1108,7 @@ class BaseQuery {
1214
1108
  if (regularMeasures.length &&
1215
1109
  multipliedMeasures.length &&
1216
1110
  !cumulativeMeasures.length) {
1217
- const cubeNames = ramda_1.default.pipe(ramda_1.default.map(m => m.cube().name), ramda_1.default.uniq, ramda_1.default.sortBy(ramda_1.default.identity));
1111
+ const cubeNames = ramda_1.default.pipe(ramda_1.default.map((m) => m.cube().name), ramda_1.default.uniq, ramda_1.default.sortBy(ramda_1.default.identity));
1218
1112
  const regularMeasuresCubes = cubeNames(regularMeasures);
1219
1113
  const multipliedMeasuresCubes = cubeNames(multipliedMeasures);
1220
1114
  if (ramda_1.default.equals(regularMeasuresCubes, multipliedMeasuresCubes)) {
@@ -1234,7 +1128,7 @@ class BaseQuery {
1234
1128
  });
1235
1129
  return i1 - i2;
1236
1130
  });
1237
- toJoin = ramda_1.default.pipe(ramda_1.default.groupBy(m => m.cube().name), ramda_1.default.toPairs, ramda_1.default.map(([keyCubeName, measures]) => this.withCubeAliasPrefix(`${keyCubeName}_key`, () => this.aggregateSubQuery(keyCubeName, measures))))(measuresList);
1131
+ toJoin = ramda_1.default.pipe(ramda_1.default.groupBy((m) => m.cube().name), ramda_1.default.toPairs, ramda_1.default.map(([keyCubeName, measures]) => this.withCubeAliasPrefix(`${keyCubeName}_key`, () => this.aggregateSubQuery(keyCubeName, measures))))(measuresList);
1238
1132
  }
1239
1133
  }
1240
1134
  const multiStageMeasures = ramda_1.default.flatten(multiStageMembers.map(m => m.measures)).map(m => this.newMeasure(m));
@@ -1245,9 +1139,10 @@ class BaseQuery {
1245
1139
  joinFullKeyQueryAggregate(multipliedMeasures, regularMeasures, cumulativeMeasures, toJoin) {
1246
1140
  return this.outerMeasuresJoinFullKeyQueryAggregate(multipliedMeasures.concat(regularMeasures).concat(cumulativeMeasures.map(([multiplied, measure]) => measure)), this.measures, toJoin);
1247
1141
  }
1142
+ // `any`: members are BaseMeasure / BaseDimension / BaseTimeDimension read uniformly via `.measure` / `.dimension`
1248
1143
  outerMeasuresJoinFullKeyQueryAggregate(innerMembers, outerMembers, toJoin) {
1249
1144
  const renderedReferenceContext = {
1250
- renderedReference: ramda_1.default.pipe(ramda_1.default.map(m => {
1145
+ renderedReference: ramda_1.default.pipe(ramda_1.default.map((m) => {
1251
1146
  const member = m.measure ? m.measure : m.dimension;
1252
1147
  const memberPath = typeof member === 'string'
1253
1148
  ? member
@@ -1296,10 +1191,10 @@ class BaseQuery {
1296
1191
  }
1297
1192
  return hasMultiStageMembersCache[m];
1298
1193
  };
1299
- const measuresToRender = (multiplied, cumulative) => ramda_1.default.pipe(ramda_1.default.values, ramda_1.default.flatten, ramda_1.default.filter(m => m.multiplied === multiplied && this.newMeasure(m.measure).isCumulative() === cumulative && !hasMultiStageMembers(m.measure)), ramda_1.default.map(m => m.measure), ramda_1.default.uniq, ramda_1.default.map(m => this.newMeasure(m)));
1194
+ const measuresToRender = (multiplied, cumulative) => ramda_1.default.pipe(ramda_1.default.values, ramda_1.default.flatten, ramda_1.default.filter((m) => m.multiplied === multiplied && this.newMeasure(m.measure).isCumulative() === cumulative && !hasMultiStageMembers(m.measure)), ramda_1.default.map((m) => m.measure), ramda_1.default.uniq, ramda_1.default.map((m) => this.newMeasure(m)));
1300
1195
  const multipliedMeasures = measuresToRender(true, false)(measureToHierarchy);
1301
1196
  const regularMeasures = measuresToRender(false, false)(measureToHierarchy);
1302
- const cumulativeMeasures = ramda_1.default.pipe(ramda_1.default.map(multiplied => ramda_1.default.xprod([multiplied], measuresToRender(multiplied, true)(measureToHierarchy))), ramda_1.default.unnest)([false, true]);
1197
+ const cumulativeMeasures = ramda_1.default.pipe(ramda_1.default.map((multiplied) => ramda_1.default.xprod([multiplied], measuresToRender(multiplied, true)(measureToHierarchy))), ramda_1.default.unnest)([false, true]);
1303
1198
  const withQueries = [];
1304
1199
  const withQueriesMemo = new Map();
1305
1200
  const multiStageMembers = ramda_1.default.uniq(this.allMembersConcat(false)
@@ -1352,7 +1247,7 @@ class BaseQuery {
1352
1247
  }
1353
1248
  collectAllMultiStageMembers(allMemberChildren) {
1354
1249
  const allMembers = ramda_1.default.uniq(ramda_1.default.flatten(Object.keys(allMemberChildren).map(k => [k].concat(allMemberChildren[k]))));
1355
- return ramda_1.default.fromPairs(allMembers.map(m => {
1250
+ return ramda_1.default.fromPairs(allMembers.map((m) => {
1356
1251
  // When `m` is coming from `collectAllMemberChildren`, it can contain `granularities.customGranularityName` in path
1357
1252
  // And it would mess up with join hints detection
1358
1253
  const trimmedPath = this
@@ -1399,11 +1294,11 @@ class BaseQuery {
1399
1294
  // TODO calculate based on remove_filter in future
1400
1295
  const wouldNodeApplyFilters = !memberChildren[member];
1401
1296
  let memberFrom = memberChildren[member]
1402
- ?.map(child => this.multiStageWithQueries(child, this.childrenMultiStageContext(member, queryContext), memberChildren, withQueries, memo));
1297
+ ?.map((child) => this.multiStageWithQueries(child, this.childrenMultiStageContext(member, queryContext), memberChildren, withQueries, memo));
1403
1298
  const unionFromDimensions = memberFrom ? ramda_1.default.uniq(ramda_1.default.flatten(memberFrom.map(f => f.dimensions))) : queryContext.dimensions;
1404
1299
  const unionDimensionsContext = { ...queryContext, dimensions: unionFromDimensions.filter(d => !this.newDimension(d).isMultiStage()) };
1405
1300
  memberFrom = memberChildren[member] &&
1406
- ramda_1.default.uniqBy(f => f.alias, memberChildren[member].map(child => this.multiStageWithQueries(child, this.childrenMultiStageContext(member, unionDimensionsContext), memberChildren, withQueries, memo)));
1301
+ ramda_1.default.uniqBy((f) => f.alias, memberChildren[member].map((child) => this.multiStageWithQueries(child, this.childrenMultiStageContext(member, unionDimensionsContext), memberChildren, withQueries, memo)));
1407
1302
  const selfContext = this.selfMultiStageContext(member, queryContext, wouldNodeApplyFilters);
1408
1303
  const subQuery = {
1409
1304
  ...selfContext,
@@ -1418,9 +1313,10 @@ class BaseQuery {
1418
1313
  withQueries.push(subQuery);
1419
1314
  return subQuery;
1420
1315
  }
1316
+ // `any`: `alias` is assigned after the CTE is built, so MultiStageWithQuery keeps it optional
1421
1317
  collectUsedWithQueries(usedQueries, member) {
1422
1318
  usedQueries[member.alias] = true;
1423
- member.memberFrom?.forEach(m => this.collectUsedWithQueries(usedQueries, m));
1319
+ member.memberFrom?.forEach((m) => this.collectUsedWithQueries(usedQueries, m));
1424
1320
  }
1425
1321
  childrenMultiStageContext(memberPath, queryContext) {
1426
1322
  let member;
@@ -1464,6 +1360,7 @@ class BaseQuery {
1464
1360
  }
1465
1361
  else if (memberOfCube) {
1466
1362
  // We avoid view's timeshift evaluation as there will be another round of underlying cube's member evaluation
1363
+ // `any`: TimeShiftDefinitionReference has optional timeDimension / interval, read unguarded here
1467
1364
  memberDef.timeShiftReferences.forEach((r) => {
1468
1365
  timeShifts[r.timeDimension] = r.type === 'next' ? this.negateInterval(r.interval) : r.interval;
1469
1366
  });
@@ -1529,13 +1426,15 @@ class BaseQuery {
1529
1426
  }
1530
1427
  return queryContext;
1531
1428
  }
1429
+ // `any`: memberFrom is optional and the body relies on `fromSubQuery &&` implying it is set,
1430
+ // which TS can't correlate; the item lambdas below are typed
1532
1431
  renderWithQuery(withQuery) {
1533
- const fromMeasures = withQuery.memberFrom && ramda_1.default.uniq(ramda_1.default.flatten(withQuery.memberFrom.map(f => f.measures)));
1432
+ const fromMeasures = withQuery.memberFrom && ramda_1.default.uniq(ramda_1.default.flatten(withQuery.memberFrom.map((f) => f.measures)));
1534
1433
  // TODO get rid of this multiStage filter
1535
- const fromDimensions = withQuery.memberFrom && ramda_1.default.uniq(ramda_1.default.flatten(withQuery.memberFrom.map(f => f.dimensions)));
1536
- const fromTimeDimensions = withQuery.memberFrom && ramda_1.default.uniq(ramda_1.default.flatten(withQuery.memberFrom.map(f => (f.timeDimensions || []).map(td => ({ ...td, dateRange: undefined })))));
1434
+ const fromDimensions = withQuery.memberFrom && ramda_1.default.uniq(ramda_1.default.flatten(withQuery.memberFrom.map((f) => f.dimensions)));
1435
+ const fromTimeDimensions = withQuery.memberFrom && ramda_1.default.uniq(ramda_1.default.flatten(withQuery.memberFrom.map((f) => (f.timeDimensions || []).map(td => ({ ...td, dateRange: undefined })))));
1537
1436
  const renderedReferenceContext = {
1538
- renderedReference: withQuery.memberFrom && ramda_1.default.fromPairs(ramda_1.default.unnest(withQuery.memberFrom.map(from => from.measures.map(m => {
1437
+ renderedReference: withQuery.memberFrom && ramda_1.default.fromPairs(ramda_1.default.unnest(withQuery.memberFrom.map((from) => from.measures.map((m) => {
1539
1438
  const measure = this.newMeasure(m);
1540
1439
  return [m, measure.aliasName()];
1541
1440
  }).concat(from.dimensions.map(m => {
@@ -1567,13 +1466,15 @@ class BaseQuery {
1567
1466
  multiStageQuery: true, // !!fromDimensions.find(d => this.newDimension(d).isMultiStage())
1568
1467
  disableExternalPreAggregations: true,
1569
1468
  });
1570
- const measures = fromSubQuery && fromMeasures.map(m => fromSubQuery.newMeasure(m));
1469
+ const measures = fromSubQuery && fromMeasures.map((m) => fromSubQuery.newMeasure(m));
1571
1470
  // TODO get rid of this multiStage filter
1572
- const multiStageDimensions = fromSubQuery && fromDimensions.map(m => fromSubQuery.newDimension(m)).filter(d => d.isMultiStage());
1573
- const multiStageTimeDimensions = fromSubQuery && fromTimeDimensions.map(m => fromSubQuery.newTimeDimension(m)).filter(d => d.isMultiStage());
1471
+ const multiStageDimensions = fromSubQuery && fromDimensions.map((m) => fromSubQuery.newDimension(m))
1472
+ .filter((d) => d.isMultiStage());
1473
+ const multiStageTimeDimensions = fromSubQuery && fromTimeDimensions.map((m) => fromSubQuery.newTimeDimension(m))
1474
+ .filter((d) => d.isMultiStage());
1574
1475
  // TODO not working yet
1575
1476
  const membersToSelect = measures?.concat(multiStageDimensions).concat(multiStageTimeDimensions);
1576
- const select = fromSubQuery && fromSubQuery.outerMeasuresJoinFullKeyQueryAggregate(membersToSelect, membersToSelect, withQuery.memberFrom.map(f => f.alias));
1477
+ const select = fromSubQuery && fromSubQuery.outerMeasuresJoinFullKeyQueryAggregate(membersToSelect, membersToSelect, withQuery.memberFrom.map((f) => f.alias));
1577
1478
  const fromSql = select && this.wrapInParenthesis(select);
1578
1479
  const subQueryOptions = {
1579
1480
  measures: withQuery.measures,
@@ -1590,7 +1491,7 @@ class BaseQuery {
1590
1491
  alias: `${withQuery.alias}_join`,
1591
1492
  },
1592
1493
  // TODO condition should something else instead of rank
1593
- multiStageQuery: !!withQuery.measures.find(d => {
1494
+ multiStageQuery: !!withQuery.measures.find((d) => {
1594
1495
  const { type } = this.newMeasure(d).definition();
1595
1496
  return type === 'rank' || CubeSymbols_1.CubeSymbols.isCalculatedMeasureType(type);
1596
1497
  }),
@@ -1701,7 +1602,7 @@ class BaseQuery {
1701
1602
  }
1702
1603
  overTimeSeriesQuery(baseQueryFn, cumulativeMeasure, fromRollup) {
1703
1604
  const dateJoinCondition = cumulativeMeasure.dateJoinCondition();
1704
- const uniqDateJoinCondition = ramda_1.default.uniqBy(djc => djc[0].dimension, dateJoinCondition);
1605
+ const uniqDateJoinCondition = ramda_1.default.uniqBy((djc) => djc[0].dimension, dateJoinCondition);
1705
1606
  const cumulativeMeasures = [cumulativeMeasure];
1706
1607
  if (!this.timeDimensions.find(d => d.granularity)) {
1707
1608
  const filters = this.segments
@@ -1769,7 +1670,6 @@ class BaseQuery {
1769
1670
  /**
1770
1671
  * BigQuery has strict date type and can not automatically convert between date
1771
1672
  * and timestamp, so we override dateFromStartToEndConditionSql() in BigQuery Dialect
1772
- * @protected
1773
1673
  */
1774
1674
  dateFromStartToEndConditionSql(dateJoinCondition, fromRollup, isFromStartToEnd) {
1775
1675
  return dateJoinCondition.map(
@@ -1785,27 +1685,17 @@ class BaseQuery {
1785
1685
  }
1786
1686
  }));
1787
1687
  }
1788
- /**
1789
- * @param {import('./BaseTimeDimension').BaseTimeDimension} timeDimension
1790
- * @return {string}
1791
- */
1792
1688
  dateSeriesSql(timeDimension) {
1793
1689
  return `(${this.seriesSql(timeDimension)}) ${this.asSyntaxTable} ${timeDimension.dateSeriesAliasName()}`;
1794
1690
  }
1795
1691
  /**
1796
1692
  * BigQuery has strict date type and can not automatically convert between date
1797
1693
  * and timestamp, so we override seriesSql() in BigQuery Dialect
1798
- * @param {import('./BaseTimeDimension').BaseTimeDimension} timeDimension
1799
- * @return {string}
1800
1694
  */
1801
1695
  seriesSql(timeDimension) {
1802
1696
  const values = timeDimension.timeSeries().map(([from, to]) => `('${from}', '${to}')`);
1803
1697
  return `SELECT ${this.dateTimeCast('date_from')} as ${this.escapeColumnName('date_from')}, ${this.dateTimeCast('date_to')} as ${this.escapeColumnName('date_to')} FROM (VALUES ${values}) ${this.asSyntaxTable} dates (date_from, date_to)`;
1804
1698
  }
1805
- /**
1806
- * @param {import('./BaseDimension').BaseDimension|import('./BaseTimeDimension').BaseTimeDimension} timeDimension
1807
- * @return {string}
1808
- */
1809
1699
  timeStampParam(timeDimension) {
1810
1700
  return timeDimension.dateFieldType() === 'string' ? '?' : this.timeStampCast('?');
1811
1701
  }
@@ -1853,9 +1743,9 @@ class BaseQuery {
1853
1743
  dimensionOnlyMeasureToHierarchy(context, m) {
1854
1744
  const measureName = typeof m.measure === 'string' ? m.measure : `${m.measure.cubeName}.${m.measure.name}`;
1855
1745
  const memberNamesForMeasure = this.collectFrom([m], this.collectMemberNamesFor.bind(this), context ? ['collectMemberNamesFor', JSON.stringify(context)] : 'collectMemberNamesFor', this.queryCache);
1856
- const cubeNamesForMeasure = ramda_1.default.pipe(ramda_1.default.map(member => this.memberInstanceByPath(member)),
1746
+ const cubeNamesForMeasure = ramda_1.default.pipe(ramda_1.default.map((member) => this.memberInstanceByPath(member)),
1857
1747
  // collectMemberNamesFor can return both view.dim and cube.dim
1858
- ramda_1.default.filter(member => member.definition().ownedByCube), ramda_1.default.map(member => member.cube().name),
1748
+ ramda_1.default.filter((member) => member.definition().ownedByCube), ramda_1.default.map((member) => member.cube().name),
1859
1749
  // Single member expression can reference multiple dimensions from same cube
1860
1750
  ramda_1.default.uniq)(memberNamesForMeasure);
1861
1751
  let cubeNameToAttach;
@@ -1896,7 +1786,7 @@ class BaseQuery {
1896
1786
  collectRootMeasureToHierarchy(context) {
1897
1787
  const notAddedMeasureFilters = ramda_1.default.flatten(this.measureFilters.map(f => f.getMembers()))
1898
1788
  .filter(f => ramda_1.default.none(m => m.measure === f.measure, this.measures));
1899
- return ramda_1.default.fromPairs(this.measures.concat(notAddedMeasureFilters).map(m => {
1789
+ return ramda_1.default.fromPairs(this.measures.concat(notAddedMeasureFilters).map((m) => {
1900
1790
  const collectedMeasures = this.collectFrom([m], this.collectMultipliedMeasures(context), context ? ['collectMultipliedMeasures', JSON.stringify(context)] : 'collectMultipliedMeasures', this.queryCache);
1901
1791
  if (m.expressionName && !collectedMeasures.length && !m.isMemberExpression) {
1902
1792
  throw new UserError_1.UserError(`Subquery measure ${m.expressionName} should reference at least one member`);
@@ -1928,12 +1818,6 @@ class BaseQuery {
1928
1818
  query() {
1929
1819
  return this.from && this.joinSql([this.from]) || this.joinQuery(this.join, this.collectFromMembers(false, this.collectSubQueryDimensionsFor.bind(this), 'collectSubQueryDimensionsFor'));
1930
1820
  }
1931
- /**
1932
- *
1933
- * @param {string} cube
1934
- * @param {boolean} [isLeftJoinCondition]
1935
- * @returns {[string, string, string?]}
1936
- */
1937
1821
  rewriteInlineCubeSql(cube, isLeftJoinCondition) {
1938
1822
  const sql = this.cubeSql(cube);
1939
1823
  const cubeAlias = this.cubeAlias(cube);
@@ -1955,11 +1839,6 @@ class BaseQuery {
1955
1839
  return [sql, cubeAlias];
1956
1840
  }
1957
1841
  }
1958
- /**
1959
- * @param {import('../compiler/JoinGraph').FinishedJoinTree} join
1960
- * @param {Array<string>} subQueryDimensions
1961
- * @returns {string}
1962
- */
1963
1842
  joinQuery(join, subQueryDimensions) {
1964
1843
  const subQueryDimensionsByCube = ramda_1.default.groupBy(d => this.cubeEvaluator.cubeNameFromPath(d), subQueryDimensions);
1965
1844
  const joins = join.joins.flatMap(j => {
@@ -1979,10 +1858,6 @@ class BaseQuery {
1979
1858
  ...this.customSubQueryJoins.map((customJoin) => this.customSubQueryJoin(customJoin)),
1980
1859
  ]);
1981
1860
  }
1982
- /**
1983
- * @param {JoinChain} toJoin
1984
- * @returns {string}
1985
- */
1986
1861
  joinSql(toJoin) {
1987
1862
  const [root, ...rest] = toJoin;
1988
1863
  const joins = rest.map(j => {
@@ -1991,12 +1866,6 @@ class BaseQuery {
1991
1866
  });
1992
1867
  return [`${root.sql} ${this.asSyntaxJoin} ${root.alias}`, ...joins].join('\n');
1993
1868
  }
1994
- /**
1995
- *
1996
- * @param {{sql: string, on: {cubeName: string, expression: Function}, joinType: 'LEFT' | 'INNER', alias: string}}
1997
- * customJoin
1998
- * @returns {JoinItem}
1999
- */
2000
1869
  customSubQueryJoin(customJoin) {
2001
1870
  const on = this.evaluateSql(customJoin.on.cubeName, customJoin.on.expression);
2002
1871
  return {
@@ -2006,11 +1875,6 @@ class BaseQuery {
2006
1875
  joinType: customJoin.joinType,
2007
1876
  };
2008
1877
  }
2009
- /**
2010
- *
2011
- * @param {string} dimension
2012
- * @returns {JoinItem}
2013
- */
2014
1878
  subQueryJoin(dimension) {
2015
1879
  const { prefix, subQuery, cubeName } = this.subQueryDescription(dimension);
2016
1880
  const primaryKeys = this.cubeEvaluator.primaryKeys[cubeName];
@@ -2032,11 +1896,6 @@ class BaseQuery {
2032
1896
  }
2033
1897
  return this.filtersWithoutSubQueriesValue;
2034
1898
  }
2035
- /**
2036
- *
2037
- * @param {string} dimension
2038
- * @returns {{ prefix: string, subQuery: this, cubeName: string }}
2039
- */
2040
1899
  subQueryDescription(dimension) {
2041
1900
  const symbol = this.cubeEvaluator.dimensionByPath(dimension);
2042
1901
  const [cubeName, name] = this.cubeEvaluator.parsePath('dimensions', dimension);
@@ -2045,7 +1904,7 @@ class BaseQuery {
2045
1904
  let segments;
2046
1905
  let timeDimensions;
2047
1906
  if (symbol.propagateFiltersToSubQuery) {
2048
- filters = this.filtersWithoutSubQueries.filter(f => f instanceof BaseFilter_1.BaseFilter && !(f instanceof BaseTimeDimension_1.BaseTimeDimension)).map(f => ({
1907
+ filters = this.filtersWithoutSubQueries.filter(f => f instanceof BaseFilter_1.BaseFilter && !(f instanceof BaseTimeDimension_1.BaseTimeDimension)).map((f) => ({
2049
1908
  dimension: f.dimension,
2050
1909
  operator: f.operator,
2051
1910
  values: f.values
@@ -2068,16 +1927,10 @@ class BaseQuery {
2068
1927
  filters,
2069
1928
  segments,
2070
1929
  timeDimensions,
2071
- order: {}
1930
+ order: []
2072
1931
  });
2073
1932
  return { prefix, subQuery, cubeName };
2074
1933
  }
2075
- /**
2076
- *
2077
- * @param {string} cubeName
2078
- * @param {string} name
2079
- * @returns {string}
2080
- */
2081
1934
  subQueryName(cubeName, name) {
2082
1935
  return `${cubeName}_${name}_subquery`;
2083
1936
  }
@@ -2090,10 +1943,6 @@ class BaseQuery {
2090
1943
  }
2091
1944
  /**
2092
1945
  * Returns SQL query for the "aggregating on top of sub-queries" uses cases.
2093
- * @param {string} keyCubeName
2094
- * @param {Array<BaseMeasure>} measures
2095
- * @param {Array<BaseFilter>} filters
2096
- * @returns {string}
2097
1946
  */
2098
1947
  aggregateSubQuery(keyCubeName, measures, filters) {
2099
1948
  filters = filters || this.allFilters;
@@ -2144,11 +1993,6 @@ class BaseQuery {
2144
1993
  return `SELECT ${columnsForSelect} FROM ${joinSql}` +
2145
1994
  (!this.safeEvaluateSymbolContext().ungrouped && this.aggregateSubQueryGroupByClause() || '');
2146
1995
  }
2147
- /**
2148
- * @param {Array<BaseMeasure>} measures
2149
- * @param {string} keyCubeName
2150
- * @returns {boolean}
2151
- */
2152
1996
  checkShouldBuildJoinForMeasureSelect(measures, keyCubeName) {
2153
1997
  // When member expression references view, it would have to collect join hints from view
2154
1998
  // Consider join A->B, as many-to-one, so B is multiplied and A is not, and member expression like SUM(AB_view.dimB)
@@ -2211,9 +2055,6 @@ class BaseQuery {
2211
2055
  }, this.dimensionsForSelect()
2212
2056
  .concat(primaryKeyDimensions));
2213
2057
  }
2214
- /**
2215
- * @param {string} cube
2216
- */
2217
2058
  cubeSql(cube) {
2218
2059
  const foundPreAggregation = this.preAggregations.findPreAggregationToUseForCube(cube);
2219
2060
  if (foundPreAggregation &&
@@ -2235,6 +2076,7 @@ class BaseQuery {
2235
2076
  }
2236
2077
  return `(${evaluatedSql})`;
2237
2078
  }
2079
+ // `any`: members include join pseudo-members, and BaseMeasure's `patchedMeasure` read here is protected
2238
2080
  traverseSymbol(s) {
2239
2081
  // TODO why not just evaluateSymbolSql for every branch?
2240
2082
  if (s.path()) {
@@ -2250,26 +2092,18 @@ class BaseQuery {
2250
2092
  // These referenced cubes must be added as join hints before Cube B to ensure correct SQL generation.
2251
2093
  const targetCube = s.targetCubeName();
2252
2094
  let { joinHints } = this.safeEvaluateSymbolContext();
2253
- joinHints = joinHints.filter(e => e !== targetCube);
2095
+ joinHints = joinHints.filter((e) => e !== targetCube);
2254
2096
  joinHints.push(targetCube);
2255
2097
  this.safeEvaluateSymbolContext().joinHints = joinHints;
2256
2098
  }
2257
2099
  return res;
2258
2100
  }
2259
2101
  }
2260
- /**
2261
- *
2262
- * @returns {Array<string>}
2263
- */
2264
2102
  collectCubeNames() {
2265
2103
  return this.collectFromMembers(false, this.collectCubeNamesFor.bind(this), 'collectCubeNamesFor');
2266
2104
  }
2267
2105
  /**
2268
2106
  * Just a helper to avoid copy/paste
2269
- * @private
2270
- * @param {import('../compiler/JoinGraph').FinishedJoinTree} a
2271
- * @param {import('../compiler/JoinGraph').FinishedJoinTree} b
2272
- * @return {boolean}
2273
2107
  */
2274
2108
  isJoinTreesEqual(a, b) {
2275
2109
  if (!a || !b || a.root !== b.root || a.joins.length !== b.joins.length) {
@@ -2289,11 +2123,6 @@ class BaseQuery {
2289
2123
  }
2290
2124
  return true;
2291
2125
  }
2292
- /**
2293
- * @private
2294
- * @param {boolean} [excludeTimeDimensions=false]
2295
- * @returns {Array<(Array<string> | string)>}
2296
- */
2297
2126
  collectJoinHints(excludeTimeDimensions = false) {
2298
2127
  const allMembersJoinHints = this.collectJoinHintsFromMembers(this.allMembersConcat(excludeTimeDimensions));
2299
2128
  const queryJoinMaps = this.queryJoinMap();
@@ -2365,6 +2194,7 @@ class BaseQuery {
2365
2194
  }]
2366
2195
  })) : [];
2367
2196
  }
2197
+ // `any`: members include join pseudo-members; `h?.length > 0` doesn't compile for an optional `joinHint`
2368
2198
  collectJoinHintsFromMembers(members) {
2369
2199
  // Extract cube names from members to make cache key member-cubes-specific
2370
2200
  const memberCubes = members
@@ -2376,14 +2206,6 @@ class BaseQuery {
2376
2206
  ...this.collectFrom(members, this.collectJoinHintsFor.bind(this), ['collectJoinHintsFromMembers', ...memberCubes]),
2377
2207
  ];
2378
2208
  }
2379
- /**
2380
- * @template T
2381
- * @param {boolean} excludeTimeDimensions
2382
- * @param {(t: () => void) => T} fn
2383
- * @param {string | Array<string>} methodName
2384
- * @param {(member: unknown) => boolean} [memberFilter]
2385
- * @returns {T}
2386
- */
2387
2209
  collectFromMembers(excludeTimeDimensions, fn, methodName, memberFilter) {
2388
2210
  const members = this.allMembersConcat(excludeTimeDimensions);
2389
2211
  const membersToCollectFrom = (memberFilter ?
@@ -2398,11 +2220,6 @@ class BaseQuery {
2398
2220
  })) : []);
2399
2221
  return this.collectFrom(membersToCollectFrom, fn, methodName);
2400
2222
  }
2401
- /**
2402
- *
2403
- * @param {boolean} excludeTimeDimensions
2404
- * @returns {Array<BaseMeasure | BaseDimension | BaseSegment>}
2405
- */
2406
2223
  allMembersConcat(excludeTimeDimensions) {
2407
2224
  return this.measures
2408
2225
  .concat(this.dimensions)
@@ -2411,17 +2228,9 @@ class BaseQuery {
2411
2228
  .concat(this.measureFilters)
2412
2229
  .concat(excludeTimeDimensions ? [] : this.timeDimensions);
2413
2230
  }
2414
- /**
2415
- * @template T
2416
- * @param {Array<unknown>} membersToCollectFrom
2417
- * @param {(t: () => void) => T} fn
2418
- * @param {string | Array<string>} methodName
2419
- * @param {unknown} [cache]
2420
- * @returns {T}
2421
- */
2422
2231
  collectFrom(membersToCollectFrom, fn, methodName, cache) {
2423
2232
  const methodCacheKey = Array.isArray(methodName) ? methodName : [methodName];
2424
- return ramda_1.default.pipe(ramda_1.default.map(f => f.getMembers()), ramda_1.default.flatten, ramda_1.default.map(s => {
2233
+ return ramda_1.default.pipe(ramda_1.default.map((f) => f.getMembers()), ramda_1.default.flatten, ramda_1.default.map((s) => {
2425
2234
  const memberPath = s.path() ? s.path().join('.') : null;
2426
2235
  const hasSqlMask = memberPath &&
2427
2236
  this.maskedMembers && this.maskedMembers.size > 0 &&
@@ -2430,11 +2239,6 @@ class BaseQuery {
2430
2239
  return (cache || (hasSqlMask ? this.queryCache : this.compilerCache)).cache(['collectFrom'].concat(methodCacheKey).concat(memberPath ? [memberPath] : [s.cube().name, s.expression?.toString() || s.expressionName || s.definition().sql]), () => fn(() => this.traverseSymbol(s)));
2431
2240
  }), ramda_1.default.unnest, ramda_1.default.uniq, ramda_1.default.filter(ramda_1.default.identity))(membersToCollectFrom);
2432
2241
  }
2433
- /**
2434
- *
2435
- * @param {() => void} fn
2436
- * @returns {Array<string>}
2437
- */
2438
2242
  collectSubQueryDimensionsFor(fn) {
2439
2243
  const context = { subQueryDimensions: [] };
2440
2244
  this.evaluateSymbolSqlWithContext(fn, context);
@@ -2447,14 +2251,12 @@ class BaseQuery {
2447
2251
  /**
2448
2252
  * Returns `GROUP BY` clause for the "aggregating on top of sub-queries" uses
2449
2253
  * cases. By the default returns the result of the `groupByClause` method.
2450
- * @returns {string}
2451
2254
  */
2452
2255
  aggregateSubQueryGroupByClause() {
2453
2256
  return this.groupByClause();
2454
2257
  }
2455
2258
  /**
2456
2259
  * Returns `GROUP BY` clause for the basic uses cases.
2457
- * @returns {string}
2458
2260
  */
2459
2261
  groupByClause() {
2460
2262
  if (this.ungrouped) {
@@ -2469,9 +2271,7 @@ class BaseQuery {
2469
2271
  }
2470
2272
  /**
2471
2273
  * XXX: String as return value is added because of HiveQuery.getFieldIndex() and DatabricksQuery.getFieldIndex()
2472
- * @protected
2473
- * @param {string} id member name in form of "cube.member[.granularity]"
2474
- * @returns {number|string|null}
2274
+ * @param id member name in form of "cube.member[.granularity]"
2475
2275
  */
2476
2276
  getFieldIndex(id) {
2477
2277
  const equalIgnoreCase = (a, b) => (typeof a === 'string' && typeof b === 'string' && a.toUpperCase() === b.toUpperCase());
@@ -2498,7 +2298,7 @@ class BaseQuery {
2498
2298
  // but they exist in this.timeDimensions, so need to filter them out
2499
2299
  .filter(d => d.selectColumns());
2500
2300
  const found = (0, shared_1.findMinGranularityDimension)(id, dimensionsForSelect);
2501
- if (found?.index > -1) {
2301
+ if (found && found.index > -1) {
2502
2302
  return found.index + 1;
2503
2303
  }
2504
2304
  index = this.measures.findIndex(d => equalIgnoreCase(d.measure, id) || equalIgnoreCase(d.expressionName, id));
@@ -2509,9 +2309,7 @@ class BaseQuery {
2509
2309
  return null;
2510
2310
  }
2511
2311
  /**
2512
- * @protected
2513
- * @param {string} id member name in form of "cube.member[.granularity]"
2514
- * @returns {null|string}
2312
+ * @param id member name in form of "cube.member[.granularity]"
2515
2313
  */
2516
2314
  getFieldAlias(id) {
2517
2315
  const equalIgnoreCase = (a, b) => (typeof a === 'string' && typeof b === 'string' && a.toUpperCase() === b.toUpperCase());
@@ -2546,10 +2344,6 @@ class BaseQuery {
2546
2344
  }
2547
2345
  return null;
2548
2346
  }
2549
- /**
2550
- * @param {{ id: string, desc: boolean }} hash
2551
- * @returns {string|null}
2552
- */
2553
2347
  orderHashToString(hash) {
2554
2348
  if (!hash || !hash.id) {
2555
2349
  return null;
@@ -2574,15 +2368,12 @@ class BaseQuery {
2574
2368
  /**
2575
2369
  * Returns a complete list of the aliased dimensions, including time
2576
2370
  * dimensions.
2577
- * @returns {Array<string>}
2578
2371
  */
2579
2372
  dimensionAliasNames() {
2580
2373
  return ramda_1.default.flatten(this.dimensionsForSelect().map(d => d.aliasName()).filter(d => !!d));
2581
2374
  }
2582
2375
  /**
2583
2376
  * Returns an array of column names correlated to the specified cube dimensions.
2584
- * @param {string} cubeAlias
2585
- * @returns {Array<string>}
2586
2377
  */
2587
2378
  dimensionColumns(cubeAlias) {
2588
2379
  return this.dimensionAliasNames().map(alias => `${cubeAlias && `${cubeAlias}.` || ''}${alias}`);
@@ -2600,11 +2391,6 @@ class BaseQuery {
2600
2391
  const offset = this.offset ? parseInt(this.offset, 10) : null;
2601
2392
  return this.limitOffsetClause(limit, offset);
2602
2393
  }
2603
- /**
2604
- * @protected
2605
- * @param {Array<string>} dimensionNames
2606
- * @returns {string}
2607
- */
2608
2394
  rollupGroupByClause(dimensionNames) {
2609
2395
  if (this.ungrouped) {
2610
2396
  return '';
@@ -2641,12 +2427,6 @@ class BaseQuery {
2641
2427
  }
2642
2428
  return result;
2643
2429
  }
2644
- /**
2645
- * @protected
2646
- * @param limit
2647
- * @param offset
2648
- * @returns {string}
2649
- */
2650
2430
  limitOffsetClause(limit, offset) {
2651
2431
  const limitClause = limit != null ? ` LIMIT ${limit}` : '';
2652
2432
  const offsetClause = offset != null ? ` OFFSET ${offset}` : '';
@@ -2659,8 +2439,6 @@ class BaseQuery {
2659
2439
  * Row limit as a number, or `null` when it is not set at all. Unlike a truthy check
2660
2440
  * this keeps `0` (a valid limit that returns no rows) distinct from "no limit", and
2661
2441
  * unlike a bare `parseInt` it keeps a non-numeric `rowLimit` out of the rendered SQL.
2662
- * @protected
2663
- * @returns {number|null}
2664
2442
  */
2665
2443
  parsedRowLimit() {
2666
2444
  if (this.rowLimit == null) {
@@ -2674,8 +2452,6 @@ class BaseQuery {
2674
2452
  * rollup query in `PreAggregations` is the one such statement. Only dialects that cannot
2675
2453
  * express a zero row limit as a trailing clause (T-SQL, where FETCH NEXT must be >= 1)
2676
2454
  * return anything here; every other dialect renders `LIMIT 0` and gets `''`.
2677
- * @public
2678
- * @returns {string}
2679
2455
  */
2680
2456
  zeroRowLimitTopClause() {
2681
2457
  return '';
@@ -2686,15 +2462,11 @@ class BaseQuery {
2686
2462
  selectAllDimensionsAndMeasures(measures) {
2687
2463
  return ramda_1.default.flatten(this.dimensionsForSelect().concat(measures).map(s => s.selectColumns())).filter(s => !!s).join(', ');
2688
2464
  }
2689
- /**
2690
- * @returns {Array<BaseDimension|BaseMeasure>}
2691
- */
2692
2465
  forSelect() {
2693
2466
  return this.dimensionsForSelect().concat(this.measures);
2694
2467
  }
2695
2468
  /**
2696
2469
  * Returns a complete list of the dimensions, including time dimensions.
2697
- * @returns {(BaseDimension|BaseTimeDimension)[]}
2698
2470
  */
2699
2471
  dimensionsForSelect() {
2700
2472
  return this.dimensions.concat(this.timeDimensions);
@@ -2764,7 +2536,9 @@ class BaseQuery {
2764
2536
  safeEvaluateSymbolContext() {
2765
2537
  return this.evaluateSymbolContext || {};
2766
2538
  }
2767
- evaluateSymbolSql(cubeName, name, symbol, memberExpressionType, subPropertyName) {
2539
+ evaluateSymbolSql(cubeName, name,
2540
+ // `any`: geo, case and filter branches read optional fields unguarded, and resolvers pass CubeSymbolDefinition
2541
+ symbol, memberExpressionType, subPropertyName) {
2768
2542
  const aliasPath = this.cubeEvaluator.joinAliasPath();
2769
2543
  if (aliasPath && this.safeEvaluateSymbolContext().memberInstanceAliasPath !== aliasPath) {
2770
2544
  this.ensureNativePlannerForJoinAliases([...aliasPath, name].join('.'));
@@ -2866,7 +2640,7 @@ class BaseQuery {
2866
2640
  // exposed only under an alias, so resolve them against the owning cube
2867
2641
  // (from aliasMember, the underlying reference) instead of the view.
2868
2642
  const orderByCubeName = symbol.aliasMember ? symbol.aliasMember.split('.')[0] : cubeName;
2869
- const orderBySql = (symbol.orderBy || []).map(o => ({ sql: this.evaluateSql(orderByCubeName, o.sql), dir: o.dir }));
2643
+ const orderBySql = (symbol.orderBy || []).map((o) => ({ sql: this.evaluateSql(orderByCubeName, o.sql), dir: o.dir }));
2870
2644
  let sql;
2871
2645
  let patchedSymbol = symbol;
2872
2646
  if (symbol.type !== 'rank') {
@@ -3099,11 +2873,6 @@ class BaseQuery {
3099
2873
  concatStringsSql(strings) {
3100
2874
  return strings.join(' || ');
3101
2875
  }
3102
- /**
3103
- *
3104
- * @param {string} cubeName
3105
- * @returns {Array<string>}
3106
- */
3107
2876
  primaryKeyNames(cubeName) {
3108
2877
  const primaryKeys = this.cubeEvaluator.primaryKeys[cubeName];
3109
2878
  if (!primaryKeys || !primaryKeys.length) {
@@ -3114,7 +2883,9 @@ class BaseQuery {
3114
2883
  primaryKeyName(cubeName, primaryKey) {
3115
2884
  return `${cubeName}.${primaryKey}`;
3116
2885
  }
3117
- evaluateSql(cubeName, sql, options) {
2886
+ evaluateSql(cubeName,
2887
+ // `any`: callers pass the optional cube `sql` / `sqlTable` they know is set, and CustomSubQueryJoin's `Function`
2888
+ sql, options) {
3118
2889
  options = options || {};
3119
2890
  const self = this;
3120
2891
  const { cubeEvaluator } = this;
@@ -3140,8 +2911,6 @@ class BaseQuery {
3140
2911
  /**
3141
2912
  * Evaluate escaped SQL-alias for cube or cube's property
3142
2913
  * (measure, dimension).
3143
- * @param {string} cubeName
3144
- * @returns string
3145
2914
  */
3146
2915
  cubeAlias(cubeName) {
3147
2916
  const prefix = this.safeEvaluateSymbolContext().cubeAliasPrefix || this.cubeAliasPrefix;
@@ -3149,11 +2918,6 @@ class BaseQuery {
3149
2918
  ? prefix + '__' + this.aliasName(cubeName)
3150
2919
  : cubeName}`));
3151
2920
  }
3152
- /**
3153
- *
3154
- * @param fn
3155
- * @returns {Array<string>}
3156
- */
3157
2921
  collectCubeNamesFor(fn) {
3158
2922
  const context = { cubeNames: [] };
3159
2923
  this.evaluateSymbolSqlWithContext(fn, context);
@@ -3164,11 +2928,6 @@ class BaseQuery {
3164
2928
  this.evaluateSymbolSqlWithContext(fn, context);
3165
2929
  return context.joinHints;
3166
2930
  }
3167
- /**
3168
- *
3169
- * @param fn
3170
- * @returns {Array<string>}
3171
- */
3172
2931
  collectMemberNamesFor(fn) {
3173
2932
  const context = { memberNames: [] };
3174
2933
  this.evaluateSymbolSqlWithContext(fn, context);
@@ -3269,20 +3028,13 @@ class BaseQuery {
3269
3028
  [renderContext.rootMeasure.value];
3270
3029
  };
3271
3030
  }
3272
- /**
3273
- * @returns {string[]}
3274
- */
3275
3031
  collectLeafMeasures(fn) {
3276
3032
  const context = { leafMeasures: {} };
3277
3033
  this.evaluateSymbolSqlWithContext(fn, context);
3278
- return ramda_1.default.pipe(ramda_1.default.toPairs, ramda_1.default.map(([measure, isLeaf]) => isLeaf && measure), ramda_1.default.filter(ramda_1.default.identity))(context.leafMeasures);
3034
+ return Object.entries(context.leafMeasures)
3035
+ .filter(([, isLeaf]) => isLeaf)
3036
+ .map(([measure]) => measure);
3279
3037
  }
3280
- /**
3281
- * @template T
3282
- * @param {() => T} fn
3283
- * @param {unknown} context
3284
- * @returns {T}
3285
- */
3286
3038
  evaluateSymbolSqlWithContext(fn, context) {
3287
3039
  const oldContext = this.evaluateSymbolContext;
3288
3040
  this.evaluateSymbolContext = oldContext ? Object.assign({}, oldContext, context) : context;
@@ -3446,7 +3198,7 @@ class BaseQuery {
3446
3198
  return `count(${distinct ? 'distinct ' : ''}${primaryKeySql})`;
3447
3199
  }
3448
3200
  renderDimensionCase(symbol, cubeName) {
3449
- const when = symbol.case.when.map(w => ({
3201
+ const when = symbol.case.when.map((w) => ({
3450
3202
  sql: this.evaluateSql(cubeName, w.sql),
3451
3203
  label: this.renderDimensionCaseLabel(w.label, cubeName)
3452
3204
  }));
@@ -3462,6 +3214,7 @@ class BaseQuery {
3462
3214
  return `CASE
3463
3215
  ${when.map(w => `WHEN ${w.sql} THEN ${w.label}`).join('\n')}${elseLabel ? ` ELSE ${elseLabel}` : ''} END`;
3464
3216
  }
3217
+ // `any`: `symbol.filters` is optional and checked only through `hasOwnFilters`, which doesn't narrow it
3465
3218
  applyMeasureFilters(evaluateSql, symbol, cubeName) {
3466
3219
  const pushDownFilterSql = this.safeEvaluateSymbolContext().patchMeasurePushDownFilterSql;
3467
3220
  const hasOwnFilters = symbol.filters && symbol.filters.length;
@@ -3482,45 +3235,26 @@ class BaseQuery {
3482
3235
  return this.evaluateFiltersArray(symbol.filters, cubeName);
3483
3236
  }
3484
3237
  evaluateFiltersArray(filtersArray, cubeName) {
3485
- return filtersArray.map(f => this.evaluateSql(cubeName, f.sql))
3486
- .map(s => `(${s})`).join(' AND ');
3238
+ return filtersArray.map((f) => this.evaluateSql(cubeName, f.sql))
3239
+ .map((s) => `(${s})`).join(' AND ');
3487
3240
  }
3488
- /**
3489
- * @param {string} primaryKeyName
3490
- * @param {string} cubeName
3491
- * @returns {unknown}
3492
- */
3493
3241
  primaryKeySql(primaryKeyName, cubeName) {
3494
3242
  const primaryKeyDimension = this.cubeEvaluator.dimensionByPath([cubeName, primaryKeyName]);
3495
3243
  return this.evaluateSymbolSql(cubeName, primaryKeyName, primaryKeyDimension);
3496
3244
  }
3497
- /**
3498
- * @param cubeName
3499
- * @returns Boolean
3500
- */
3501
3245
  multipliedJoinRowResult(cubeName) {
3502
3246
  // this.join not initialized on collectCubeNamesForSql
3503
- return this.join && this.join.multiplicationFactor[cubeName];
3247
+ return this.join?.multiplicationFactor[cubeName];
3504
3248
  }
3505
3249
  inDbTimeZone(date) {
3506
3250
  return (0, shared_1.localTimestampToUtc)(this.timezone || 'UTC', this.timestampFormat(), date);
3507
3251
  }
3508
- /**
3509
- * @return {string}
3510
- */
3511
3252
  timestampFormat() {
3512
3253
  return 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]';
3513
3254
  }
3514
- /**
3515
- * @return {number}
3516
- */
3517
3255
  timestampPrecision() {
3518
3256
  return 3;
3519
3257
  }
3520
- /**
3521
- * @param {string} field
3522
- * @return {string}
3523
- */
3524
3258
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
3525
3259
  convertTz(field) {
3526
3260
  throw new Error('Not implemented');
@@ -3529,17 +3263,10 @@ class BaseQuery {
3529
3263
  * URL-encode a SQL expression. Override in dialect-specific query classes
3530
3264
  * for native URL encoding support. Default implementation uses REPLACE
3531
3265
  * chains for the most common characters.
3532
- * @param {string} sql
3533
- * @return {string}
3534
3266
  */
3535
3267
  urlEncode(sql) {
3536
3268
  return `REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(CAST(${sql} as TEXT), '%', '%25'), '&', '%26'), '=', '%3D'), '+', '%2B'), ' ', '%20')`;
3537
3269
  }
3538
- /**
3539
- * @param {string} granularity
3540
- * @param {string} dimension
3541
- * @return {string}
3542
- */
3543
3270
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
3544
3271
  timeGroupedColumn(granularity, dimension) {
3545
3272
  throw new Error('Not implemented');
@@ -3547,10 +3274,9 @@ class BaseQuery {
3547
3274
  /**
3548
3275
  * Returns sql for source expression floored to timestamps aligned with
3549
3276
  * intervals relative to origin timestamp point
3550
- * @param {string} interval (a value expression of type interval)
3551
- * @param {string} source (a value expression of type timestamp/date)
3552
- * @param {string} origin (a value expression of type timestamp/date without timezone)
3553
- * @returns {string}
3277
+ * @param interval (a value expression of type interval)
3278
+ * @param source (a value expression of type timestamp/date)
3279
+ * @param origin (a value expression of type timestamp/date without timezone)
3554
3280
  */
3555
3281
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
3556
3282
  dateBin(interval, source, origin) {
@@ -3559,9 +3285,6 @@ class BaseQuery {
3559
3285
  }
3560
3286
  /**
3561
3287
  * Returns the lowest time unit for the interval
3562
- * @protected
3563
- * @param {string} interval
3564
- * @returns {string}
3565
3288
  */
3566
3289
  diffTimeUnitForInterval(interval) {
3567
3290
  if (/second/i.test(interval)) {
@@ -3589,11 +3312,6 @@ class BaseQuery {
3589
3312
  return 'year';
3590
3313
  }
3591
3314
  }
3592
- /**
3593
- * @param {string} dimension
3594
- * @param {import('./Granularity').Granularity} granularity
3595
- * @return {string}
3596
- */
3597
3315
  dimensionTimeGroupedColumn(dimension, granularity) {
3598
3316
  let dtDate;
3599
3317
  // Interval is aligned with natural calendar, so we can use DATE_TRUNC
@@ -3611,9 +3329,6 @@ class BaseQuery {
3611
3329
  }
3612
3330
  /**
3613
3331
  * Evaluate alias for specific cube's property.
3614
- * @param {string} name Property name.
3615
- * @param {boolean?} isPreAggregationName Pre-agg flag.
3616
- * @returns {string}
3617
3332
  */
3618
3333
  aliasName(name, isPreAggregationName = false) {
3619
3334
  if (this.options.memberToAlias && this.options.memberToAlias[name]) {
@@ -3625,9 +3340,6 @@ class BaseQuery {
3625
3340
  * Alias of a member when the query asks for none (`memberToAlias`). A pre-aggregation
3626
3341
  * table is built by a query asking for none, so its columns go by these names however
3627
3342
  * the query reading it aliases its own output.
3628
- * @param {string} name Property name.
3629
- * @param {boolean?} isPreAggregationName Pre-agg flag.
3630
- * @returns {string}
3631
3343
  */
3632
3344
  canonicalAliasName(name, isPreAggregationName = false) {
3633
3345
  const path = name.split('.');
@@ -3645,14 +3357,8 @@ class BaseQuery {
3645
3357
  }
3646
3358
  return inflection_1.default.underscore(name).replace(/\./g, isPreAggregationName ? '_' : '__');
3647
3359
  }
3648
- /**
3649
- *
3650
- * @param {unknown} options
3651
- * @returns {this}
3652
- */
3653
3360
  newSubQuery(options) {
3654
- const QueryClass = this.constructor;
3655
- return new QueryClass(this.compilers, this.subQueryOptions(options));
3361
+ return this.compilers.createQuery(this.constructor, this.subQueryOptions(options));
3656
3362
  }
3657
3363
  newSubQueryForCube(cube, options) {
3658
3364
  options = { ...options };
@@ -3661,7 +3367,10 @@ class BaseQuery {
3661
3367
  // By default, we'll use BaseQuery, but it's important to note that different databases (Oracle, PostgreSQL, MySQL, Druid, etc.)
3662
3368
  // have unique parameter allocator symbols. Using the wrong allocator can break the query, especially when rollup joins involve
3663
3369
  // different cubes that require different allocators.
3664
- return this.options.queryFactory.createQuery(cube, this.compilers, { ...this.subQueryOptions(options), paramAllocator: null });
3370
+ const query = this.options.queryFactory.createQuery(cube, this.compilers, { ...this.subQueryOptions(options), paramAllocator: null });
3371
+ // Its dialect is `cube`'s, but its members can reach a cube of another data source
3372
+ query.detectDataSource();
3373
+ return query;
3665
3374
  }
3666
3375
  return this.newSubQuery(options);
3667
3376
  }
@@ -3734,7 +3443,8 @@ class BaseQuery {
3734
3443
  };
3735
3444
  return cubes.map(cube => [cube, refreshKeyQueryByCube(cube)])
3736
3445
  .map(([cube, refreshKeyTuple]) => (transformFn ? transformFn(cube, refreshKeyTuple) : refreshKeyTuple))
3737
- .map(([sql, options, query]) => query.paramAllocator.buildSqlAndParams(sql).concat(options));
3446
+ // The query is viewed through an untupled buildSqlAndParams() so the options can be appended to its result
3447
+ .map(([sql, options, query]) => (query.paramAllocator.buildSqlAndParams(sql).concat(options)));
3738
3448
  }
3739
3449
  aggSelectForDimension(cube, dimension, aggFunction) {
3740
3450
  const cubeNamesForTimeDimension = this.collectFrom([dimension], this.collectCubeNamesFor.bind(this), 'collectCubeNamesFor');
@@ -3862,7 +3572,7 @@ class BaseQuery {
3862
3572
  acc.set(outputColumnType.name, outputColumnType);
3863
3573
  return acc;
3864
3574
  }, new Map());
3865
- const findSchemaType = member => {
3575
+ const findSchemaType = (member) => {
3866
3576
  const outputSchemaType = evaluatedMapOutputColumnTypes.get(member);
3867
3577
  if (!outputSchemaType) {
3868
3578
  throw new UserError_1.UserError(`Output schema type for ${member} not found in pre-aggregation ${preAggregation}`);
@@ -3888,7 +3598,7 @@ class BaseQuery {
3888
3598
  }
3889
3599
  preAggregationUniqueKeyColumns(cube, preAggregation) {
3890
3600
  if (preAggregation.uniqueKeyColumns) {
3891
- return preAggregation.uniqueKeyColumns.map(key => this.aliasName(`${cube}.${key}`));
3601
+ return preAggregation.uniqueKeyColumns.map((key) => this.aliasName(`${cube}.${key}`));
3892
3602
  }
3893
3603
  return this.dimensionColumns();
3894
3604
  }
@@ -3898,10 +3608,6 @@ class BaseQuery {
3898
3608
  preAggregationAllowUngroupingWithPrimaryKey(_cube, _preAggregation) {
3899
3609
  return false;
3900
3610
  }
3901
- /**
3902
- * @public
3903
- * @returns {any}
3904
- */
3905
3611
  sqlTemplates() {
3906
3612
  return {
3907
3613
  functions: {
@@ -4163,13 +3869,6 @@ class BaseQuery {
4163
3869
  },
4164
3870
  };
4165
3871
  }
4166
- /**
4167
- *
4168
- * @param cube
4169
- * @param preAggregation
4170
- * @returns {BaseQuery}
4171
- */
4172
- // eslint-disable-next-line consistent-return
4173
3872
  preAggregationQueryForSqlEvaluation(cube, preAggregation, context = {}) {
4174
3873
  if (preAggregation.type === 'autoRollup') {
4175
3874
  return this.preAggregations.autoRollupPreAggregationQuery(cube, preAggregation);
@@ -4180,6 +3879,7 @@ class BaseQuery {
4180
3879
  else if (preAggregation.type === 'originalSql') {
4181
3880
  return this;
4182
3881
  }
3882
+ throw new Error(`Pre-aggregation type '${preAggregation.type}' has no SQL evaluation query`);
4183
3883
  }
4184
3884
  parseCronSyntax(every) {
4185
3885
  // Use the Unix epoch as the reference point for calculating dayOffset.
@@ -4219,6 +3919,7 @@ class BaseQuery {
4219
3919
  }
4220
3920
  let utcOffset = 0;
4221
3921
  if (refreshKey.timezone || this.timezone) {
3922
+ // TODO: falls back to UTC instead of `this.timezone` when only the query timezone is set
4222
3923
  utcOffset = moment_timezone_1.default.tz(refreshKey.timezone).utcOffset() * 60;
4223
3924
  }
4224
3925
  return {
@@ -4230,8 +3931,6 @@ class BaseQuery {
4230
3931
  /**
4231
3932
  * Both the rendered SQL and the descriptor handed to the orchestrator for local
4232
3933
  * evaluation derive from this, so they cannot disagree on the formula.
4233
- *
4234
- * @return {{ utcOffset: number, interval: number, dayOffset: number, cron: boolean }}
4235
3934
  */
4236
3935
  everyRefreshKeyParts(refreshKey) {
4237
3936
  const every = refreshKey.every || '1 hour';
@@ -4246,8 +3945,7 @@ class BaseQuery {
4246
3945
  return { ...this.calcIntervalForCronString(refreshKey), cron: true };
4247
3946
  }
4248
3947
  /**
4249
- * @protected
4250
- * @param {BaseQuery} [query] the instance that rendered the SQL, when it differs from `this`
3948
+ * @param query the instance that rendered the SQL, when it differs from `this`
4251
3949
  */
4252
3950
  localRefreshKeyOptions(refreshKey, query) {
4253
3951
  return this.localRefreshKey
@@ -4320,11 +4018,6 @@ class BaseQuery {
4320
4018
  }
4321
4019
  return 'second'; // TODO return 'millisecond';
4322
4020
  }
4323
- /**
4324
- * @protected
4325
- * @param {string} interval
4326
- * @return {[number, string]}
4327
- */
4328
4021
  parseInterval(interval) {
4329
4022
  const intervalMatch = interval.match(/^(-?\d+) (second|minute|hour|day|week|month|quarter|year)s?$/);
4330
4023
  if (!intervalMatch) {
@@ -4376,11 +4069,6 @@ class BaseQuery {
4376
4069
  * | 27089928 |
4377
4070
  * +-------------------------------------------+
4378
4071
  * 1 row in set (0.00 sec)
4379
- *
4380
- * @protected
4381
- *
4382
- * @param {string} sql
4383
- * @return {string}
4384
4072
  */
4385
4073
  refreshKeySelect(sql) {
4386
4074
  return `SELECT ${sql} as refresh_key`;
@@ -4465,6 +4153,7 @@ class BaseQuery {
4465
4153
  return preAggregationQueryForSql.evaluateSymbolSqlWithContext(() => preAggregationQueryForSql.cacheKeyQueries(), { preAggregationQuery: true });
4466
4154
  }, { inputProps: { collectOriginalSqlPreAggregations: [] }, cache: this.queryCache });
4467
4155
  }
4156
+ // `any`: preAggregationInvalidateKeyQueries() passes a refresh key whose `every` is optional, tested as a string here
4468
4157
  refreshKeyRenewalThresholdForInterval(refreshKey, everyWithoutSql = true) {
4469
4158
  const { every } = refreshKey;
4470
4159
  if (/^(\d+) (second|minute|hour|day|week)s?$/.test(every)) {
@@ -4529,16 +4218,15 @@ class BaseQuery {
4529
4218
  // dependencies it touched. The recording logic is a standalone, stateless
4530
4219
  // module so it can be unit-tested in isolation.
4531
4220
  compileMemberSql(sqlFn, securityContext, argNames) {
4532
- // eslint-disable-next-line global-require
4533
- const { compileMemberSql } = require('./MemberSqlTemplateCompiler');
4534
- return compileMemberSql(sqlFn, argNames, securityContext, this.sqlUtilsForRust());
4221
+ return (0, MemberSqlTemplateCompiler_1.compileMemberSql)(sqlFn, argNames, securityContext, this.sqlUtilsForRust());
4535
4222
  }
4536
4223
  contextSymbolsProxy(symbols) {
4537
4224
  return CubeSymbols_1.CubeSymbols.contextSymbolsProxyFrom(symbols, this.paramAllocator.allocateParam.bind(this.paramAllocator));
4538
4225
  }
4226
+ // `any`: walks initialized filters and segments, and BaseGroupFilter's `values` / `operator` are protected
4539
4227
  static extractFilterMembers(filter) {
4540
4228
  if (filter.operator === 'and' || filter.operator === 'or') {
4541
- return filter.values.map(f => BaseQuery.extractFilterMembers(f)).reduce((a, b) => ((a && b) ? { ...a, ...b } : null), {});
4229
+ return filter.values.map((f) => BaseQuery.extractFilterMembers(f)).reduce((a, b) => ((a && b) ? { ...a, ...b } : null), {});
4542
4230
  }
4543
4231
  else if (filter.measure) {
4544
4232
  return {
@@ -4554,7 +4242,9 @@ class BaseQuery {
4554
4242
  return null;
4555
4243
  }
4556
4244
  }
4557
- static findAndSubTreeForFilterGroup(filter, groupMembers, newGroupFilter, aliases) {
4245
+ static findAndSubTreeForFilterGroup(
4246
+ // `any`: as in extractFilterMembers()
4247
+ filter, groupMembers, newGroupFilter, aliases) {
4558
4248
  if ((filter.operator === 'and' || filter.operator === 'or') && !filter.values?.length) {
4559
4249
  return null;
4560
4250
  }
@@ -4563,7 +4253,9 @@ class BaseQuery {
4563
4253
  return filter;
4564
4254
  }
4565
4255
  if (filter.operator === 'and') {
4566
- const result = filter.values.map(f => BaseQuery.findAndSubTreeForFilterGroup(f, groupMembers, newGroupFilter, aliases)).filter(f => !!f);
4256
+ const result = filter.values
4257
+ .map((f) => BaseQuery.findAndSubTreeForFilterGroup(f, groupMembers, newGroupFilter, aliases))
4258
+ .filter((f) => !!f);
4567
4259
  if (!result.length) {
4568
4260
  return null;
4569
4261
  }
@@ -4591,14 +4283,18 @@ class BaseQuery {
4591
4283
  const allFilters = filters.map(this.initFilter.bind(this));
4592
4284
  return this.filterGroupFunctionImpl(allFilters);
4593
4285
  }
4594
- static renderFilterParams(filter, filterParamArgs, allocateParam, newGroupFilter, aliases) {
4286
+ static renderFilterParams(
4287
+ // `any`: as in extractFilterMembers()
4288
+ filter,
4289
+ // `any`: `__column()` is typeof-checked and then called again, which doesn't narrow its `unknown` result
4290
+ filterParamArgs, allocateParam, newGroupFilter, aliases) {
4595
4291
  if (!filter) {
4596
4292
  return BaseFilter_1.BaseFilter.ALWAYS_TRUE;
4597
4293
  }
4598
4294
  if (filter.operator === 'and' || filter.operator === 'or') {
4599
4295
  const values = filter.values
4600
- .map(f => BaseQuery.renderFilterParams(f, filterParamArgs, allocateParam, newGroupFilter, aliases))
4601
- .map(v => ({ filterToWhere: () => v }));
4296
+ .map((f) => BaseQuery.renderFilterParams(f, filterParamArgs, allocateParam, newGroupFilter, aliases))
4297
+ .map((v) => ({ filterToWhere: () => v }));
4602
4298
  return newGroupFilter({ operator: filter.operator, values }).filterToWhere();
4603
4299
  }
4604
4300
  const filterParams = filter.filterParams();
@@ -4643,7 +4339,8 @@ class BaseQuery {
4643
4339
  });
4644
4340
  const aliases = allFilters ?
4645
4341
  allFilters
4646
- .map(v => (v.query ? v.query.allBackAliasMembersExceptSegments() : {}))
4342
+ // `any`: `query` is protected on BaseDimension and BaseSegment
4343
+ .map((v) => (v.query ? v.query.allBackAliasMembersExceptSegments() : {}))
4647
4344
  .reduce((a, b) => ({ ...a, ...b }), {})
4648
4345
  : {};
4649
4346
  // Filtering aliases that somehow relate to this group members
@@ -4654,7 +4351,9 @@ class BaseQuery {
4654
4351
  return `(${BaseQuery.renderFilterParams(filter, filterParamArgs, allocateParam, newGroupFilter, aliases)})`;
4655
4352
  };
4656
4353
  }
4657
- static filterProxyFromAllFilters(allFilters, cubeEvaluator, allocateParam, newGroupFilter) {
4354
+ static filterProxyFromAllFilters(allFilters, cubeEvaluator, allocateParam,
4355
+ // `any`: called with the possibly null `allFilters` as group values
4356
+ newGroupFilter) {
4658
4357
  return new Proxy({}, {
4659
4358
  get: (_target, name) => {
4660
4359
  if (name === '_objectWithResolvedProperties') {
@@ -4701,7 +4400,9 @@ class BaseQuery {
4701
4400
  static get NOT_SHIFT_NAMES() {
4702
4401
  return new Set(['toString', 'valueOf', 'filter']);
4703
4402
  }
4704
- static filterProxyBinding(cubeName, propertyName, isTimeShift, column, allFilters, cubeEvaluator, allocateParam, newGroupFilter) {
4403
+ static filterProxyBinding(cubeName, propertyName, isTimeShift, column, allFilters, cubeEvaluator, allocateParam,
4404
+ // `any`: called with the possibly null `allFilters` as group values
4405
+ newGroupFilter) {
4705
4406
  return {
4706
4407
  __column() {
4707
4408
  return column;
@@ -4730,7 +4431,8 @@ class BaseQuery {
4730
4431
  // is checked below to prevent looping.
4731
4432
  const aliases = allFilters ?
4732
4433
  allFilters
4733
- .map(v => (v.query && !v.query.safeEvaluateSymbolContext().aliasGathering ? v.query.allBackAliasMembersExceptSegments() : {}))
4434
+ // `any`: `query` is protected on BaseDimension and BaseSegment
4435
+ .map((v) => (v.query && !v.query.safeEvaluateSymbolContext().aliasGathering ? v.query.allBackAliasMembersExceptSegments() : {}))
4734
4436
  .reduce((a, b) => ({ ...a, ...b }), {})
4735
4437
  : {};
4736
4438
  // Filtering aliases that somehow relate to this group member
@@ -4743,11 +4445,6 @@ class BaseQuery {
4743
4445
  }
4744
4446
  };
4745
4447
  }
4746
- /**
4747
- *
4748
- * @param {boolean} excludeSegments
4749
- * @returns {Array<BaseMeasure | BaseDimension | BaseSegment>}
4750
- */
4751
4448
  flattenAllMembers(excludeSegments = false) {
4752
4449
  return ramda_1.default.flatten(this.measures
4753
4450
  .concat(this.dimensions)
@@ -4757,30 +4454,16 @@ class BaseQuery {
4757
4454
  .concat(this.timeDimensions)
4758
4455
  .map(m => m.getMembers()));
4759
4456
  }
4760
- /**
4761
- * @returns {Record<string, string>}
4762
- */
4763
4457
  allBackAliasTimeDimensions() {
4764
4458
  const members = ramda_1.default.flatten(this.timeDimensions.map(m => m.getMembers()));
4765
4459
  return this.backAliasMembers(members);
4766
4460
  }
4767
- /**
4768
- * @returns {Record<string, string>}
4769
- */
4770
4461
  allBackAliasMembersExceptSegments() {
4771
4462
  return this.backAliasMembers(this.flattenAllMembers(true));
4772
4463
  }
4773
- /**
4774
- * @returns {Record<string, string>}
4775
- */
4776
4464
  allBackAliasMembers() {
4777
4465
  return this.backAliasMembers(this.flattenAllMembers());
4778
4466
  }
4779
- /**
4780
- *
4781
- * @param {Array<BaseMeasure | BaseDimension | BaseSegment>} members
4782
- * @returns {Record<string, string>}
4783
- */
4784
4467
  backAliasMembers(members) {
4785
4468
  const query = this;
4786
4469
  const aliases = Object.fromEntries(members.flatMap(member => {
@@ -4824,9 +4507,6 @@ class BaseQuery {
4824
4507
  return aliases;
4825
4508
  }
4826
4509
  const buildJoinPath = this.buildJoinPathFn();
4827
- /**
4828
- * @type {Record<string, string>}
4829
- */
4830
4510
  const res = {};
4831
4511
  for (const [original, alias] of Object.entries(aliases)) {
4832
4512
  const [cube, field] = original.split('.');
@@ -4850,10 +4530,6 @@ class BaseQuery {
4850
4530
  return (target) => {
4851
4531
  const visited = new Set();
4852
4532
  const path = [];
4853
- /**
4854
- * @param {string} node
4855
- * @returns {boolean}
4856
- */
4857
4533
  function dfs(node) {
4858
4534
  if (node === target) {
4859
4535
  path.push(node);
@@ -4863,7 +4539,7 @@ class BaseQuery {
4863
4539
  return false;
4864
4540
  }
4865
4541
  visited.add(node);
4866
- const neighbors = query.joinGraphPaths[node] || [];
4542
+ const neighbors = query.joinGraphPaths?.[node] || [];
4867
4543
  for (const neighbor of neighbors) {
4868
4544
  if (dfs(neighbor)) {
4869
4545
  path.unshift(node);
@@ -4878,7 +4554,6 @@ class BaseQuery {
4878
4554
  /**
4879
4555
  * Returns a function that constructs the full member path
4880
4556
  * based on the query's join structure.
4881
- * @returns {(member: string) => string}
4882
4557
  */
4883
4558
  resolveFullMemberPathFn() {
4884
4559
  const { root: queryJoinRoot } = this.join || {};