@platforma-open/milaboratories.software-ptabler.schema 1.3.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.
@@ -0,0 +1,416 @@
1
+ import type { DataType } from './common';
2
+
3
+ export type Expression =
4
+ | ComparisonExpression
5
+ | BinaryArithmeticExpression
6
+ | UnaryArithmeticExpression
7
+ | CastExpression
8
+ | BooleanLogicExpression
9
+ | NotExpression
10
+ | NullCheckExpression
11
+ | StringJoinExpression
12
+ | HashExpression
13
+ | ColumnReferenceExpression
14
+ | ConstantValueExpression
15
+ | RankExpression
16
+ | CumsumExpression
17
+ | ExtendedUnaryStringExpression
18
+ | StringDistanceExpression
19
+ | FuzzyStringFilterExpression
20
+ | WhenThenOtherwiseExpression
21
+ | SubstringExpression
22
+ | StringReplaceExpression
23
+ | MinMaxExpression
24
+ | FillNaExpression
25
+ | WindowExpression;
26
+
27
+ /** Represents all possible expression types in the system. */
28
+ export type ComparisonOperator = 'gt' | 'ge' | 'eq' | 'lt' | 'le' | 'neq';
29
+
30
+ /** Defines a comparison operation between two expressions. */
31
+ export interface ComparisonExpression {
32
+ /** The type of comparison (e.g., 'gt', 'eq'). */
33
+ type: ComparisonOperator;
34
+ /** The left-hand side expression. */
35
+ lhs: Expression;
36
+ /** The right-hand side expression. */
37
+ rhs: Expression;
38
+ }
39
+
40
+ /** Defines the supported binary arithmetic operators. */
41
+ export type BinaryArithmeticOperator =
42
+ | 'plus'
43
+ | 'minus'
44
+ | 'multiply'
45
+ | 'truediv'
46
+ | 'floordiv';
47
+
48
+ /** Represents a binary arithmetic operation between two expressions. */
49
+ export interface BinaryArithmeticExpression {
50
+ /** The type of arithmetic operation (e.g., 'plus', 'minus'). */
51
+ type: BinaryArithmeticOperator;
52
+ /** The left-hand side expression. */
53
+ lhs: Expression;
54
+ /** The right-hand side expression. */
55
+ rhs: Expression;
56
+ }
57
+
58
+ /** Defines the supported unary arithmetic operators. */
59
+ export type UnaryArithmeticOperator =
60
+ | 'log10'
61
+ | 'log'
62
+ | 'log2'
63
+ | 'abs'
64
+ | 'sqrt'
65
+ | 'negate'
66
+ | 'floor'
67
+ | 'round'
68
+ | 'ceil';
69
+
70
+ /** Represents a unary arithmetic operation on a single expression. */
71
+ export interface UnaryArithmeticExpression {
72
+ /** The type of unary operation (e.g., 'log10', 'abs'). */
73
+ type: UnaryArithmeticOperator;
74
+ /** The expression to operate on. */
75
+ value: Expression;
76
+ }
77
+
78
+ /**
79
+ * Represents a type casting operation that converts the result of an expression to a specified data type.
80
+ */
81
+ export interface CastExpression {
82
+ /** The type of operation, always 'cast'. */
83
+ type: 'cast';
84
+ /** The expression whose result will be cast to the target data type. */
85
+ value: Expression;
86
+ /** The target data type to cast the expression result to. */
87
+ dtype: DataType;
88
+ /**
89
+ * Whether to use strict casting mode. If true, conversion errors and overflows will throw exceptions.
90
+ * If false or undefined, uses non-strict mode where failures result in null values. Defaults to false.
91
+ */
92
+ strict?: boolean;
93
+ }
94
+
95
+ /** Defines the supported boolean list operators. */
96
+ export type BooleanListOperator = 'and' | 'or';
97
+
98
+ /** Represents a boolean logic operation (AND, OR) on a list of expressions. */
99
+ export interface BooleanLogicExpression {
100
+ /** The type of boolean operation ('and', 'or'). */
101
+ type: BooleanListOperator;
102
+ /** An array of boolean expressions as operands. */
103
+ operands: Expression[]; // Array of boolean expressions
104
+ }
105
+
106
+ /** Represents a logical NOT operation on a single boolean expression. */
107
+ export interface NotExpression {
108
+ /** The type of operation, always 'not'. */
109
+ type: 'not';
110
+ /** The boolean expression to negate. */
111
+ value: Expression;
112
+ }
113
+
114
+ /** Defines the supported null check operators. */
115
+ export type NullCheckOperator = 'is_na' | 'is_not_na';
116
+
117
+ /** Represents a null check operation (is NA, is not NA) on an expression. */
118
+ export interface NullCheckExpression {
119
+ /** The type of null check ('is_na', 'is_not_na'). */
120
+ type: NullCheckOperator;
121
+ /** The expression to check for nullity. */
122
+ value: Expression;
123
+ }
124
+
125
+ /** Represents a string join operation on an array of expressions. */
126
+ export interface StringJoinExpression {
127
+ /** The type of operation, always 'str_join'. */
128
+ type: 'str_join';
129
+ /** An array of expressions whose string representations will be joined. */
130
+ operands: Expression[];
131
+ /** An optional delimiter string to insert between joined elements. */
132
+ delimiter?: string;
133
+ }
134
+
135
+ /** Defines the supported hash types. Includes common cryptographic and non-cryptographic algorithms. */
136
+ export type HashType =
137
+ | 'sha256' // Cryptographic
138
+ | 'sha512' // Cryptographic
139
+ | 'md5' // Cryptographic (use with caution due to vulnerabilities)
140
+ | 'blake3' // Cryptographic
141
+ | 'wyhash' // Non-cryptographic
142
+ | 'xxh3'; // Non-cryptographic
143
+
144
+ /**
145
+ * Defines the encoding for the hash output.
146
+ * - 'hex': Standard hexadecimal encoding.
147
+ * - 'base64': Standard base64 encoding.
148
+ * - 'base64_alphanumeric': Base64 encoding with non-alphanumeric characters (e.g., '+', '/') removed.
149
+ * - 'base64_alphanumeric_upper': Base64 encoding with non-alphanumeric characters removed and the result converted to uppercase.
150
+ */
151
+ export type HashEncoding =
152
+ | 'hex'
153
+ | 'base64'
154
+ | 'base64_alphanumeric'
155
+ | 'base64_alphanumeric_upper';
156
+
157
+ /** Represents a hashing operation on an expression. */
158
+ export interface HashExpression {
159
+ /** The specific type of hash algorithm to apply. */
160
+ type: 'hash';
161
+ /** The type of hash algorithm to apply. */
162
+ hashType: HashType;
163
+ /** The encoding for the output hash string. */
164
+ encoding: HashEncoding;
165
+ /** The expression whose value will be hashed. */
166
+ value: Expression;
167
+ /** Optional. Minimal number of entropy bits required. Affects encoding, truncating the result to the shortest string with the requested entropy. No error if bits exceed what the hash offers. */
168
+ bits?: number;
169
+ }
170
+
171
+ /** Represents a reference to a column by its name. */
172
+ export interface ColumnReferenceExpression {
173
+ /** The type of operation, always 'col'. */
174
+ type: 'col';
175
+ /** The name of the column to reference. */
176
+ name: string;
177
+ }
178
+
179
+ /** Represents a constant literal value (string, number, boolean, or null). */
180
+ export interface ConstantValueExpression {
181
+ /** The type of operation, always 'const'. */
182
+ type: 'const';
183
+ /** The constant value. */
184
+ value: string | number | boolean | null;
185
+ }
186
+
187
+ /**
188
+ * Represents a rank function applied over a dataset partition.
189
+ * Calculates the rank of each row within its partition based on the specified ordering.
190
+ */
191
+ export interface RankExpression {
192
+ /** The type of operation, always 'rank'. */
193
+ type: 'rank';
194
+ /** List of expressions to partition the data by before ranking. The output of these expressions will be used for partitioning. */
195
+ partitionBy: Expression[];
196
+ /** Defines the ordering expressions within partitions to determine the rank. */
197
+ orderBy: Expression[];
198
+ /** Whether to sort in descending order. Defaults to false (ascending). */
199
+ descending?: boolean;
200
+ }
201
+
202
+ /**
203
+ * Represents a cumulative sum function applied over a dataset partition.
204
+ * Calculates the cumulative sum of the 'value' expression within each partition,
205
+ * based on the specified ordering. Values are sorted by value and then by
206
+ * additional_order_by before summing.
207
+ */
208
+ export interface CumsumExpression {
209
+ /** The type of operation, always 'cumsum'. */
210
+ type: 'cumsum';
211
+ /** The expression whose values will be cumulatively summed. */
212
+ value: Expression;
213
+ /** Defines additional ordering within partitions for the cumulative sum calculation, in addition to the ordering of the values themselves. */
214
+ additionalOrderBy: Expression[];
215
+ /** List of expressions to partition the data by before calculating the cumulative sum. The output of these expressions will be used for partitioning. */
216
+ partitionBy: Expression[];
217
+ /** Whether to sort in descending order. Defaults to false (ascending). */
218
+ descending?: boolean;
219
+ }
220
+
221
+ /** Defines the supported unary string operators. */
222
+ export type UnaryStringOperator = 'to_upper' | 'to_lower';
223
+
224
+ /** Represents a unary string operation on a single expression. */
225
+ export interface ExtendedUnaryStringExpression {
226
+ /** The type of unary string operation (e.g., 'to_upper', 'to_lower', 'str_len'). */
227
+ type: UnaryStringOperator | 'str_len';
228
+ /** The string expression to operate on. */
229
+ value: Expression;
230
+ }
231
+
232
+ /** Defines the supported string distance metrics. */
233
+ export type StringDistanceMetric =
234
+ | 'levenshtein'
235
+ | 'optimal_string_alignment'
236
+ | 'jaro_winkler';
237
+
238
+ /**
239
+ * Represents a string distance/similarity calculation between two expressions.
240
+ * Computes metrics like Levenshtein, Optimal String Alignment, or Jaro-Winkler.
241
+ */
242
+ export interface StringDistanceExpression {
243
+ /** The type of operation, always 'string_distance'. */
244
+ type: 'string_distance';
245
+ /** The specific distance metric to use. */
246
+ metric: StringDistanceMetric;
247
+ /** The first string expression. */
248
+ string1: Expression;
249
+ /** The second string expression to compare against. */
250
+ string2: Expression;
251
+ /**
252
+ * If true, the expression returns a similarity score (typically normalized between 0 and 1).
253
+ * If false or undefined, it returns the raw edit distance (e.g., Levenshtein, OSA).
254
+ * Jaro-Winkler inherently returns a similarity score; this flag might be ignored or influence its normalization if applicable.
255
+ */
256
+ returnSimilarity?: boolean;
257
+ }
258
+
259
+ /** Defines the supported fuzzy string filter distance metrics. */
260
+ export type FuzzyFilterDistanceMetric = 'levenshtein' | 'hamming';
261
+
262
+ /**
263
+ * Represents a fuzzy string filter operation on an expression.
264
+ * This operation compares the string value of an expression (`value`)
265
+ * against another string or string expression (`pattern`) using a specified
266
+ * distance metric (`levenshtein` or `hamming`), returning true if the distance is
267
+ * within the specified `bound`.
268
+ */
269
+ export interface FuzzyStringFilterExpression {
270
+ /** The type of operation, always 'fuzzy_string_filter'. */
271
+ type: 'fuzzy_string_filter';
272
+ /** The distance metric to use for the fuzzy comparison. */
273
+ metric: FuzzyFilterDistanceMetric;
274
+ /** The expression whose string value will be compared. */
275
+ value: Expression;
276
+ /** The expression representing the string pattern to compare against. */
277
+ pattern: Expression;
278
+ /** The maximum allowed distance for a match (inclusive). */
279
+ bound: number;
280
+ }
281
+
282
+ /**
283
+ * Represents a single "when" condition and its corresponding "then" result expression.
284
+ * Used within the WhenThenOtherwiseExpression.
285
+ */
286
+ export interface WhenThenClause {
287
+ /** The condition expression. Should evaluate to a boolean. */
288
+ when: Expression;
289
+ /** The result expression if the 'when' condition is true. */
290
+ then: Expression;
291
+ }
292
+
293
+ /**
294
+ * Represents a conditional expression that evaluates a series of "when"
295
+ * conditions and returns the corresponding "then" expression's value.
296
+ * If no "when" condition is met, it returns the value of the "otherwise" expression.
297
+ * This mimics Polars' when/then/otherwise functionality.
298
+ */
299
+ export interface WhenThenOtherwiseExpression {
300
+ /** The type of operation, always 'when_then_otherwise'. */
301
+ type: 'when_then_otherwise';
302
+ /** An array of "when/then" clauses to be evaluated in order. */
303
+ conditions: WhenThenClause[];
304
+ /** The expression whose value is returned if none of the "when" conditions are met. */
305
+ otherwise: Expression;
306
+ }
307
+
308
+ /**
309
+ * Represents a substring extraction operation on an expression.
310
+ * Extracts a portion of the string value resulting from the 'value' expression.
311
+ * The substring starts at the 'start' index (0-based).
312
+ * - If 'length' is provided, it specifies the maximum length of the substring.
313
+ * - If 'end' is provided, it specifies the index *before* which the substring ends.
314
+ * - If neither 'length' nor 'end' is provided, the substring extends to the end of the string.
315
+ * - 'length' and 'end' are mutually exclusive.
316
+ * If the requested substring range extends beyond the actual string length,
317
+ * the extraction automatically stops at the end of the string.
318
+ */
319
+ export interface SubstringExpression {
320
+ /** The type of operation, always 'substring'. */
321
+ type: 'substring';
322
+ /** The expression whose string value will be used. */
323
+ value: Expression;
324
+ /** The starting position (0-indexed). */
325
+ start: number;
326
+ /** The length of the substring. Mutually exclusive with 'end'. */
327
+ length?: number;
328
+ /** The end position of the substring (exclusive). Mutually exclusive with 'length'. */
329
+ end?: number;
330
+ }
331
+
332
+ /**
333
+ * Represents a string replacement operation.
334
+ * Replaces occurrences of a pattern (regex or literal) in a string expression with a replacement string.
335
+ * The behavior is aligned with Polars' `replace` and `replace_all` functions.
336
+ *
337
+ * - If `literal` is true, the `pattern` is treated as a literal string. Otherwise, it's treated as a regular expression.
338
+ * - If `replaceAll` is true, all occurrences of the pattern are replaced. Otherwise, only the first occurrence is replaced.
339
+ *
340
+ * When using regular expressions (i.e., `literal` is false or undefined):
341
+ * - Positional capture groups can be referenced in the `replacement` string using `$n` or `${n}` (e.g., `$1` for the first group).
342
+ * - Named capture groups can be referenced using `${name}`.
343
+ * - To include a literal dollar sign (`$`) in the replacement, it must be escaped as `$$`.
344
+ */
345
+ export interface StringReplaceExpression {
346
+ /** The type of operation, always 'str_replace'. */
347
+ type: 'str_replace';
348
+ /** The input string expression to operate on. */
349
+ value: Expression;
350
+ /** The pattern (regex or literal string) to search for. Can be a string literal or an expression evaluating to a string. */
351
+ pattern: Expression | string;
352
+ /** The replacement string. Can be a string literal or an expression evaluating to a string. Can use $n or ${name} for captured groups if pattern is a regex. */
353
+ replacement: Expression | string;
354
+ /** If true, replace all occurrences of the pattern. If false or undefined, replace only the first. Defaults to false. */
355
+ replaceAll?: boolean;
356
+ /** If true, treat the pattern as a literal string. If false or undefined, treat it as a regex. Defaults to false. */
357
+ literal?: boolean;
358
+ }
359
+
360
+ /** Defines the supported min/max operators. */
361
+ export type MinMaxOperator = 'min' | 'max';
362
+
363
+ /** Represents a min or max operation on a list of expressions. */
364
+ export interface MinMaxExpression {
365
+ /** The type of operation ('min' or 'max'). */
366
+ type: MinMaxOperator;
367
+ /** An array of expressions to find the minimum or maximum value from. */
368
+ operands: Expression[];
369
+ }
370
+
371
+ /**
372
+ * Represents a fill NA (null) operation.
373
+ * If the 'input' expression evaluates to null, the 'fillValue' expression is used.
374
+ * Otherwise, the 'input' expression's value is used.
375
+ * This is a convenience shortcut for a common pattern often implemented with
376
+ * conditional expressions (e.g., when(is_na(input), fillValue).otherwise(input)).
377
+ */
378
+ export interface FillNaExpression {
379
+ /** The type of operation, always 'fill_na'. */
380
+ type: 'fill_na';
381
+ /** The primary expression to evaluate. */
382
+ input: Expression;
383
+ /** The expression whose value is used if 'input' is null. */
384
+ fillValue: Expression;
385
+ }
386
+
387
+ /**
388
+ * Defines standard aggregation functions that can be used in window expressions.
389
+ */
390
+ export type AggregationType =
391
+ | 'sum'
392
+ | 'mean'
393
+ | 'median'
394
+ | 'min'
395
+ | 'max'
396
+ | 'std'
397
+ | 'var'
398
+ | 'count'
399
+ | 'first'
400
+ | 'last'
401
+ | 'n_unique';
402
+
403
+ /**
404
+ * Represents a window function call.
405
+ * This allows applying an aggregation function over a specific partition of the data.
406
+ */
407
+ export interface WindowExpression {
408
+ /** The type of operation, always 'aggregate'. Note: This might be confusing, consider 'window_aggregate' or similar if 'aggregate' is heavily used elsewhere for a different step type. */
409
+ type: 'aggregate';
410
+ /** The aggregation function to apply (e.g., 'sum', 'mean'). */
411
+ aggregation: AggregationType;
412
+ /** The expression to apply the aggregation function to. */
413
+ value: Expression;
414
+ /** List of expressions to partition the data by. The aggregation is performed independently within each partition. */
415
+ partitionBy: Expression[];
416
+ }
package/src/index.ts ADDED
@@ -0,0 +1,20 @@
1
+ import type { ReadCsvStep, WriteCsvStep } from './io';
2
+ import type { AddColumnsStep, FilterStep } from './basic_steps';
3
+ import type { AggregateStep } from './aggregate';
4
+ import type { AnyJoinStep } from './join';
5
+ import type { ConcatenateStep } from './concatenate';
6
+ import type { SortStep } from './sort';
7
+
8
+ export type PTablerStep =
9
+ | ReadCsvStep
10
+ | WriteCsvStep
11
+ | AddColumnsStep
12
+ | FilterStep
13
+ | AggregateStep
14
+ | AnyJoinStep
15
+ | ConcatenateStep
16
+ | SortStep;
17
+
18
+ export type PTablerWorkflow = {
19
+ workflow: PTablerStep[];
20
+ };
package/src/io.ts ADDED
@@ -0,0 +1,72 @@
1
+ import type { DataType } from './common';
2
+
3
+ /**
4
+ * Represents the schema definition for a single column.
5
+ */
6
+ export interface ColumnSchema {
7
+ /** The name of the column. */
8
+ column: string;
9
+ /** Optional: The expected Polars data type for this column. */
10
+ type?: DataType;
11
+ /** Optional: A specific string to be interpreted as a null value for this column. */
12
+ nullValue?: string;
13
+ }
14
+
15
+ /** Represents the configuration for a step that reads data from a CSV file into the tablespace. */
16
+ export interface ReadCsvStep {
17
+ /** The type of the step, which is always 'read_csv' for this operation. */
18
+ type: 'read_csv';
19
+ /** Path to the CSV file to be read. */
20
+ file: string;
21
+ /** The name assigned to the loaded DataFrame in the tablespace. */
22
+ name: string;
23
+ /** Optional: The delimiter character used in the CSV file. */
24
+ delimiter?: string;
25
+ /**
26
+ * Optional: Provides schema information for specific columns.
27
+ * If `infer_schema` is `true` (default), these definitions act as overrides
28
+ * to the types inferred by Polars. Each `ColumnSchema` can specify a `type`
29
+ * and/or a `nullValue`. If `infer_schema` is `false`, these definitions are
30
+ * used directly; for columns not listed, Polars' default behavior when no
31
+ * type is specified (e.g., reading as string) will apply.
32
+ */
33
+ schema?: ColumnSchema[];
34
+ /**
35
+ * Optional: Whether to infer the schema from the CSV file using Polars'
36
+ * default inference mechanism (e.g., reading a certain number of rows).
37
+ * Defaults to `true`. If set to `false`, type inference is disabled,
38
+ * and types will rely on the `schema` field or Polars' defaults for
39
+ * columns not specified in `schema`.
40
+ */
41
+ infer_schema?: boolean;
42
+ }
43
+
44
+ /**
45
+ * Represents the configuration for a step that writes a table from the tablespace to a CSV file.
46
+ */
47
+ export interface WriteCsvStep {
48
+ /** The type of the step, which is always 'write_csv' for this operation. */
49
+ type: 'write_csv';
50
+ /** The name of the table in the tablespace to be written. */
51
+ table: string;
52
+ /** Path to the output CSV file. */
53
+ file: string;
54
+ /** Optional: A list of column names to write to the CSV. If omitted, all columns are written. */
55
+ columns?: string[];
56
+ /** Optional: The delimiter character to use in the output CSV file. */
57
+ delimiter?: string;
58
+ }
59
+
60
+ /**
61
+ * Represents the configuration for a step that writes a table from the tablespace to a JSON file.
62
+ */
63
+ export interface WriteJsonStep {
64
+ /** The type of the step, which is always 'write_json' for this operation. */
65
+ type: 'write_json';
66
+ /** The name of the table in the tablespace to be written. */
67
+ table: string;
68
+ /** Path to the output JSON file. */
69
+ file: string;
70
+ /** Optional: A list of column names to write to the JSON. If omitted, all columns are written. */
71
+ columns?: string[];
72
+ }
package/src/join.ts ADDED
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Defines the structure for mapping a column, with an optional rename.
3
+ */
4
+ export interface ColumnMapping {
5
+ /** The original name of the column. */
6
+ column: string;
7
+ /** The new name for the column. If absent, the original name is used. */
8
+ rename?: string;
9
+ }
10
+
11
+ /**
12
+ * Defines the type for join operations (excluding cross join) in a workflow.
13
+ * This step joins two tables from the tablespace based on specified columns and join strategy.
14
+ */
15
+ export interface JoinStep {
16
+ /** The type of the step, which is always "join" for this operation. */
17
+ type: 'join';
18
+
19
+ /** The name of the left table in the tablespace to be joined. */
20
+ leftTable: string;
21
+
22
+ /** The name of the right table in the tablespace to be joined. */
23
+ rightTable: string;
24
+
25
+ /** The name to be assigned to the resulting joined table in the tablespace. */
26
+ outputTable: string;
27
+
28
+ /** A list of column names from the left table to be used for the equi-join, original not mapped names. */
29
+ leftOn: string[];
30
+
31
+ /** A list of column names from the right table to be used for the equi-join, original not mapped names. */
32
+ rightOn: string[];
33
+
34
+ /** The type of join to perform. */
35
+ how: JoinStrategy;
36
+
37
+ /**
38
+ * Determines how to handle key columns with the same name from both the left and right tables after the join.
39
+ * When set to \`true\` (the default), Polars will attempt to merge these identically named key columns into a single column in the output table.
40
+ * For 'inner', 'left', and 'right' joins, this is the standard behavior.
41
+ * For 'full' joins, setting this to \`true\` ensures the key columns are coalesced.
42
+ * When set to \`false\`, identically named key columns from the left and right tables will be kept separate in the output,
43
+ * with the column from the right table typically being renamed (e.g., by adding a suffix like '_right').
44
+ * This parameter mirrors the behavior of Polars' join coalescing logic.
45
+ * It does not apply to 'cross' joins, as they do not involve key columns in the same way.
46
+ */
47
+ coalesce?: boolean;
48
+
49
+ /**
50
+ * An optional list to select and rename columns from the left table.
51
+ * If provided, only these columns (plus any from `leftOn` not explicitly listed) will be included.
52
+ * Use the `rename` property within a mapping to change a column's name.
53
+ */
54
+ leftColumns?: ColumnMapping[];
55
+
56
+ /**
57
+ * An optional list to select and rename columns from the right table.
58
+ * If provided, only these columns (plus any from `rightOn` not explicitly listed) will be included.
59
+ * Use the `rename` property within a mapping to change a column's name.
60
+ */
61
+ rightColumns?: ColumnMapping[];
62
+ }
63
+
64
+ /**
65
+ * Defines the type for a cross join operation in a workflow.
66
+ * This step computes the Cartesian product of two tables.
67
+ */
68
+ export interface CrossJoinStep {
69
+ /** The type of the step, which is always "join" for this operation. */
70
+ type: 'join'; // Or should this be 'cross_join'? For now, keeping it 'join' as per user doc for steps having a 'type'.
71
+
72
+ /** The name of the left table in the tablespace to be joined. */
73
+ leftTable: string;
74
+
75
+ /** The name of the right table in the tablespace to be joined. */
76
+ rightTable: string;
77
+
78
+ /** The name to be assigned to the resulting joined table in the tablespace. */
79
+ outputTable: string;
80
+
81
+ /** The type of join to perform, which is always "cross" for this operation. */
82
+ how: 'cross';
83
+
84
+ /**
85
+ * An optional list to select and rename columns from the left table.
86
+ * If provided, only these columns will be included.
87
+ * Use the `rename` property within a mapping to change a column's name.
88
+ */
89
+ leftColumns?: ColumnMapping[];
90
+
91
+ /**
92
+ * An optional list to select and rename columns from the right table.
93
+ * If provided, only these columns will be included.
94
+ * Use the `rename` property within a mapping to change a column's name.
95
+ */
96
+ rightColumns?: ColumnMapping[];
97
+ }
98
+
99
+ /** Defines the possible join strategies for a standard join operation (excluding cross join). */
100
+ export type JoinStrategy = 'inner' | 'left' | 'right' | 'full';
101
+
102
+ /** Defines any possible join step. */
103
+ export type AnyJoinStep = JoinStep | CrossJoinStep;
package/src/sort.ts ADDED
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Defines a single sort instruction, specifying the column, sort order,
3
+ * and null handling strategy.
4
+ */
5
+ export interface SortDirective {
6
+ /** The name of the column to sort by. */
7
+ column: string;
8
+
9
+ /**
10
+ * Whether to sort in descending order for this column.
11
+ * Defaults to false (ascending).
12
+ */
13
+ descending?: boolean;
14
+
15
+ /**
16
+ * Determines how null values are handled in the sort for this column.
17
+ * If true, nulls are placed last.
18
+ * If false, nulls are placed first.
19
+ * If undefined, the default Polars behavior is used (nulls are considered smallest,
20
+ * so they appear first in ascending sorts and last in descending sorts, unless platform defaults differ).
21
+ * This maps to Polars' `nulls_last` parameter.
22
+ */
23
+ nullsLast?: boolean;
24
+ }
25
+
26
+ /**
27
+ * Defines a step that sorts a table based on one or more column directives.
28
+ * The operation reads from an input table and writes the sorted result to an output table.
29
+ */
30
+ export interface SortStep {
31
+ /** The type identifier for this step. Must be 'sort'. */
32
+ type: 'sort';
33
+
34
+ /** The name of the input table from the tablespace to be sorted. */
35
+ inputTable: string;
36
+
37
+ /** The name to be assigned to the newly created sorted table in the tablespace. */
38
+ outputTable: string;
39
+
40
+ /**
41
+ * An array of sort directives defining the columns and their respective sort orders.
42
+ * The table is sorted by the first directive in the array, then by the second
43
+ * for any ties, and so on.
44
+ */
45
+ by: SortDirective[];
46
+
47
+ /**
48
+ * Optional. If true, maintains the stability of the sort. This means that if
49
+ * two rows are equivalent according to the sorting criteria, their relative order
50
+ * from the input table is preserved in the output.
51
+ * Corresponds to `maintain_order=True` in Polars `DataFrame.sort()`.
52
+ * Defaults to false.
53
+ */
54
+ stable?: boolean;
55
+ }