drizzle-cube 0.6.3 → 0.6.4

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 (56) hide show
  1. package/dist/adapters/compiler-DyyBaLry.cjs +166 -0
  2. package/dist/adapters/{compiler-LKTN9PTt.js → compiler-lG6eNsoI.js} +214 -210
  3. package/dist/adapters/express/index.cjs +1 -1
  4. package/dist/adapters/express/index.js +1 -1
  5. package/dist/adapters/fastify/index.cjs +1 -1
  6. package/dist/adapters/fastify/index.js +1 -1
  7. package/dist/adapters/hono/index.cjs +1 -1
  8. package/dist/adapters/hono/index.js +1 -1
  9. package/dist/adapters/nextjs/index.cjs +1 -1
  10. package/dist/adapters/nextjs/index.d.ts +10 -0
  11. package/dist/adapters/nextjs/index.js +13 -9
  12. package/dist/cjs/adapters/nextjs/index.d.ts +10 -0
  13. package/dist/cjs/client/components/AnalysisBuilder/utils/filterUtils.d.ts +4 -10
  14. package/dist/cjs/client/components/shared/utils.d.ts +2 -1
  15. package/dist/cjs/client/shared/filters/filterOperations.d.ts +95 -0
  16. package/dist/cjs/client/shared/filters/index.d.ts +10 -0
  17. package/dist/cjs/client/shared/filters/operators.d.ts +23 -0
  18. package/dist/cjs/client/shared/index.d.ts +3 -2
  19. package/dist/cjs/client/shared/types.d.ts +3 -10
  20. package/dist/cjs/client/shared/utils.d.ts +1 -59
  21. package/dist/cjs/client/utils/filterUtils.d.ts +2 -9
  22. package/dist/cjs/server/logical-plan/logical-plan-builder.d.ts +0 -5
  23. package/dist/cjs/server/logical-plan/schema-builder.d.ts +19 -0
  24. package/dist/client/chunks/{DashboardEditModal-CWurUU2B.js → DashboardEditModal-Cs1ig1_V.js} +1520 -1119
  25. package/dist/client/chunks/DashboardEditModal-Cs1ig1_V.js.map +1 -0
  26. package/dist/client/chunks/{analysis-builder-Uj_Fxv0-.js → analysis-builder-B64yaeDe.js} +73 -73
  27. package/dist/client/chunks/{analysis-builder-Uj_Fxv0-.js.map → analysis-builder-B64yaeDe.js.map} +1 -1
  28. package/dist/client/chunks/{analysis-builder-shared-AdAYIfj_.js → analysis-builder-shared-CD0n2Nb8.js} +948 -1023
  29. package/dist/client/chunks/analysis-builder-shared-CD0n2Nb8.js.map +1 -0
  30. package/dist/client/chunks/{useDirtyStateTracking-BY_IIG1n.js → useDirtyStateTracking-BT6zqCFl.js} +249 -590
  31. package/dist/client/chunks/useDirtyStateTracking-BT6zqCFl.js.map +1 -0
  32. package/dist/client/chunks/{useExplainAI-PjMBmj2p.js → useExplainAI-Dq_meKNN.js} +2 -2
  33. package/dist/client/chunks/{useExplainAI-PjMBmj2p.js.map → useExplainAI-Dq_meKNN.js.map} +1 -1
  34. package/dist/client/components/AnalysisBuilder/utils/filterUtils.d.ts +4 -10
  35. package/dist/client/components/shared/utils.d.ts +2 -1
  36. package/dist/client/components.js +2 -2
  37. package/dist/client/hooks.js +2 -2
  38. package/dist/client/index.js +13 -13
  39. package/dist/client/index.js.map +1 -1
  40. package/dist/client/shared/filters/filterOperations.d.ts +95 -0
  41. package/dist/client/shared/filters/index.d.ts +10 -0
  42. package/dist/client/shared/filters/operators.d.ts +23 -0
  43. package/dist/client/shared/index.d.ts +3 -2
  44. package/dist/client/shared/types.d.ts +3 -10
  45. package/dist/client/shared/utils.d.ts +1 -59
  46. package/dist/client/utils/filterUtils.d.ts +2 -9
  47. package/dist/client-bundle-stats.html +1 -1
  48. package/dist/server/index.cjs +33 -33
  49. package/dist/server/index.js +1272 -1268
  50. package/dist/server/logical-plan/logical-plan-builder.d.ts +0 -5
  51. package/dist/server/logical-plan/schema-builder.d.ts +19 -0
  52. package/package.json +3 -3
  53. package/dist/adapters/compiler-ChGO4ZLU.cjs +0 -166
  54. package/dist/client/chunks/DashboardEditModal-CWurUU2B.js.map +0 -1
  55. package/dist/client/chunks/analysis-builder-shared-AdAYIfj_.js.map +0 -1
  56. package/dist/client/chunks/useDirtyStateTracking-BY_IIG1n.js.map +0 -1
