@milaboratories/pl-model-common 1.41.2 → 1.42.0

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.
@@ -7,7 +7,7 @@ import type {
7
7
  SpecQueryJoinEntry,
8
8
  } from "./query_spec";
9
9
 
10
- const booleanTypesSet = new Set<SpecQueryBooleanExpression["type"]>([
10
+ const BOOLEAN_TYPES = new Set<SpecQueryBooleanExpression["type"]>([
11
11
  "numericComparison",
12
12
  "stringEquals",
13
13
  "stringContains",
@@ -18,10 +18,11 @@ const booleanTypesSet = new Set<SpecQueryBooleanExpression["type"]>([
18
18
  "and",
19
19
  "or",
20
20
  "isIn",
21
+ // "isInPolygon", -- disabled until the Rust executor wires it up
21
22
  ]);
22
23
 
23
24
  export function isBooleanExpression(expr: SpecQueryExpression): expr is SpecQueryBooleanExpression {
24
- return booleanTypesSet.has(
25
+ return BOOLEAN_TYPES.has(
25
26
  // @ts-expect-error -- TypeScript doesn't understand the discriminated union here, but we do at runtime
26
27
  expr.type,
27
28
  );
@@ -88,6 +89,7 @@ export function traverseQuerySpec<C1, C2>(
88
89
  case "filter":
89
90
  case "sort":
90
91
  case "sliceAxes":
92
+ case "transformColumns":
91
93
  result = { ...query, input: traverseQuerySpec(query.input, visitor) };
92
94
  break;
93
95
  default:
@@ -123,7 +125,14 @@ export function sortSpecQuery(query: SpecQuery): SpecQuery {
123
125
  node: (node) => {
124
126
  switch (node.type) {
125
127
  case "sparseToDenseColumn":
126
- return { ...node, axesIndices: node.axesIndices.toSorted((a, b) => a - b) };
128
+ return {
129
+ ...node,
130
+ // toSorted preserves array length but the type system widens
131
+ // the non-empty tuple back to a plain array, so re-narrow.
132
+ axes: node.axes.toSorted((a, b) =>
133
+ canonicalizeJson(a).localeCompare(canonicalizeJson(b)),
134
+ ) as typeof node.axes,
135
+ };
127
136
  case "innerJoin":
128
137
  case "fullJoin": {
129
138
  const sorted = [...node.entries].sort(cmpQueryJoinEntrySpec);
@@ -236,6 +245,15 @@ function cmpQuerySpec(lhs: SpecQuery, rhs: SpecQuery): number {
236
245
  return cmpQuerySpec(lhs.input, (rhs as typeof lhs).input);
237
246
  case "filter":
238
247
  return cmpQuerySpec(lhs.input, (rhs as typeof lhs).input);
248
+ case "transformColumns": {
249
+ const rhsTc = rhs as typeof lhs;
250
+ const cmp = cmpQuerySpec(lhs.input, rhsTc.input);
251
+ if (cmp !== 0) return cmp;
252
+ const modeCmp = lhs.mode.localeCompare(rhsTc.mode);
253
+ if (modeCmp !== 0) return modeCmp;
254
+ // Column entries are positional; compare by canonical JSON.
255
+ return canonicalizeJson(lhs.columns).localeCompare(canonicalizeJson(rhsTc.columns));
256
+ }
239
257
  default:
240
258
  assertNever(lhs);
241
259
  }