@platforma-sdk/model 1.42.10 → 1.42.16

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,6 +7,8 @@ import type {
7
7
  JsonDataInfoEntries,
8
8
  JsonPartitionedDataInfoEntries,
9
9
  BinaryPartitionedDataInfoEntries,
10
+ ParquetPartitionedDataInfoEntries,
11
+ PartitionedDataInfoEntries,
10
12
  } from '@milaboratories/pl-model-common';
11
13
  import type { AxisFilterByIdx } from '@milaboratories/pl-model-common';
12
14
 
@@ -18,6 +20,10 @@ import type { AxisFilterByIdx } from '@milaboratories/pl-model-common';
18
20
  * @param axisFilters - Array of axis filters (index, value pairs)
19
21
  * @throws Error if any filter axis is outside the partitioning axes or data axes for Json data
20
22
  */
23
+ export function filterDataInfoEntries<Blob>(
24
+ dataInfoEntries: ParquetPartitionedDataInfoEntries<Blob>,
25
+ axisFilters: AxisFilterByIdx[],
26
+ ): ParquetPartitionedDataInfoEntries<Blob>;
21
27
  export function filterDataInfoEntries<Blob>(
22
28
  dataInfoEntries: BinaryPartitionedDataInfoEntries<Blob>,
23
29
  axisFilters: AxisFilterByIdx[],
@@ -27,9 +33,9 @@ export function filterDataInfoEntries<Blob>(
27
33
  axisFilters: AxisFilterByIdx[],
28
34
  ): JsonPartitionedDataInfoEntries<Blob>;
29
35
  export function filterDataInfoEntries<Blob>(
30
- dataInfoEntries: BinaryPartitionedDataInfoEntries<Blob> | JsonPartitionedDataInfoEntries<Blob>,
36
+ dataInfoEntries: PartitionedDataInfoEntries<Blob>,
31
37
  axisFilters: AxisFilterByIdx[],
32
- ): BinaryPartitionedDataInfoEntries<Blob> | JsonPartitionedDataInfoEntries<Blob>;
38
+ ): PartitionedDataInfoEntries<Blob>;
33
39
  export function filterDataInfoEntries(
34
40
  dataInfoEntries: JsonDataInfoEntries,
35
41
  axisFilters: AxisFilterByIdx[],
@@ -42,16 +48,27 @@ export function filterDataInfoEntries<Blob>(
42
48
  const sortedFilters = [...axisFilters].sort((a, b) => b[0] - a[0]);
43
49
 
44
50
  // Check for invalid filter axes
45
- if (dataInfoEntries.type === 'JsonPartitioned' || dataInfoEntries.type === 'BinaryPartitioned') {
46
- const { partitionKeyLength } = dataInfoEntries;
47
- for (const [axisIdx] of axisFilters)
48
- if (axisIdx >= partitionKeyLength)
49
- throw new Error(`Can't filter on non-partitioned axis ${axisIdx}. Must be >= ${partitionKeyLength}`);
50
- } else if (dataInfoEntries.type === 'Json') {
51
- const { keyLength } = dataInfoEntries;
52
- for (const [axisIdx] of axisFilters)
53
- if (axisIdx >= keyLength)
54
- throw new Error(`Can't filter on non-data axis ${axisIdx}. Must be >= ${keyLength}`);
51
+ const { type } = dataInfoEntries;
52
+ switch (type) {
53
+ case 'Json': {
54
+ const { keyLength } = dataInfoEntries;
55
+ for (const [axisIdx] of axisFilters)
56
+ if (axisIdx >= keyLength)
57
+ throw new Error(`Can't filter on non-data axis ${axisIdx}. Must be >= ${keyLength}`);
58
+ break;
59
+ }
60
+ case 'JsonPartitioned':
61
+ case 'BinaryPartitioned':
62
+ case 'ParquetPartitioned': {
63
+ const { partitionKeyLength } = dataInfoEntries;
64
+ for (const [axisIdx] of axisFilters)
65
+ if (axisIdx >= partitionKeyLength)
66
+ throw new Error(`Can't filter on non-partitioned axis ${axisIdx}. Must be >= ${partitionKeyLength}`);
67
+ break;
68
+ }
69
+ default:
70
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
71
+ throw new Error(`Unsupported data info type: ${type satisfies never}`);
55
72
  }
56
73
 
57
74
  const keyMatchesFilters = (key: PColumnKey): boolean => {
@@ -72,49 +89,45 @@ export function filterDataInfoEntries<Blob>(
72
89
  };
73
90
 
74
91
  switch (dataInfoEntries.type) {
75
- case 'Json': {
76
- const filteredData: PColumnDataEntry<PColumnValue>[] = dataInfoEntries.data
77
- .filter((entry: PColumnDataEntry<PColumnValue>) => keyMatchesFilters(entry.key))
78
- .map((entry: PColumnDataEntry<PColumnValue>) => ({
92
+ case 'Json': return {
93
+ type: 'Json',
94
+ keyLength: dataInfoEntries.keyLength - axisFilters.length,
95
+ data: dataInfoEntries.data
96
+ .filter((entry) => keyMatchesFilters(entry.key))
97
+ .map((entry) => ({
79
98
  key: removeFilteredAxes(entry.key),
80
99
  value: entry.value,
81
- }));
82
-
83
- return {
84
- type: 'Json',
85
- keyLength: dataInfoEntries.keyLength - axisFilters.length,
86
- data: filteredData,
87
- };
88
- }
89
-
90
- case 'JsonPartitioned': {
91
- const filteredParts = dataInfoEntries.parts
92
- .filter((entry: PColumnDataEntry<Blob>) => keyMatchesFilters(entry.key))
93
- .map((entry: PColumnDataEntry<Blob>) => ({
100
+ } satisfies PColumnDataEntry<PColumnValue>)),
101
+ };
102
+ case 'JsonPartitioned': return {
103
+ type: 'JsonPartitioned',
104
+ partitionKeyLength: dataInfoEntries.partitionKeyLength - axisFilters.length,
105
+ parts: dataInfoEntries.parts
106
+ .filter((entry) => keyMatchesFilters(entry.key))
107
+ .map((entry) => ({
94
108
  key: removeFilteredAxes(entry.key),
95
109
  value: entry.value,
96
- }));
97
-
98
- return {
99
- type: 'JsonPartitioned',
100
- partitionKeyLength: dataInfoEntries.partitionKeyLength - axisFilters.length,
101
- parts: filteredParts,
102
- };
103
- }
104
-
105
- case 'BinaryPartitioned': {
106
- const filteredParts = dataInfoEntries.parts
107
- .filter((entry: PColumnDataEntry<BinaryChunk<Blob>>) => keyMatchesFilters(entry.key))
108
- .map((entry: PColumnDataEntry<BinaryChunk<Blob>>) => ({
110
+ } satisfies PColumnDataEntry<Blob>)),
111
+ };
112
+ case 'BinaryPartitioned': return {
113
+ type: 'BinaryPartitioned',
114
+ partitionKeyLength: dataInfoEntries.partitionKeyLength - axisFilters.length,
115
+ parts: dataInfoEntries.parts
116
+ .filter((entry) => keyMatchesFilters(entry.key))
117
+ .map((entry) => ({
109
118
  key: removeFilteredAxes(entry.key),
110
119
  value: entry.value,
111
- }));
112
-
113
- return {
114
- type: 'BinaryPartitioned',
115
- partitionKeyLength: dataInfoEntries.partitionKeyLength - axisFilters.length,
116
- parts: filteredParts,
117
- };
118
- }
120
+ } satisfies PColumnDataEntry<BinaryChunk<Blob>>)),
121
+ };
122
+ case 'ParquetPartitioned': return {
123
+ type: 'ParquetPartitioned',
124
+ partitionKeyLength: dataInfoEntries.partitionKeyLength - axisFilters.length,
125
+ parts: dataInfoEntries.parts
126
+ .filter((entry) => keyMatchesFilters(entry.key))
127
+ .map((entry) => ({
128
+ key: removeFilteredAxes(entry.key),
129
+ value: entry.value,
130
+ } satisfies PColumnDataEntry<Blob>)),
131
+ };
119
132
  }
120
133
  }
@@ -23,6 +23,7 @@ import {
23
23
  isPartitionedDataInfoEntries,
24
24
  entriesToDataInfo,
25
25
  deriveNativeId,
26
+ Annotation,
26
27
  } from '@milaboratories/pl-model-common';
27
28
  import type { TreeNodeAccessor } from '../accessor';
28
29
  import type { LabelDerivationOps, TraceEntry } from './label';
@@ -407,8 +408,8 @@ export class PColumnCollection {
407
408
  ...finalSpec,
408
409
  annotations: {
409
410
  ...(finalSpec.annotations ?? {}),
410
- 'pl7.app/label': label,
411
- },
411
+ [Annotation.Label]: label,
412
+ } satisfies Annotation,
412
413
  };
413
414
  }
414
415
 
@@ -1,6 +1,6 @@
1
1
  import { test, expect } from '@jest/globals';
2
- import { deriveLabels, PAnnotationLabel, PAnnotationTrace, Trace } from './label';
3
- import { PColumnSpec } from '@milaboratories/pl-model-common';
2
+ import { deriveLabels, Trace } from './label';
3
+ import { Annotation, PColumnSpec } from '@milaboratories/pl-model-common';
4
4
 
5
5
  function tracesToSpecs(traces: Trace[]) {
6
6
  return traces.map(
@@ -10,8 +10,8 @@ function tracesToSpecs(traces: Trace[]) {
10
10
  name: 'name',
11
11
  valueType: 'Int',
12
12
  annotations: {
13
- [PAnnotationTrace]: JSON.stringify(t),
14
- [PAnnotationLabel]: 'Label'
13
+ [Annotation.Trace]: JSON.stringify(t),
14
+ [Annotation.Label]: 'Label'
15
15
  },
16
16
  axesSpec: []
17
17
  }) satisfies PColumnSpec
@@ -1,9 +1,6 @@
1
- import type { PObjectSpec } from '@milaboratories/pl-model-common';
1
+ import { Annotation, parseJson, readAnnotation, type PObjectSpec } from '@milaboratories/pl-model-common';
2
2
  import { z } from 'zod';
3
3
 
4
- export const PAnnotationLabel = 'pl7.app/label';
5
- export const PAnnotationTrace = 'pl7.app/trace';
6
-
7
4
  export type RecordsWithLabel<T> = {
8
5
  value: T;
9
6
  label: string;
@@ -76,9 +73,9 @@ export function deriveLabels<T>(
76
73
  spec = extractorResult as PObjectSpec;
77
74
  }
78
75
 
79
- const label = spec.annotations?.[PAnnotationLabel];
80
- const traceStr = spec.annotations?.[PAnnotationTrace];
81
- const baseTrace = (traceStr ? Trace.safeParse(JSON.parse(traceStr)).data : undefined) ?? [];
76
+ const label = readAnnotation(spec, Annotation.Label);
77
+ const traceStr = readAnnotation(spec, Annotation.Trace);
78
+ const baseTrace = (traceStr ? Trace.safeParse(parseJson(traceStr)).data : undefined) ?? [];
82
79
 
83
80
  const trace = [
84
81
  ...(prefixTrace ?? []),