@@ -6317,7 +6317,88 @@ var ti = {
6317
6317
  buildPeriodNumberExpression(e, t, n) {
6318
6318
  return this.databaseAdapter.buildDateDiffPeriods(e, t, n);
6319
6319
  }
6320
- }, ri = class {
6320
+ };
6321
+ //#endregion
6322
+ //#region src/server/logical-plan/schema-builder.ts
6323
+ function Q(e) {
6324
+ return {
6325
+ name: e.name,
6326
+ cube: e
6327
+ };
6328
+ }
6329
+ function ri(e, t) {
6330
+ return e.measures ? e.measures.map((e) => {
6331
+ let [n, i] = e.split("."), a = t.get(n);
6332
+ if (!a) throw Error(r("server.errors.cubeNotFoundForMeasure", {
6333
+ cubeName: n,
6334
+ measure: e
6335
+ }));
6336
+ return {
6337
+ name: e,
6338
+ cube: Q(a),
6339
+ localName: i
6340
+ };
6341
+ }) : [];
6342
+ }
6343
+ function ii(e, t) {
6344
+ return e.dimensions ? e.dimensions.map((e) => {
6345
+ let [n, i] = e.split("."), a = t.get(n);
6346
+ if (!a) throw Error(r("server.errors.cubeNotFoundForDimension", {
6347
+ cubeName: n,
6348
+ dimension: e
6349
+ }));
6350
+ return {
6351
+ name: e,
6352
+ cube: Q(a),
6353
+ localName: i
6354
+ };
6355
+ }) : [];
6356
+ }
6357
+ function ai(e, t) {
6358
+ return e.timeDimensions ? e.timeDimensions.map((e) => {
6359
+ let [n, i] = e.dimension.split("."), a = t.get(n);
6360
+ if (!a) throw Error(r("server.errors.cubeNotFoundForTimeDimension", {
6361
+ cubeName: n,
6362
+ timeDimension: e.dimension
6363
+ }));
6364
+ return {
6365
+ name: e.dimension,
6366
+ cube: Q(a),
6367
+ localName: i,
6368
+ granularity: e.granularity,
6369
+ dateRange: e.dateRange,
6370
+ fillMissingDates: e.fillMissingDates,
6371
+ compareDateRange: e.compareDateRange
6372
+ };
6373
+ }) : [];
6374
+ }
6375
+ function oi(e, t) {
6376
+ return {
6377
+ measures: ri(e, t),
6378
+ dimensions: ii(e, t),
6379
+ timeDimensions: ai(e, t)
6380
+ };
6381
+ }
6382
+ function si(e, t) {
6383
+ return {
6384
+ measures: e.measures.map((e) => {
6385
+ let [n, r] = e.split(".");
6386
+ return {
6387
+ name: e,
6388
+ cube: {
6389
+ name: n,
6390
+ cube: t.get(n)
6391
+ },
6392
+ localName: r
6393
+ };
6394
+ }),
6395
+ dimensions: [],
6396
+ timeDimensions: []
6397
+ };
6398
+ }
6399
+ //#endregion
6400
+ //#region src/server/logical-plan/logical-plan-builder.ts
6401
+ var ci = class {
6321
6402
  queryPlanner;
6322
6403
  constructor(e) {
6323
6404
  this.queryPlanner = e;
@@ -6417,7 +6498,7 @@ var ti = {
6417
6498
  source: o,
6418
6499
  strategy: "multiFactMerge",
6419
6500
  classification: {
6420
- regular: this.buildMeasureRefs(i, r),
6501
+ regular: ri(i, r),
6421
6502
  multiplied: [],
6422
6503
  deduplicationSafe: []
6423
6504
  }
@@ -6434,11 +6515,11 @@ var ti = {
6434
6515
  };
6435
6516
  }
6436
6517
  buildSimpleSourceFromPhases(e, t, n, r, i) {
6437
- let a = this.buildMeasureRefs(i, r), o = this.buildDimensionRefs(i, r), s = this.buildTimeDimensionRefs(i, r), c = this.toCubeRef(e), l = t, u = n.map((e) => {
6438
- let t = this.toCubeRef(e.cube);
6518
+ let a = Q(e), o = t, s = n.map((e) => {
6519
+ let t = Q(e.cube);
6439
6520
  return {
6440
6521
  type: "ctePreAggregate",
6441
- schema: this.buildCTESchema(e, r),
6522
+ schema: si(e, r),
6442
6523
  cube: t,
6443
6524
  alias: e.alias,
6444
6525
  cteAlias: e.cteAlias,
@@ -6453,14 +6534,10 @@ var ti = {
6453
6534
  });
6454
6535
  return {
6455
6536
  type: "simpleSource",
6456
- schema: {
6457
- measures: a,
6458
- dimensions: o,
6459
- timeDimensions: s
6460
- },
6461
- primaryCube: c,
6462
- joins: l,
6463
- ctes: u
6537
+ schema: oi(i, r),
6538
+ primaryCube: a,
6539
+ joins: o,
6540
+ ctes: s
6464
6541
  };
6465
6542
  }
6466
6543
  tryBuildMultiFactMergeSource(e, t, n) {
@@ -6485,8 +6562,8 @@ var ti = {
6485
6562
  if (r.has(a) || !t.get(a)) return null;
6486
6563
  let o = Array.from(r);
6487
6564
  if (!o.every((e) => this.hasDirectJoinToSharedDimension(t.get(e), a, t))) return null;
6488
- let s = this.buildDimensionRefs(e, t), c = this.buildTimeDimensionRefs(e, t), l = {
6489
- measures: this.buildMeasureRefs(e, t),
6565
+ let s = ii(e, t), c = ai(e, t), l = {
6566
+ measures: ri(e, t),
6490
6567
  dimensions: s,
6491
6568
  timeDimensions: c
6492
6569
  }, u = [];
@@ -6647,20 +6724,16 @@ var ti = {
6647
6724
  return Array.from(t.values());
6648
6725
  }
6649
6726
  buildQueryNode(e, t, n, r) {
6650
- let i = this.buildMeasureRefs(t, n), a = this.buildDimensionRefs(t, n), o = this.buildTimeDimensionRefs(t, n), s = this.buildOrderByRefs(t), c = t.filters ?? [];
6727
+ let i = oi(t, n), { measures: a, dimensions: o, timeDimensions: s } = i, c = this.buildOrderByRefs(t);
6651
6728
  return {
6652
6729
  type: "query",
6653
- schema: {
6654
- measures: i,
6655
- dimensions: a,
6656
- timeDimensions: o
6657
- },
6730
+ schema: i,
6658
6731
  source: e,
6659
- dimensions: a,
6660
- measures: i,
6661
- filters: c,
6662
- timeDimensions: o,
6663
- orderBy: s,
6732
+ dimensions: o,
6733
+ measures: a,
6734
+ filters: t.filters ?? [],
6735
+ timeDimensions: s,
6736
+ orderBy: c,
6664
6737
  limit: t.limit,
6665
6738
  offset: t.offset,
6666
6739
  ungrouped: t.ungrouped,
@@ -6681,82 +6754,13 @@ var ti = {
6681
6754
  cteType: e.cteType
6682
6755
  }));
6683
6756
  }
6684
- buildMeasureRefs(e, t) {
6685
- return e.measures ? e.measures.map((e) => {
6686
- let [n, i] = e.split("."), a = t.get(n);
6687
- if (!a) throw Error(r("server.errors.cubeNotFoundForMeasure", {
6688
- cubeName: n,
6689
- measure: e
6690
- }));
6691
- return {
6692
- name: e,
6693
- cube: this.toCubeRef(a),
6694
- localName: i
6695
- };
6696
- }) : [];
6697
- }
6698
- buildDimensionRefs(e, t) {
6699
- return e.dimensions ? e.dimensions.map((e) => {
6700
- let [n, i] = e.split("."), a = t.get(n);
6701
- if (!a) throw Error(r("server.errors.cubeNotFoundForDimension", {
6702
- cubeName: n,
6703
- dimension: e
6704
- }));
6705
- return {
6706
- name: e,
6707
- cube: this.toCubeRef(a),
6708
- localName: i
6709
- };
6710
- }) : [];
6711
- }
6712
- buildTimeDimensionRefs(e, t) {
6713
- return e.timeDimensions ? e.timeDimensions.map((e) => {
6714
- let [n, i] = e.dimension.split("."), a = t.get(n);
6715
- if (!a) throw Error(r("server.errors.cubeNotFoundForTimeDimension", {
6716
- cubeName: n,
6717
- timeDimension: e.dimension
6718
- }));
6719
- return {
6720
- name: e.dimension,
6721
- cube: this.toCubeRef(a),
6722
- localName: i,
6723
- granularity: e.granularity,
6724
- dateRange: e.dateRange,
6725
- fillMissingDates: e.fillMissingDates,
6726
- compareDateRange: e.compareDateRange
6727
- };
6728
- }) : [];
6729
- }
6730
6757
  buildOrderByRefs(e) {
6731
6758
  return e.order ? Object.entries(e.order).map(([e, t]) => ({
6732
6759
  name: e,
6733
6760
  direction: t
6734
6761
  })) : [];
6735
6762
  }
6736
- toCubeRef(e) {
6737
- return {
6738
- name: e.name,
6739
- cube: e
6740
- };
6741
- }
6742
- buildCTESchema(e, t) {
6743
- return {
6744
- measures: e.measures.map((e) => {
6745
- let [n, r] = e.split(".");
6746
- return {
6747
- name: e,
6748
- cube: {
6749
- name: n,
6750
- cube: t.get(n)
6751
- },
6752
- localName: r
6753
- };
6754
- }),
6755
- dimensions: [],
6756
- timeDimensions: []
6757
- };
6758
- }
6759
- }, ii = class {
6763
+ }, li = class {
6760
6764
  name = "identity";
6761
6765
  optimise(e) {
6762
6766
  return e;
@@ -6764,11 +6768,11 @@ var ti = {
6764
6768
  };
6765
6769
  //#endregion
6766
6770
  //#region src/server/physical-plan/processors/cte-processor.ts
6767
- function ai(e, t, n, r) {
6768
- let i = oi(e, n, r), a = [], o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map();
6771
+ function ui(e, t, n, r) {
6772
+ let i = di(e, n, r), a = [], o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map();
6769
6773
  if (e.preAggregationCTEs && e.preAggregationCTEs.length > 0) for (let c of e.preAggregationCTEs) {
6770
6774
  let l = r.cteBuilder.buildPreAggregationCTE(c, t, n, e, i);
6771
- l && (a.push(l), o.set(c.cube.name, c.cteAlias), si(c, s));
6775
+ l && (a.push(l), o.set(c.cube.name, c.cteAlias), fi(c, s));
6772
6776
  }
6773
6777
  return {
6774
6778
  preBuiltFilterMap: i,
@@ -6777,7 +6781,7 @@ function ai(e, t, n, r) {
6777
6781
  downstreamCubeMap: s
6778
6782
  };
6779
6783
  }
6780
- function oi(e, t, n) {
6784
+ function di(e, t, n) {
6781
6785
  let r = /* @__PURE__ */ new Map();
6782
6786
  if (!e.preAggregationCTEs || e.preAggregationCTEs.length === 0) return r;
6783
6787
  for (let i of e.preAggregationCTEs) if (!(!i.propagatingFilters || i.propagatingFilters.length === 0)) for (let e of i.propagatingFilters) {
@@ -6791,7 +6795,7 @@ function oi(e, t, n) {
6791
6795
  }
6792
6796
  return r;
6793
6797
  }
6794
- function si(e, t) {
6798
+ function fi(e, t) {
6795
6799
  if (e.downstreamJoinKeys) for (let n of e.downstreamJoinKeys) t.set(n.targetCubeName, {
6796
6800
  cteAlias: e.cteAlias,
6797
6801
  joinKeys: n.joinKeys
@@ -6799,7 +6803,7 @@ function si(e, t) {
6799
6803
  }
6800
6804
  //#endregion
6801
6805
  //#region src/server/physical-plan/processors/window-processor.ts
6802
- function ci(e, t, n, r, i, a) {
6806
+ function pi(e, t, n, r, i, a) {
6803
6807
  if (n.measures) for (let o of n.measures) {
6804
6808
  let [s, c] = o.split("."), l = i.get(s);
6805
6809
  if (!l?.measures?.[c]) continue;
@@ -6811,11 +6815,11 @@ function ci(e, t, n, r, i, a) {
6811
6815
  if (!m?.measures?.[p]) continue;
6812
6816
  let h = m.measures[p], g = t.preAggregationCTEs?.find((e) => e.cube?.name === f && e.measures?.includes(d)), _;
6813
6817
  _ = g ? T`sum(${T`${T.identifier(g.cteAlias)}.${T.identifier(p)}`})` : a.queryBuilder.buildMeasureExpression(h, r, m), e[d] || (e[d] = T`${_}`.as(d));
6814
- let v = li(u, _, n, r, l, t, a);
6818
+ let v = mi(u, _, n, r, l, t, a);
6815
6819
  v && (e[o] = T`${v}`.as(o));
6816
6820
  }
6817
6821
  }
6818
- function li(e, t, n, r, i, a, o) {
6822
+ function mi(e, t, n, r, i, a, o) {
6819
6823
  let s = e.windowConfig || {}, c = (e, t) => {
6820
6824
  if (!a.preAggregationCTEs) return null;
6821
6825
  let n = a.preAggregationCTEs.find((t) => t.cube?.name === e);
@@ -6885,23 +6889,23 @@ function li(e, t, n, r, i, a, o) {
6885
6889
  }
6886
6890
  //#endregion
6887
6891
  //#region src/server/physical-plan/processors/selection-processor.ts
6888
- function ui(e, t, n, r, i) {
6892
+ function hi(e, t, n, r, i) {
6889
6893
  let a = { ...i.queryBuilder.buildSelections(e.joinCubes.length > 0 ? r : e.primaryCube, t, n) };
6890
- if (e.preAggregationCTEs) for (let o of e.preAggregationCTEs) di(a, o, t, n, r, i), pi(a, o, r);
6891
- return ci(a, e, t, n, r, i), a;
6894
+ if (e.preAggregationCTEs) for (let o of e.preAggregationCTEs) gi(a, o, t, n, r, i), vi(a, o, r);
6895
+ return pi(a, e, t, n, r, i), a;
6892
6896
  }
6893
- function di(e, t, n, r, i, a) {
6897
+ function gi(e, t, n, r, i, a) {
6894
6898
  let o = t.cube.name;
6895
6899
  for (let s of t.measures) {
6896
6900
  if (!e[s]) continue;
6897
6901
  let [, c] = s.split("."), l = i.get(o);
6898
6902
  if (!l?.measures?.[c]) continue;
6899
6903
  let u = l.measures[c], d = T`${T.identifier(t.cteAlias)}.${T.identifier(c)}`, f;
6900
- f = u.type === "calculated" && u.calculatedSql ? a.queryBuilder.buildCTECalculatedMeasure(u, l, t, i, r) : fi(u, d, t, n, i, a), e[s] = T`${f}`.as(s);
6904
+ f = u.type === "calculated" && u.calculatedSql ? a.queryBuilder.buildCTECalculatedMeasure(u, l, t, i, r) : _i(u, d, t, n, i, a), e[s] = T`${f}`.as(s);
6901
6905
  }
6902
6906
  }
6903
- function fi(e, t, n, r, i, a) {
6904
- let o = n.cteReason === "fanOutPrevention", s = mi(n, r, i), c = o || s;
6907
+ function _i(e, t, n, r, i, a) {
6908
+ let o = n.cteReason === "fanOutPrevention", s = yi(n, r, i), c = o || s;
6905
6909
  switch (e.type) {
6906
6910
  case "count":
6907
6911
  case "countDistinct":
@@ -6913,7 +6917,7 @@ function fi(e, t, n, r, i, a) {
6913
6917
  default: return c ? M(t) : j(t);
6914
6918
  }
6915
6919
  }
6916
- function pi(e, t, n) {
6920
+ function vi(e, t, n) {
6917
6921
  let r = t.cube.name;
6918
6922
  for (let i in e) {
6919
6923
  let [a, o] = i.split(".");
@@ -6928,10 +6932,10 @@ function pi(e, t, n) {
6928
6932
  (u || l && s?.dimensions?.[o]) && (e[i] = T`${T.identifier(t.cteAlias)}.${T.identifier(o)}`.as(i));
6929
6933
  }
6930
6934
  }
6931
- function mi(e, t, n) {
6932
- return e.cteReason !== "hasMany" || e.downstreamJoinKeys && e.downstreamJoinKeys.length > 0 || e.intermediateJoins && e.intermediateJoins.length > 0 || !(t.dimensions && t.dimensions.length > 0 || t.timeDimensions && t.timeDimensions.length > 0) || t.dimensions?.some((t) => t.startsWith(`${e.cube.name}.`)) || t.timeDimensions?.some((t) => t.dimension.startsWith(`${e.cube.name}.`)) ? !1 : e.joinKeys.length > 0 && e.joinKeys.every((e) => !!e.sourceColumnObj && hi(e.sourceColumnObj, t, n));
6935
+ function yi(e, t, n) {
6936
+ return e.cteReason !== "hasMany" || e.downstreamJoinKeys && e.downstreamJoinKeys.length > 0 || e.intermediateJoins && e.intermediateJoins.length > 0 || !(t.dimensions && t.dimensions.length > 0 || t.timeDimensions && t.timeDimensions.length > 0) || t.dimensions?.some((t) => t.startsWith(`${e.cube.name}.`)) || t.timeDimensions?.some((t) => t.dimension.startsWith(`${e.cube.name}.`)) ? !1 : e.joinKeys.length > 0 && e.joinKeys.every((e) => !!e.sourceColumnObj && bi(e.sourceColumnObj, t, n));
6933
6937
  }
6934
- function hi(e, t, n) {
6938
+ function bi(e, t, n) {
6935
6939
  if (t.dimensions) for (let r of t.dimensions) {
6936
6940
  let [t, i] = r.split(".");
6937
6941
  if (n.get(t)?.dimensions?.[i]?.sql === e) return !0;
@@ -6945,7 +6949,7 @@ function hi(e, t, n) {
6945
6949
  }
6946
6950
  //#endregion
6947
6951
  //#region src/server/physical-plan/processors/shared.ts
6948
- function Q(e, t, n, r) {
6952
+ function $(e, t, n, r) {
6949
6953
  switch (t) {
6950
6954
  case "inner": return e.innerJoin(n, r);
6951
6955
  case "right": return e.rightJoin(n, r);
@@ -6953,20 +6957,20 @@ function Q(e, t, n, r) {
6953
6957
  default: return e.leftJoin(n, r);
6954
6958
  }
6955
6959
  }
6956
- function gi(e) {
6960
+ function xi(e) {
6957
6961
  let t = /* @__PURE__ */ new Map();
6958
6962
  if (t.set(e.primaryCube.name, e.primaryCube), e.joinCubes) for (let n of e.joinCubes) t.set(n.cube.name, n.cube);
6959
6963
  return t;
6960
6964
  }
6961
6965
  //#endregion
6962
6966
  //#region src/server/physical-plan/processors/joins-processor.ts
6963
- function _i(e, t, n, r, i, a) {
6964
- let o = [], s = vi(t, n, r, i);
6965
- s = yi(s, n.joins);
6966
- let c = /* @__PURE__ */ new Set(), l = bi(e);
6967
+ function Si(e, t, n, r, i, a) {
6968
+ let o = [], s = Ci(t, n, r, i);
6969
+ s = wi(s, n.joins);
6970
+ let c = /* @__PURE__ */ new Set(), l = Ti(e);
6967
6971
  if (e.joinCubes && e.joinCubes.length > 0) for (let n of e.joinCubes) {
6968
6972
  let r = n.cube.name;
6969
- l.has(r) && !i.cteAliasMap.has(r) || (s = xi(s, n, e, i, t, o), s = wi(s, n, e, i, t, a, c));
6973
+ l.has(r) && !i.cteAliasMap.has(r) || (s = Ei(s, n, e, i, t, o), s = ki(s, n, e, i, t, a, c));
6970
6974
  }
6971
6975
  return {
6972
6976
  drizzleQuery: s,
@@ -6975,38 +6979,38 @@ function _i(e, t, n, r, i, a) {
6975
6979
  absorbedIntermediateCubes: l
6976
6980
  };
6977
6981
  }
6978
- function vi(e, t, n, r) {
6982
+ function Ci(e, t, n, r) {
6979
6983
  return r.ctes.length > 0 ? e.db.with(...r.ctes).select(n).from(t.from) : e.db.select(n).from(t.from);
6980
6984
  }
6981
- function yi(e, t) {
6985
+ function wi(e, t) {
6982
6986
  if (!t) return e;
6983
6987
  let n = e;
6984
- for (let e of t) n = Q(n, e.type ?? "left", e.table, e.on);
6988
+ for (let e of t) n = $(n, e.type ?? "left", e.table, e.on);
6985
6989
  return n;
6986
6990
  }
6987
- function bi(e) {
6991
+ function Ti(e) {
6988
6992
  let t = /* @__PURE__ */ new Set();
6989
6993
  if (e.preAggregationCTEs) {
6990
6994
  for (let n of e.preAggregationCTEs) if (n.intermediateJoins && n.intermediateJoins.length > 0) for (let e of n.intermediateJoins) t.add(e.cube.name);
6991
6995
  }
6992
6996
  return t;
6993
6997
  }
6994
- function xi(e, t, n, r, i, a) {
6998
+ function Ei(e, t, n, r, i, a) {
6995
6999
  let o = t.junctionTable;
6996
7000
  if (!o) return e;
6997
- let s = Si(o, t, n, r), c = [];
7001
+ let s = Di(o, t, n, r), c = [];
6998
7002
  if (o.securitySql) {
6999
7003
  let e = o.securitySql(i.securityContext);
7000
7004
  Array.isArray(e) ? c.push(...e) : c.push(e);
7001
7005
  }
7002
7006
  try {
7003
- let t = Q(e, o.joinType ?? "left", o.table, s);
7007
+ let t = $(e, o.joinType ?? "left", o.table, s);
7004
7008
  return c.length > 0 && a.push(...c), t;
7005
7009
  } catch {
7006
7010
  return e;
7007
7011
  }
7008
7012
  }
7009
- function Si(e, t, n, r) {
7013
+ function Di(e, t, n, r) {
7010
7014
  let i = e.joinCondition, a = e.sourceCubeName ? r.cteAliasMap.get(e.sourceCubeName) : void 0;
7011
7015
  if (!a) return i;
7012
7016
  let o = (n.preAggregationCTEs?.find((t) => t.cube.name === e.sourceCubeName))?.downstreamJoinKeys?.find((e) => e.targetCubeName === t.cube.name);
@@ -7020,7 +7024,7 @@ function Si(e, t, n, r) {
7020
7024
  }
7021
7025
  return i;
7022
7026
  }
7023
- function Ci(e, t, n, r, i, a) {
7027
+ function Oi(e, t, n, r, i, a) {
7024
7028
  if (t) return {
7025
7029
  joinTarget: T`${T.identifier(t)}`,
7026
7030
  joinCondition: a.cteBuilder.buildCTEJoinCondition(e, t, r),
@@ -7043,26 +7047,26 @@ function Ci(e, t, n, r, i, a) {
7043
7047
  joinCubeBase: s
7044
7048
  };
7045
7049
  }
7046
- function wi(e, t, n, r, i, a, o) {
7047
- let { joinTarget: s, joinCondition: c, securityCondition: l, joinCubeBase: u } = Ci(t, r.cteAliasMap.get(t.cube.name), r, n, i, a), d = t.joinType || "left", f = d !== "inner" && l ? k(c, l) : c;
7050
+ function ki(e, t, n, r, i, a, o) {
7051
+ let { joinTarget: s, joinCondition: c, securityCondition: l, joinCubeBase: u } = Oi(t, r.cteAliasMap.get(t.cube.name), r, n, i, a), d = t.joinType || "left", f = d !== "inner" && l ? k(c, l) : c;
7048
7052
  try {
7049
7053
  let n;
7050
- return d === "inner" ? n = e.innerJoin(s, c) : (n = Q(e, d, s, f), l && o.add(t.cube.name)), yi(n, u?.joins);
7054
+ return d === "inner" ? n = e.innerJoin(s, c) : (n = $(e, d, s, f), l && o.add(t.cube.name)), wi(n, u?.joins);
7051
7055
  } catch {
7052
7056
  return e;
7053
7057
  }
7054
7058
  }
7055
7059
  //#endregion
7056
7060
  //#region src/server/physical-plan/processors/predicates-processor.ts
7057
- function Ti(e, t, n, r, i, a, o, s) {
7058
- let c = Ei(e, t, n, r, i, a, o, s), l = o.drizzleQuery;
7061
+ function Ai(e, t, n, r, i, a, o, s) {
7062
+ let c = ji(e, t, n, r, i, a, o, s), l = o.drizzleQuery;
7059
7063
  if (c.length > 0) {
7060
7064
  let e = c.length === 1 ? c[0] : k(...c);
7061
7065
  l = l.where(e);
7062
7066
  }
7063
- return Di(l, e, t, n, r, s);
7067
+ return Mi(l, e, t, n, r, s);
7064
7068
  }
7065
- function Ei(e, t, n, r, i, a, o, s) {
7069
+ function ji(e, t, n, r, i, a, o, s) {
7066
7070
  let c = [...o.allWhereConditions];
7067
7071
  if (i.where && c.push(i.where), e.joinCubes && e.joinCubes.length > 0) for (let t of e.joinCubes) {
7068
7072
  let e = t.cube.name;
@@ -7073,7 +7077,7 @@ function Ei(e, t, n, r, i, a, o, s) {
7073
7077
  let l = s.queryBuilder.buildWhereConditions(e.joinCubes.length > 0 ? r : e.primaryCube, t, n, e, a.preBuiltFilterMap);
7074
7078
  return l.length > 0 && c.push(...l), c;
7075
7079
  }
7076
- function Di(e, t, n, r, i, a) {
7080
+ function Mi(e, t, n, r, i, a) {
7077
7081
  let o = t.joinCubes.length > 0 ? i : t.primaryCube, s = e, c = a.queryBuilder.buildGroupByFields(o, n, r, t);
7078
7082
  if (c.length > 0 && (s = s.groupBy(...c)), !n.ungrouped) {
7079
7083
  let e = a.queryBuilder.buildHavingConditions(o, n, r, t);
@@ -7087,17 +7091,17 @@ function Di(e, t, n, r, i, a) {
7087
7091
  }
7088
7092
  //#endregion
7089
7093
  //#region src/server/physical-plan/processors/keys-dedup-processor.ts
7090
- function Oi(e, t, n, r) {
7094
+ function Ni(e, t, n, r) {
7091
7095
  let i = e.keysDeduplication;
7092
7096
  if (!i?.multipliedCubeName || !t.measures?.length) return null;
7093
- let a = e.joinCubes.length > 0 ? gi(e) : new Map([[e.primaryCube.name, e.primaryCube]]), o = a.get(i.multipliedCubeName);
7094
- if (!o || !Li(t, o, i.multipliedCubeName)) return null;
7095
- let s = i.primaryKeyDimensions.length > 0 ? i.primaryKeyDimensions : zi(o);
7097
+ let a = e.joinCubes.length > 0 ? xi(e) : new Map([[e.primaryCube.name, e.primaryCube]]), o = a.get(i.multipliedCubeName);
7098
+ if (!o || !Hi(t, o, i.multipliedCubeName)) return null;
7099
+ let s = i.primaryKeyDimensions.length > 0 ? i.primaryKeyDimensions : Wi(o);
7096
7100
  if (s.length === 0) return null;
7097
- let c = `${i.multipliedCubeName.toLowerCase()}_keys`, l = `${i.multipliedCubeName.toLowerCase()}_pk_agg`, u = i.regularMeasures ?? [], d = ki(t, n, r, a, o, s, u);
7101
+ let c = `${i.multipliedCubeName.toLowerCase()}_keys`, l = `${i.multipliedCubeName.toLowerCase()}_pk_agg`, u = i.regularMeasures ?? [], d = Pi(t, n, r, a, o, s, u);
7098
7102
  if (!d) return null;
7099
- let f = Ai(e, t, n, r, a, c, d.keysSelections, d.keyGroupBy), p = Ni(t, n, r, o, s, d.multipliedMeasures, l);
7100
- return p ? Ii(t, n, r, a, o, {
7103
+ let f = Fi(e, t, n, r, a, c, d.keysSelections, d.keyGroupBy), p = Ri(t, n, r, o, s, d.multipliedMeasures, l);
7104
+ return p ? Vi(t, n, r, a, o, {
7101
7105
  keysAlias: c,
7102
7106
  aggAlias: l,
7103
7107
  keysCte: f,
@@ -7108,7 +7112,7 @@ function Oi(e, t, n, r) {
7108
7112
  regularMeasureNames: u
7109
7113
  }) : null;
7110
7114
  }
7111
- function ki(e, t, n, r, i, a, o) {
7115
+ function Pi(e, t, n, r, i, a, o) {
7112
7116
  let s = {}, c = [];
7113
7117
  if (e.dimensions) for (let n of e.dimensions) {
7114
7118
  let [e, i] = n.split("."), a = r.get(e), o = a?.dimensions?.[i];
@@ -7146,35 +7150,35 @@ function ki(e, t, n, r, i, a, o) {
7146
7150
  multipliedMeasures: d
7147
7151
  };
7148
7152
  }
7149
- function Ai(e, t, n, r, i, a, o, s) {
7153
+ function Fi(e, t, n, r, i, a, o, s) {
7150
7154
  let c = e.primaryCube.sql(n), l = [];
7151
7155
  c.where && l.push(c.where);
7152
7156
  let u = n.db.select(o).from(c.from);
7153
- if (c.joins) for (let e of c.joins) u = Q(u, e.type ?? "left", e.table, e.on);
7154
- for (let t of e.joinCubes) u = ji(u, t, n, l);
7155
- return l.push(...r.queryBuilder.buildWhereConditions(i, t, n)), u = Fi(u, l), s.length > 0 && (u = u.groupBy(...s)), n.db.$with(a).as(u);
7157
+ if (c.joins) for (let e of c.joins) u = $(u, e.type ?? "left", e.table, e.on);
7158
+ for (let t of e.joinCubes) u = Ii(u, t, n, l);
7159
+ return l.push(...r.queryBuilder.buildWhereConditions(i, t, n)), u = Bi(u, l), s.length > 0 && (u = u.groupBy(...s)), n.db.$with(a).as(u);
7156
7160
  }
7157
- function ji(e, t, n, r) {
7161
+ function Ii(e, t, n, r) {
7158
7162
  let i = e;
7159
- t.junctionTable && (i = Q(i, t.junctionTable.joinType ?? "left", t.junctionTable.table, t.junctionTable.joinCondition), Mi(t.junctionTable.securitySql, n, r));
7163
+ t.junctionTable && (i = $(i, t.junctionTable.joinType ?? "left", t.junctionTable.table, t.junctionTable.joinCondition), Li(t.junctionTable.securitySql, n, r));
7160
7164
  let a = t.cube.sql(n);
7161
- if (i = Q(i, t.joinType ?? "left", a.from, t.joinCondition), a.joins) for (let e of a.joins) i = Q(i, e.type ?? "left", e.table, e.on);
7165
+ if (i = $(i, t.joinType ?? "left", a.from, t.joinCondition), a.joins) for (let e of a.joins) i = $(i, e.type ?? "left", e.table, e.on);
7162
7166
  return a.where && r.push(a.where), i;
7163
7167
  }
7164
- function Mi(e, t, n) {
7168
+ function Li(e, t, n) {
7165
7169
  if (!e) return;
7166
7170
  let r = e(t.securityContext);
7167
7171
  Array.isArray(r) ? n.push(...r) : n.push(r);
7168
7172
  }
7169
- function Ni(e, t, n, r, i, a, o) {
7170
- let s = r.sql(t), c = Pi(t, n, r, i, a);
7173
+ function Ri(e, t, n, r, i, a, o) {
7174
+ let s = r.sql(t), c = zi(t, n, r, i, a);
7171
7175
  if (!c) return null;
7172
7176
  let l = t.db.select(c.aggSelections).from(s.from);
7173
- if (s.joins) for (let e of s.joins) l = Q(l, e.type ?? "left", e.table, e.on);
7177
+ if (s.joins) for (let e of s.joins) l = $(l, e.type ?? "left", e.table, e.on);
7174
7178
  let u = [];
7175
- return s.where && u.push(s.where), u.push(...n.queryBuilder.buildWhereConditions(r, e, t)), l = Fi(l, u), c.aggGroupBy.length > 0 && (l = l.groupBy(...c.aggGroupBy)), t.db.$with(o).as(l);
7179
+ return s.where && u.push(s.where), u.push(...n.queryBuilder.buildWhereConditions(r, e, t)), l = Bi(l, u), c.aggGroupBy.length > 0 && (l = l.groupBy(...c.aggGroupBy)), t.db.$with(o).as(l);
7176
7180
  }
7177
- function Pi(e, t, n, r, i) {
7181
+ function zi(e, t, n, r, i) {
7178
7182
  let a = {}, o = [];
7179
7183
  for (let t of r) {
7180
7184
  let r = n.dimensions?.[t];
@@ -7212,20 +7216,20 @@ function Pi(e, t, n, r, i) {
7212
7216
  aggGroupBy: o
7213
7217
  };
7214
7218
  }
7215
- function Fi(e, t) {
7219
+ function Bi(e, t) {
7216
7220
  return t.length === 0 ? e : e.where(t.length === 1 ? t[0] : k(...t));
7217
7221
  }
7218
- function Ii(e, t, n, r, i, a) {
7222
+ function Vi(e, t, n, r, i, a) {
7219
7223
  let { keysAlias: o, aggAlias: s, keysCte: c, aggCte: l, pkDimensions: u, pkAliases: d, multipliedMeasures: f, regularMeasureNames: p } = a, m = {};
7220
7224
  for (let t of e.dimensions ?? []) m[t] = T`${T.identifier(o)}.${T.identifier(t)}`.as(t);
7221
7225
  for (let t of e.timeDimensions ?? []) m[t.dimension] = T`${T.identifier(o)}.${T.identifier(t.dimension)}`.as(t.dimension);
7222
7226
  for (let e of f) {
7223
7227
  let [, t] = e.split("."), n = i.measures?.[t];
7224
- m[e] = Bi(n?.type ?? "sum", s, t, e);
7228
+ m[e] = Gi(n?.type ?? "sum", s, t, e);
7225
7229
  }
7226
7230
  for (let e of p) {
7227
7231
  let [t, n] = e.split("."), i = r.get(t)?.measures?.[n], a = `__reg__${e.replace(".", "__")}`;
7228
- m[e] = Bi(i?.type ?? "sum", o, a, e);
7232
+ m[e] = Gi(i?.type ?? "sum", o, a, e);
7229
7233
  }
7230
7234
  let h = t.db.with(c, l).select(m).from(T`${T.identifier(o)}`), g = d.map((e, t) => O(T`${T.identifier(o)}.${T.identifier(e)}`, T`${T.identifier(s)}.${T.identifier(u[t])}`)), _ = g.length === 1 ? g[0] : k(...g);
7231
7235
  h = h.leftJoin(T`${T.identifier(s)}`, _);
@@ -7234,7 +7238,7 @@ function Ii(e, t, n, r, i, a) {
7234
7238
  let y = n.queryBuilder.buildOrderBy(e, Object.keys(m));
7235
7239
  return y.length > 0 && (h = h.orderBy(...y)), n.queryBuilder.applyLimitAndOffset(h, e);
7236
7240
  }
7237
- function Li(e, t, n) {
7241
+ function Hi(e, t, n) {
7238
7242
  if (!e.measures?.length) return !1;
7239
7243
  for (let r of e.measures) {
7240
7244
  let [e, i] = r.split(".");
@@ -7249,9 +7253,9 @@ function Li(e, t, n) {
7249
7253
  "avg"
7250
7254
  ].includes(a.type)) return !1;
7251
7255
  }
7252
- return !Ri(e, t, n);
7256
+ return !Ui(e, t, n);
7253
7257
  }
7254
- function Ri(e, t, n) {
7258
+ function Ui(e, t, n) {
7255
7259
  let r = (e) => {
7256
7260
  if (!e) return !1;
7257
7261
  for (let i of e) {
@@ -7272,10 +7276,10 @@ function Ri(e, t, n) {
7272
7276
  };
7273
7277
  return r(e.filters);
7274
7278
  }
7275
- function zi(e) {
7279
+ function Wi(e) {
7276
7280
  return Object.entries(e.dimensions ?? {}).filter(([, e]) => !!e.primaryKey).map(([e]) => e);
7277
7281
  }
7278
- function Bi(e, t, n, r) {
7282
+ function Gi(e, t, n, r) {
7279
7283
  switch (e) {
7280
7284
  case "min": return T`min(${T`${T.identifier(t)}.${T.identifier(n)}`})`.as(r);
7281
7285
  case "max": return T`max(${T`${T.identifier(t)}.${T.identifier(n)}`})`.as(r);
@@ -7285,38 +7289,38 @@ function Bi(e, t, n, r) {
7285
7289
  }
7286
7290
  //#endregion
7287
7291
  //#region src/server/physical-plan/processors/multi-fact-processor.ts
7288
- function Vi(e, t, n, r, i) {
7292
+ function Ki(e, t, n, r, i) {
7289
7293
  let a = e.multiFactMerge;
7290
7294
  if (!a || a.groups.length < 2) return null;
7291
- let o = [...t.dimensions ?? [], ...(t.timeDimensions ?? []).map((e) => e.dimension)], s = Array.from(new Set(o)), c = s.length > 0, l = Ji(r), u = c && a.mergeStrategy === "fullJoin" && !l, d = a.groups.map((e) => {
7295
+ let o = [...t.dimensions ?? [], ...(t.timeDimensions ?? []).map((e) => e.dimension)], s = Array.from(new Set(o)), c = s.length > 0, l = $i(r), u = c && a.mergeStrategy === "fullJoin" && !l, d = a.groups.map((e) => {
7292
7296
  let t = i(e.queryPlan, e.query, n);
7293
7297
  return n.db.$with(e.alias).as(t);
7294
7298
  });
7295
- return u ? Gi(t, n, r, a, d, s) : Wi(t, n, r, a, d, s, qi(a.mergeStrategy, c, l));
7299
+ return u ? Xi(t, n, r, a, d, s) : Yi(t, n, r, a, d, s, Qi(a.mergeStrategy, c, l));
7296
7300
  }
7297
- function Hi(e, t, n) {
7301
+ function qi(e, t, n) {
7298
7302
  let r = {};
7299
- for (let e of t) r[e] = T`${Yi(n, e)}`.as(e);
7303
+ for (let e of t) r[e] = T`${ea(n, e)}`.as(e);
7300
7304
  for (let t of e.groups) for (let e of t.measures) r[e] = T`coalesce(${T`${T.identifier(t.alias)}.${T.identifier(e)}`}, 0)`.as(e);
7301
7305
  return r;
7302
7306
  }
7303
- function Ui(e, t, n) {
7307
+ function Ji(e, t, n) {
7304
7308
  if (t.length === 0) return T`1 = 1`;
7305
7309
  let r = t.map((t) => O(n.get(t), T`${T.identifier(e)}.${T.identifier(t)}`));
7306
7310
  return r.length === 1 ? r[0] : k(...r);
7307
7311
  }
7308
- function Wi(e, t, n, r, i, a, o) {
7309
- let s = r.groups[0].alias, c = Hi(r, a, r.groups.map((e) => e.alias)), l = t.db.with(...i).select(c).from(T`${T.identifier(s)}`), u = /* @__PURE__ */ new Map();
7312
+ function Yi(e, t, n, r, i, a, o) {
7313
+ let s = r.groups[0].alias, c = qi(r, a, r.groups.map((e) => e.alias)), l = t.db.with(...i).select(c).from(T`${T.identifier(s)}`), u = /* @__PURE__ */ new Map();
7310
7314
  for (let e of a) u.set(e, T`${T.identifier(s)}.${T.identifier(e)}`);
7311
7315
  for (let e = 1; e < r.groups.length; e++) {
7312
- let t = r.groups[e].alias, n = Ui(t, a, u);
7313
- if (l = Q(l, o, T`${T.identifier(t)}`, n), a.length > 0 && o === "full") for (let e of a) u.set(e, T`coalesce(${u.get(e)}, ${T`${T.identifier(t)}.${T.identifier(e)}`})`);
7316
+ let t = r.groups[e].alias, n = Ji(t, a, u);
7317
+ if (l = $(l, o, T`${T.identifier(t)}`, n), a.length > 0 && o === "full") for (let e of a) u.set(e, T`coalesce(${u.get(e)}, ${T`${T.identifier(t)}.${T.identifier(e)}`})`);
7314
7318
  }
7315
7319
  let d = n.queryBuilder.buildOrderBy(e, Object.keys(c));
7316
7320
  return d.length > 0 && (l = l.orderBy(...d)), n.queryBuilder.applyLimitAndOffset(l, e);
7317
7321
  }
7318
- function Gi(e, t, n, r, i, a) {
7319
- let o = "mf_all_keys", s = r.groups.map((e) => T`select ${Ki(e.alias, a)} from ${T.identifier(e.alias)}`), c = T`${T.join(s, T` union `)}`, l = t.db.$with(o).as(c), u = {};
7322
+ function Xi(e, t, n, r, i, a) {
7323
+ let o = "mf_all_keys", s = r.groups.map((e) => T`select ${Zi(e.alias, a)} from ${T.identifier(e.alias)}`), c = T`${T.join(s, T` union `)}`, l = t.db.$with(o).as(c), u = {};
7320
7324
  for (let e of a) u[e] = T`${T.identifier(o)}.${T.identifier(e)}`.as(e);
7321
7325
  for (let e of r.groups) for (let t of e.measures) u[t] = T`coalesce(${T`${T.identifier(e.alias)}.${T.identifier(t)}`}, 0)`.as(t);
7322
7326
  let d = t.db.with(...i, l).select(u).from(T`${T.identifier(o)}`);
@@ -7327,18 +7331,18 @@ function Gi(e, t, n, r, i, a) {
7327
7331
  let f = n.queryBuilder.buildOrderBy(e, Object.keys(u));
7328
7332
  return f.length > 0 && (d = d.orderBy(...f)), n.queryBuilder.applyLimitAndOffset(d, e);
7329
7333
  }
7330
- function Ki(e, t) {
7334
+ function Zi(e, t) {
7331
7335
  let n = t.map((t) => T`${T.identifier(e)}.${T.identifier(t)} as ${T.identifier(t)}`);
7332
7336
  return T.join(n, T`, `);
7333
7337
  }
7334
- function qi(e, t, n) {
7338
+ function Qi(e, t, n) {
7335
7339
  return !t || e === "innerJoin" ? "inner" : e === "leftJoin" ? "left" : n ? "full" : "left";
7336
7340
  }
7337
- function Ji(e) {
7341
+ function $i(e) {
7338
7342
  let t = e.databaseAdapter.getEngineType();
7339
7343
  return t === "postgres" || t === "duckdb";
7340
7344
  }
7341
- function Yi(e, t) {
7345
+ function ea(e, t) {
7342
7346
  if (e.length === 1) return T`${T.identifier(e[0])}.${T.identifier(t)}`;
7343
7347
  let n = e.map((e) => T`${T.identifier(e)}.${T.identifier(t)}`), r = n[0];
7344
7348
  for (let e = 1; e < n.length; e++) r = T`coalesce(${r}, ${n[e]})`;
@@ -7346,7 +7350,7 @@ function Yi(e, t) {
7346
7350
  }
7347
7351
  //#endregion
7348
7352
  //#region src/server/physical-plan/drizzle-plan-builder.ts
7349
- var Xi = class {
7353
+ var ta = class {
7350
7354
  queryBuilder;
7351
7355
  cteBuilder;
7352
7356
  databaseAdapter;
@@ -7507,23 +7511,23 @@ var Xi = class {
7507
7511
  queryBuilder: this.queryBuilder,
7508
7512
  cteBuilder: this.cteBuilder,
7509
7513
  databaseAdapter: this.databaseAdapter
7510
- }, i = Vi(e, t, n, r, (e, t, n) => this.build(e, t, n));
7514
+ }, i = Ki(e, t, n, r, (e, t, n) => this.build(e, t, n));
7511
7515
  if (i) return i;
7512
- let a = Oi(e, t, n, r);
7516
+ let a = Ni(e, t, n, r);
7513
7517
  if (a) return a;
7514
- let o = ai(e, t, n, r), s = e.primaryCube.sql(n), c = e.joinCubes.length > 0 ? gi(e) : new Map([[e.primaryCube.name, e.primaryCube]]);
7515
- return Ti(e, t, n, c, s, o, _i(e, n, s, ui(e, t, n, c, r), o, r), r);
7518
+ let o = ui(e, t, n, r), s = e.primaryCube.sql(n), c = e.joinCubes.length > 0 ? xi(e) : new Map([[e.primaryCube.name, e.primaryCube]]);
7519
+ return Ai(e, t, n, c, s, o, Si(e, n, s, hi(e, t, n, c, r), o, r), r);
7516
7520
  }
7517
7521
  };
7518
7522
  //#endregion
7519
7523
  //#region src/server/executor.ts
7520
- function $(e, t) {
7524
+ function na(e, t) {
7521
7525
  if (!(typeof process > "u" || !process.env?.DC_DEBUG)) try {
7522
7526
  let { sql: n, params: r } = t.toSQL();
7523
7527
  console.log(`\n[DC_DEBUG] ${e}`), console.log(n), r.length > 0 && console.log("params:", r), console.log();
7524
7528
  } catch {}
7525
7529
  }
7526
- var Zi = class {
7530
+ var ra = class {
7527
7531
  dbExecutor;
7528
7532
  queryBuilder;
7529
7533
  drizzlePlanBuilder;
@@ -7542,7 +7546,7 @@ var Zi = class {
7542
7546
  if (this.dbExecutor = e, this.databaseAdapter = e.databaseAdapter, !this.databaseAdapter) throw Error(r("server.errors.dbAdapterRequired"));
7543
7547
  this.queryBuilder = new Fn(this.databaseAdapter);
7544
7548
  let a = new Xn(), o = new Qn(this.queryBuilder);
7545
- this.drizzlePlanBuilder = new Xi(this.queryBuilder, o, this.databaseAdapter), this.comparisonQueryBuilder = new Jr(this.databaseAdapter), this.funnelQueryBuilder = new Yr(this.databaseAdapter), this.flowQueryBuilder = new Xr(this.databaseAdapter), this.retentionQueryBuilder = new ni(this.databaseAdapter), this.logicalPlanBuilder = new ri(a), this.planOptimiser = i ?? new ii(), this.rlsSetup = n, this.modeRouter = new Rr({
7549
+ this.drizzlePlanBuilder = new ta(this.queryBuilder, o, this.databaseAdapter), this.comparisonQueryBuilder = new Jr(this.databaseAdapter), this.funnelQueryBuilder = new Yr(this.databaseAdapter), this.flowQueryBuilder = new Xr(this.databaseAdapter), this.retentionQueryBuilder = new ni(this.databaseAdapter), this.logicalPlanBuilder = new ci(a), this.planOptimiser = i ?? new li(), this.rlsSetup = n, this.modeRouter = new Rr({
7546
7550
  comparison: this.comparisonQueryBuilder,
7547
7551
  funnel: this.funnelQueryBuilder,
7548
7552
  flow: this.flowQueryBuilder,
@@ -7622,7 +7626,7 @@ var Zi = class {
7622
7626
  schema: this.dbExecutor.schema,
7623
7627
  securityContext: n
7624
7628
  }, a = this.funnelQueryBuilder.buildFunnelQuery(r, e, i);
7625
- $("funnel query", a);
7629
+ na("funnel query", a);
7626
7630
  let o = await a, s = this.funnelQueryBuilder.transformResult(o, r), c = {
7627
7631
  measures: {},
7628
7632
  dimensions: {},
@@ -7647,7 +7651,7 @@ var Zi = class {
7647
7651
  schema: this.dbExecutor.schema,
7648
7652
  securityContext: n
7649
7653
  }, a = this.flowQueryBuilder.buildFlowQuery(r, e, i);
7650
- $("flow query", a);
7654
+ na("flow query", a);
7651
7655
  let o = await a, s = this.flowQueryBuilder.transformResult(o), c = {
7652
7656
  measures: {},
7653
7657
  dimensions: {},
@@ -7670,7 +7674,7 @@ var Zi = class {
7670
7674
  schema: this.dbExecutor.schema,
7671
7675
  securityContext: n
7672
7676
  }, a = this.retentionQueryBuilder.buildRetentionQuery(r, e, i);
7673
- $("retention query", a);
7677
+ na("retention query", a);
7674
7678
  let o = await a, s = this.retentionQueryBuilder.transformResult(o, r), c = {
7675
7679
  measures: {},
7676
7680
  dimensions: {},
@@ -7694,7 +7698,7 @@ var Zi = class {
7694
7698
  let { optimisedPlan: o } = this.buildRegularQueryArtifacts(e, t, a), s = this.drizzlePlanBuilder.derivePhysicalPlanContext(o), c = this.drizzlePlanBuilder.toSemanticQuery(o);
7695
7699
  this.validateSecurityContext(s, a);
7696
7700
  let l = this.drizzlePlanBuilder.build(s, c, a);
7697
- $("query", l);
7701
+ na("query", l);
7698
7702
  let u = this.queryBuilder.collectNumericFields(e, t), d = {
7699
7703
  data: yr(await this.dbExecutor.execute(l, u), t, this.databaseAdapter),
7700
7704
  annotation: $n(s, t),
@@ -7827,7 +7831,7 @@ var Zi = class {
7827
7831
  let r = this.buildComparisonExecutionPlan(t).periodQueries[0];
7828
7832
  return this.generateUnifiedSQL(e, r, n);
7829
7833
  }
7830
- }, Qi = [
7834
+ }, ia = [
7831
7835
  "year",
7832
7836
  "quarter",
7833
7837
  "month",
@@ -7835,14 +7839,14 @@ var Zi = class {
7835
7839
  "day",
7836
7840
  "hour"
7837
7841
  ];
7838
- function $i(e, t) {
7842
+ function aa(e, t) {
7839
7843
  return t.includes(".") ? t : `${e}.${t}`;
7840
7844
  }
7841
- function ea(e) {
7845
+ function oa(e) {
7842
7846
  let t = Object.keys(e.measures), n = Array(t.length);
7843
7847
  for (let r = 0; r < t.length; r++) {
7844
7848
  let i = t[r], a = e.measures[i], o;
7845
- a.drillMembers && a.drillMembers.length > 0 && (o = a.drillMembers.map((t) => $i(e.name, t))), n[r] = {
7849
+ a.drillMembers && a.drillMembers.length > 0 && (o = a.drillMembers.map((t) => aa(e.name, t))), n[r] = {
7846
7850
  name: `${e.name}.${i}`,
7847
7851
  title: a.title || i,
7848
7852
  shortTitle: a.title || i,
@@ -7855,10 +7859,10 @@ function ea(e) {
7855
7859
  }
7856
7860
  return n;
7857
7861
  }
7858
- function ta(e) {
7862
+ function sa(e) {
7859
7863
  let t = Object.keys(e.dimensions), n = Array(t.length);
7860
7864
  for (let r = 0; r < t.length; r++) {
7861
- let i = t[r], a = e.dimensions[i], o = a.type === "time" ? a.granularities || Qi : void 0;
7865
+ let i = t[r], a = e.dimensions[i], o = a.type === "time" ? a.granularities || ia : void 0;
7862
7866
  n[r] = {
7863
7867
  name: `${e.name}.${i}`,
7864
7868
  title: a.title || i,
@@ -7872,7 +7876,7 @@ function ta(e) {
7872
7876
  }
7873
7877
  return n;
7874
7878
  }
7875
- function na(e, t, n) {
7879
+ function ca(e, t, n) {
7876
7880
  let r = [];
7877
7881
  if (!e.joins) return r;
7878
7882
  for (let [, i] of Object.entries(e.joins)) {
@@ -7888,20 +7892,20 @@ function na(e, t, n) {
7888
7892
  }
7889
7893
  return r;
7890
7894
  }
7891
- function ra(e) {
7895
+ function la(e) {
7892
7896
  let t = [];
7893
7897
  if (!e.hierarchies) return t;
7894
7898
  for (let [, n] of Object.entries(e.hierarchies)) t.push({
7895
7899
  name: n.name,
7896
7900
  title: n.title || n.name,
7897
7901
  cubeName: e.name,
7898
- levels: n.levels.map((t) => $i(e.name, t))
7902
+ levels: n.levels.map((t) => aa(e.name, t))
7899
7903
  });
7900
7904
  return t;
7901
7905
  }
7902
7906
  //#endregion
7903
7907
  //#region src/server/compiler.ts
7904
- var ia = class {
7908
+ var ua = class {
7905
7909
  cubes = /* @__PURE__ */ new Map();
7906
7910
  metadataCache;
7907
7911
  cacheConfig;
@@ -7930,7 +7934,7 @@ var ia = class {
7930
7934
  return Mt(this.db, this.schema, this.engineType);
7931
7935
  }
7932
7936
  createQueryExecutor(e = !1) {
7933
- return new Zi(this.createDbExecutor(), e ? this.cacheConfig : void 0, this.rlsSetup, this.planOptimiser);
7937
+ return new ra(this.createDbExecutor(), e ? this.cacheConfig : void 0, this.rlsSetup, this.planOptimiser);
7934
7938
  }
7935
7939
  formatSqlResult(e) {
7936
7940
  let t = this.getEngineType() ?? "postgres";
@@ -8025,7 +8029,7 @@ var ia = class {
8025
8029
  return "unknown_column";
8026
8030
  }
8027
8031
  generateCubeMetadata(e) {
8028
- let t = ea(e), n = ta(e), r = na(e, this.cubes, (e) => this.getColumnName(e)), i = ra(e);
8032
+ let t = oa(e), n = sa(e), r = ca(e, this.cubes, (e) => this.getColumnName(e)), i = la(e);
8029
8033
  return {
8030
8034
  name: e.name,
8031
8035
  title: e.title || e.name,
@@ -8092,4 +8096,4 @@ var ia = class {
8092
8096
  }
8093
8097
  };
8094
8098
  //#endregion
8095
- export { ia as t };
8099
+ export { ua as t };