tranfi 0.0.2 → 0.2.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.
- package/LICENSE +177 -21
- package/NOTICE +8 -0
- package/README.md +627 -0
- package/app/assets/index-6quYZ5Ap.css +5 -0
- package/app/assets/index-BIAIKnrp.js +160 -0
- package/app/assets/materialdesignicons-webfont-B7mPwVP_.ttf +0 -0
- package/app/assets/materialdesignicons-webfont-CSr8KVlo.eot +0 -0
- package/app/assets/materialdesignicons-webfont-Dp5v-WZN.woff2 +0 -0
- package/app/assets/materialdesignicons-webfont-PXm3-2wK.woff +0 -0
- package/app/index.html +13 -0
- package/binding.gyp +121 -0
- package/csrc/arena.c +93 -0
- package/csrc/batch.c +976 -0
- package/csrc/buffer.c +154 -0
- package/csrc/cJSON.c +3386 -0
- package/csrc/cJSON.h +316 -0
- package/csrc/codec_csv.c +1951 -0
- package/csrc/codec_jsonl.c +1086 -0
- package/csrc/codec_table.c +248 -0
- package/csrc/codec_text.c +447 -0
- package/csrc/compiler.c +130 -0
- package/csrc/config.h +21 -0
- package/csrc/date_utils.h +94 -0
- package/csrc/dsl.c +5417 -0
- package/csrc/dsl.h +22 -0
- package/csrc/expr.c +1553 -0
- package/csrc/expr.h +58 -0
- package/csrc/internal.h +539 -0
- package/csrc/ir.c +166 -0
- package/csrc/ir.h +208 -0
- package/csrc/ir_schema.c +75 -0
- package/csrc/ir_serialize.c +166 -0
- package/csrc/ir_sql.c +1822 -0
- package/csrc/ir_validate.c +576 -0
- package/csrc/json_path.c +210 -0
- package/csrc/main.c +1241 -0
- package/csrc/memory_estimate.c +477 -0
- package/csrc/op_acf.c +283 -0
- package/csrc/op_across.c +477 -0
- package/csrc/op_anomaly.c +255 -0
- package/csrc/op_assert.c +761 -0
- package/csrc/op_bin.c +248 -0
- package/csrc/op_cast.c +523 -0
- package/csrc/op_clip.c +99 -0
- package/csrc/op_date_trunc.c +355 -0
- package/csrc/op_datetime.c +394 -0
- package/csrc/op_derive.c +216 -0
- package/csrc/op_diff.c +250 -0
- package/csrc/op_ewma.c +222 -0
- package/csrc/op_explode.c +206 -0
- package/csrc/op_fill_down.c +235 -0
- package/csrc/op_fill_null.c +268 -0
- package/csrc/op_filter.c +181 -0
- package/csrc/op_frequency.c +721 -0
- package/csrc/op_grep.c +181 -0
- package/csrc/op_group_agg.c +1956 -0
- package/csrc/op_hash.c +159 -0
- package/csrc/op_head.c +84 -0
- package/csrc/op_interpolate.c +445 -0
- package/csrc/op_join.c +2902 -0
- package/csrc/op_json_extract.c +227 -0
- package/csrc/op_json_filter.c +384 -0
- package/csrc/op_json_flatten.c +293 -0
- package/csrc/op_json_schema.c +503 -0
- package/csrc/op_label_encode.c +419 -0
- package/csrc/op_lag.c +181 -0
- package/csrc/op_lead.c +242 -0
- package/csrc/op_normalize.c +510 -0
- package/csrc/op_onehot.c +457 -0
- package/csrc/op_pivot.c +1754 -0
- package/csrc/op_quarantine.c +189 -0
- package/csrc/op_registry.c +3044 -0
- package/csrc/op_rename.c +129 -0
- package/csrc/op_replace.c +354 -0
- package/csrc/op_rleid.c +297 -0
- package/csrc/op_rowid.c +559 -0
- package/csrc/op_sample.c +158 -0
- package/csrc/op_schema.c +1341 -0
- package/csrc/op_schema_infer.c +252 -0
- package/csrc/op_select.c +340 -0
- package/csrc/op_set.c +3449 -0
- package/csrc/op_skip.c +95 -0
- package/csrc/op_sort.c +819 -0
- package/csrc/op_source_name.c +120 -0
- package/csrc/op_split.c +151 -0
- package/csrc/op_split_data.c +119 -0
- package/csrc/op_stack.c +271 -0
- package/csrc/op_stats.c +875 -0
- package/csrc/op_step.c +333 -0
- package/csrc/op_tail.c +105 -0
- package/csrc/op_tee.c +338 -0
- package/csrc/op_top.c +357 -0
- package/csrc/op_trim.c +138 -0
- package/csrc/op_unique.c +1343 -0
- package/csrc/op_unpivot.c +193 -0
- package/csrc/op_validate.c +648 -0
- package/csrc/op_window.c +591 -0
- package/csrc/path_policy.c +85 -0
- package/csrc/pipeline.c +1088 -0
- package/csrc/recipes.c +104 -0
- package/csrc/recipes.h +27 -0
- package/csrc/report.c +506 -0
- package/csrc/report.h +22 -0
- package/csrc/selector.c +1097 -0
- package/csrc/size_utils.c +348 -0
- package/csrc/spill.c +317 -0
- package/csrc/spill.h +21 -0
- package/csrc/tranfi.h +291 -0
- package/csrc/transform.h +209 -0
- package/csrc/transform_api.c +2237 -0
- package/csrc/transform_categorical.c +923 -0
- package/csrc/transform_internal.h +472 -0
- package/csrc/transform_json.c +3812 -0
- package/csrc/transform_numeric.c +1966 -0
- package/csrc/transform_sha256.c +154 -0
- package/csrc/transform_wasm.h +162 -0
- package/csrc/transform_wasm_api.c +1373 -0
- package/csrc/wasm_api.c +218 -0
- package/napi_api.c +534 -0
- package/napi_transform.c +1648 -0
- package/napi_transform.h +8 -0
- package/package.json +64 -59
- package/scripts/install-native.js +76 -0
- package/scripts/prepack.js +64 -0
- package/scripts/sync-csrc.js +23 -0
- package/src/cli.js +190 -0
- package/src/engines/duckdb.js +142 -0
- package/src/index.js +925 -0
- package/src/memory_policy.js +411 -0
- package/src/native.js +18 -0
- package/src/pipeline.js +709 -0
- package/src/recipe_json.js +80 -0
- package/src/server.js +279 -0
- package/src/transform.js +403 -0
- package/src/transform_error.js +10 -0
- package/src/wasm.js +21 -0
- package/wasm/index.js +732 -0
- package/wasm/package.json +1 -0
- package/wasm/tranfi_core.js +0 -0
- package/wasm/transform.js +1156 -0
- package/wasm/worker.js +786 -0
- package/dist/bundle.js +0 -1
- package/index.html +0 -18
- package/src/app.css +0 -169
- package/src/app.js +0 -203
- package/src/app.vue +0 -250
- package/src/bulma-input.vue +0 -110
- package/src/common-inputs.js +0 -28
- package/src/main.js +0 -20
- package/src/transforms.js +0 -166
- package/webpack.config.js +0 -108
package/src/index.js
ADDED
|
@@ -0,0 +1,925 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tranfi — Streaming ETL language + runtime.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* const { pipeline, codec, ops, expr } = require('tranfi')
|
|
6
|
+
*
|
|
7
|
+
* const p = pipeline([
|
|
8
|
+
* codec.csv({ delimiter: ',' }),
|
|
9
|
+
* ops.filter(expr("col('age') > 25")),
|
|
10
|
+
* ops.select(['name', 'age']),
|
|
11
|
+
* codec.csvEncode(),
|
|
12
|
+
* ])
|
|
13
|
+
*
|
|
14
|
+
* const result = await p.run({ inputFile: './data.csv' })
|
|
15
|
+
* console.log(result.outputText)
|
|
16
|
+
*
|
|
17
|
+
* // Or use DSL string:
|
|
18
|
+
* const p2 = pipeline('csv | filter "col(\'age\') > 25" | csv')
|
|
19
|
+
* const result2 = await p2.run({ inputFile: './data.csv' })
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const { Pipeline, PipelineResult, compileDsl, compileToSql, loadRecipe, saveRecipe, recipes } = require('./pipeline.js')
|
|
23
|
+
|
|
24
|
+
function pipeline(steps, { engine } = {}) {
|
|
25
|
+
return new Pipeline(steps, { engine })
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function param(name, defaultValue) {
|
|
29
|
+
const result = { param: name }
|
|
30
|
+
if (defaultValue !== undefined) result.default = defaultValue
|
|
31
|
+
return result
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function expr(text) {
|
|
35
|
+
return text
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const codec = {
|
|
39
|
+
csv({ delimiter = ',', header = true, batchSize = 1024, repair = false, mode, strict = false, maxErrorBytes = 4096, maxRecordBytes = 64 * 1024 * 1024, maxColumns = 8192, audit = false, auditLimit, auditIncludeRow, auditColumns, auditRedact, auditHashColumns, auditMaxBytes, auditMaxCellBytes, nulls, na, quotedNulls = true, comment, trimWs = true, skipEmptyRows = false, skipRepeatedHeader = false, skip = 0, nMax, maxRows } = {}) {
|
|
40
|
+
const args = {}
|
|
41
|
+
if (delimiter !== ',') args.delimiter = delimiter
|
|
42
|
+
if (!header) args.header = false
|
|
43
|
+
if (batchSize !== 1024) args.batch_size = batchSize
|
|
44
|
+
if (repair) args.repair = true
|
|
45
|
+
if (mode !== undefined) args.mode = mode
|
|
46
|
+
if (strict) args.strict = true
|
|
47
|
+
if (maxErrorBytes !== 4096) args.max_error_bytes = Number(maxErrorBytes)
|
|
48
|
+
if (maxRecordBytes !== 64 * 1024 * 1024) args.max_record_bytes = Number(maxRecordBytes)
|
|
49
|
+
if (maxColumns !== 8192) args.max_columns = Number(maxColumns)
|
|
50
|
+
if (audit) args.audit = true
|
|
51
|
+
if (auditLimit !== undefined) args.audit_limit = Number(auditLimit)
|
|
52
|
+
if (auditIncludeRow !== undefined) args.audit_include_row = !!auditIncludeRow
|
|
53
|
+
if (auditColumns !== undefined) args.audit_columns = auditColumns
|
|
54
|
+
if (auditRedact !== undefined) args.audit_redact = auditRedact
|
|
55
|
+
if (auditHashColumns !== undefined) args.audit_hash_columns = auditHashColumns
|
|
56
|
+
if (auditMaxBytes !== undefined) args.audit_max_bytes = Number(auditMaxBytes)
|
|
57
|
+
if (auditMaxCellBytes !== undefined) args.audit_max_cell_bytes = Number(auditMaxCellBytes)
|
|
58
|
+
if (nulls !== undefined) args.nulls = nulls
|
|
59
|
+
else if (na !== undefined) args.na = na
|
|
60
|
+
if (quotedNulls !== true) args.quoted_nulls = Boolean(quotedNulls)
|
|
61
|
+
if (comment) args.comment = String(comment)
|
|
62
|
+
if (trimWs !== true) args.trim_ws = Boolean(trimWs)
|
|
63
|
+
if (skipEmptyRows) args.skip_empty_rows = true
|
|
64
|
+
if (skipRepeatedHeader) args.skip_repeated_header = true
|
|
65
|
+
if (skip) args.skip = Number(skip)
|
|
66
|
+
if (nMax !== undefined) args.n_max = Number(nMax)
|
|
67
|
+
else if (maxRows !== undefined) args.max_rows = Number(maxRows)
|
|
68
|
+
return { op: 'codec.csv.decode', args }
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
csvDecode(opts = {}) {
|
|
72
|
+
return codec.csv(opts)
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
csvEncode({ delimiter = ',' } = {}) {
|
|
76
|
+
const args = {}
|
|
77
|
+
if (delimiter !== ',') args.delimiter = delimiter
|
|
78
|
+
return { op: 'codec.csv.encode', args }
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
jsonl({ batchSize = 1024, onError = 'skip', maxErrorBytes = 4096, maxRecordBytes = 64 * 1024 * 1024 } = {}) {
|
|
82
|
+
const args = {}
|
|
83
|
+
if (batchSize !== 1024) args.batch_size = batchSize
|
|
84
|
+
if (onError !== 'skip') args.on_error = onError
|
|
85
|
+
if (maxErrorBytes !== 4096) args.max_error_bytes = Number(maxErrorBytes)
|
|
86
|
+
if (maxRecordBytes !== 64 * 1024 * 1024) args.max_record_bytes = Number(maxRecordBytes)
|
|
87
|
+
return { op: 'codec.jsonl.decode', args }
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
jsonlDecode(opts = {}) {
|
|
91
|
+
return codec.jsonl(opts)
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
jsonlEncode() {
|
|
95
|
+
return { op: 'codec.jsonl.encode', args: {} }
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
text({ batchSize = 1024, maxErrorBytes = 4096, maxRecordBytes = 64 * 1024 * 1024 } = {}) {
|
|
99
|
+
const args = {}
|
|
100
|
+
if (batchSize !== 1024) args.batch_size = batchSize
|
|
101
|
+
if (maxErrorBytes !== 4096) args.max_error_bytes = Number(maxErrorBytes)
|
|
102
|
+
if (maxRecordBytes !== 64 * 1024 * 1024) args.max_record_bytes = Number(maxRecordBytes)
|
|
103
|
+
return { op: 'codec.text.decode', args }
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
textDecode(opts = {}) {
|
|
107
|
+
return codec.text(opts)
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
textEncode() {
|
|
111
|
+
return { op: 'codec.text.encode', args: {} }
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
tableEncode({ maxWidth = 40, maxRows = 0 } = {}) {
|
|
115
|
+
const args = {}
|
|
116
|
+
if (maxWidth !== 40) args.max_width = maxWidth
|
|
117
|
+
if (maxRows !== 0) args.max_rows = maxRows
|
|
118
|
+
return { op: 'codec.table.encode', args }
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const ops = {
|
|
123
|
+
filter(expression, { audit = false, auditLimit, auditIncludeRow, auditColumns, auditRedact, auditHashColumns, auditMaxBytes, auditMaxCellBytes } = {}) {
|
|
124
|
+
const args = { expr: expression }
|
|
125
|
+
if (audit) args.audit = true
|
|
126
|
+
if (auditLimit !== undefined) args.audit_limit = auditLimit
|
|
127
|
+
if (auditIncludeRow !== undefined) args.audit_include_row = !!auditIncludeRow
|
|
128
|
+
if (auditColumns !== undefined) args.audit_columns = auditColumns
|
|
129
|
+
if (auditRedact !== undefined) args.audit_redact = auditRedact
|
|
130
|
+
if (auditHashColumns !== undefined) args.audit_hash_columns = auditHashColumns
|
|
131
|
+
if (auditMaxBytes !== undefined) args.audit_max_bytes = Number(auditMaxBytes)
|
|
132
|
+
if (auditMaxCellBytes !== undefined) args.audit_max_cell_bytes = Number(auditMaxCellBytes)
|
|
133
|
+
return { op: 'filter', args }
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
select(columns) {
|
|
137
|
+
return { op: 'select', args: { columns } }
|
|
138
|
+
},
|
|
139
|
+
|
|
140
|
+
relocate(columns, { before, after } = {}) {
|
|
141
|
+
const args = { columns }
|
|
142
|
+
if (before !== undefined) args.before = before
|
|
143
|
+
if (after !== undefined) args.after = after
|
|
144
|
+
return { op: 'relocate', args }
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
rename(mapping) {
|
|
148
|
+
return { op: 'rename', args: { mapping } }
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
head(n) {
|
|
152
|
+
return { op: 'head', args: { n } }
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
skip(n) {
|
|
156
|
+
return { op: 'skip', args: { n } }
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
derive(columns) {
|
|
160
|
+
// columns: { name: expr, ... } or [{ name, expr }, ...]
|
|
161
|
+
const cols = Array.isArray(columns)
|
|
162
|
+
? columns
|
|
163
|
+
: Object.entries(columns).map(([name, e]) => ({ name, expr: e }))
|
|
164
|
+
return { op: 'derive', args: { columns: cols } }
|
|
165
|
+
},
|
|
166
|
+
|
|
167
|
+
sourceName({ result = '_source', defaultValue = '' } = {}) {
|
|
168
|
+
const args = {}
|
|
169
|
+
if (result !== '_source') args.result = result
|
|
170
|
+
if (defaultValue !== '') args.default = defaultValue
|
|
171
|
+
return { op: 'source-name', args }
|
|
172
|
+
},
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
across(columns, { functions, fn, names, replace } = {}) {
|
|
176
|
+
const args = { columns }
|
|
177
|
+
if (functions !== undefined) args.functions = Array.isArray(functions) ? functions : [functions]
|
|
178
|
+
else if (fn !== undefined) args.fn = fn
|
|
179
|
+
else throw new Error('across requires functions or fn')
|
|
180
|
+
if (names !== undefined) args.names = names
|
|
181
|
+
if (replace !== undefined) args.replace = !!replace
|
|
182
|
+
return { op: 'across', args }
|
|
183
|
+
},
|
|
184
|
+
|
|
185
|
+
stats(statsList) {
|
|
186
|
+
const args = {}
|
|
187
|
+
if (statsList) args.stats = statsList
|
|
188
|
+
return { op: 'stats', args }
|
|
189
|
+
},
|
|
190
|
+
|
|
191
|
+
scan(statsList) {
|
|
192
|
+
const args = {}
|
|
193
|
+
if (statsList) args.stats = statsList
|
|
194
|
+
return { op: 'scan', args }
|
|
195
|
+
},
|
|
196
|
+
|
|
197
|
+
unique(columns, { maxKeys, maxStateBytes, sorted = false, mode, approx = false, bloomBytes, bloomHashes } = {}) {
|
|
198
|
+
const args = {}
|
|
199
|
+
if (columns) args.columns = columns
|
|
200
|
+
if (mode !== undefined) args.mode = mode
|
|
201
|
+
if (approx) args.approx = true
|
|
202
|
+
if (bloomBytes !== undefined) args.bloom_bytes = bloomBytes
|
|
203
|
+
if (bloomHashes !== undefined) args.bloom_hashes = bloomHashes
|
|
204
|
+
if (maxKeys !== undefined) args.max_keys = maxKeys
|
|
205
|
+
if (maxStateBytes !== undefined) args.max_state_bytes = maxStateBytes
|
|
206
|
+
if (sorted) args.sorted = true
|
|
207
|
+
return { op: 'unique', args }
|
|
208
|
+
},
|
|
209
|
+
|
|
210
|
+
sort(columns) {
|
|
211
|
+
// columns: ['age', '-name'] or [{ name, desc }, ...]
|
|
212
|
+
const cols = columns.map(c => {
|
|
213
|
+
if (typeof c === 'string') {
|
|
214
|
+
const desc = c.startsWith('-')
|
|
215
|
+
return { name: desc ? c.slice(1) : c, desc }
|
|
216
|
+
}
|
|
217
|
+
return c
|
|
218
|
+
})
|
|
219
|
+
return { op: 'sort', args: { columns: cols } }
|
|
220
|
+
},
|
|
221
|
+
|
|
222
|
+
tail(n) {
|
|
223
|
+
return { op: 'tail', args: { n } }
|
|
224
|
+
},
|
|
225
|
+
|
|
226
|
+
validate(expression, { audit = false, auditLimit, maxFailures, maxFailureRate, warnFailureRate, name, message, rules, rulesFile, auditIncludeRow, auditColumns, auditRedact, auditHashColumns, auditMaxBytes, auditMaxCellBytes } = {}) {
|
|
227
|
+
const args = {}
|
|
228
|
+
const isBuffer = typeof Buffer !== 'undefined' && Buffer.isBuffer(expression)
|
|
229
|
+
const firstArgIsRules = rules === undefined && expression && typeof expression === 'object' && !isBuffer
|
|
230
|
+
if (rulesFile !== undefined) args.rules_file = rulesFile
|
|
231
|
+
if (rules !== undefined) args.rules = rules
|
|
232
|
+
else if (firstArgIsRules) args.rules = expression
|
|
233
|
+
else if (expression !== undefined && expression !== null) args.expr = expression
|
|
234
|
+
if (args.expr === undefined && args.rules === undefined && args.rules_file === undefined) {
|
|
235
|
+
throw new Error('validate requires expression, rules, or rulesFile')
|
|
236
|
+
}
|
|
237
|
+
if (audit) args.audit = true
|
|
238
|
+
if (auditLimit !== undefined) args.audit_limit = auditLimit
|
|
239
|
+
if (auditIncludeRow !== undefined) args.audit_include_row = !!auditIncludeRow
|
|
240
|
+
if (auditColumns !== undefined) args.audit_columns = auditColumns
|
|
241
|
+
if (auditRedact !== undefined) args.audit_redact = auditRedact
|
|
242
|
+
if (auditHashColumns !== undefined) args.audit_hash_columns = auditHashColumns
|
|
243
|
+
if (auditMaxBytes !== undefined) args.audit_max_bytes = Number(auditMaxBytes)
|
|
244
|
+
if (auditMaxCellBytes !== undefined) args.audit_max_cell_bytes = Number(auditMaxCellBytes)
|
|
245
|
+
if (maxFailures !== undefined) args.max_failures = maxFailures
|
|
246
|
+
if (maxFailureRate !== undefined) args.max_failure_rate = maxFailureRate
|
|
247
|
+
if (warnFailureRate !== undefined) args.warn_failure_rate = warnFailureRate
|
|
248
|
+
if (name !== undefined && name !== null) args.name = name
|
|
249
|
+
if (message) args.message = message
|
|
250
|
+
return { op: 'validate', args }
|
|
251
|
+
},
|
|
252
|
+
|
|
253
|
+
assert(expression, { action = 'fail', name = 'assert', message = '', result = '_assert', audit = false, auditLimit, aggregate, op, value, column, tolerance, rel, auditIncludeRow, auditColumns, auditRedact, auditHashColumns, auditMaxBytes, auditMaxCellBytes } = {}) {
|
|
254
|
+
const args = { action }
|
|
255
|
+
if (aggregate !== undefined && aggregate !== null) {
|
|
256
|
+
if (expression !== undefined && expression !== null) throw new Error('assert accepts either expression or aggregate, not both')
|
|
257
|
+
if (op === undefined || value === undefined) throw new Error('aggregate assert requires op and value')
|
|
258
|
+
args.aggregate = aggregate
|
|
259
|
+
args.op = op
|
|
260
|
+
args.value = Number(value)
|
|
261
|
+
if (column !== undefined && column !== null) args.column = column
|
|
262
|
+
if (tolerance !== undefined) args.tolerance = Number(tolerance)
|
|
263
|
+
if (rel !== undefined) args.rel = !!rel
|
|
264
|
+
} else if (expression !== undefined && expression !== null) {
|
|
265
|
+
if (tolerance !== undefined || rel !== undefined) throw new Error('assert tolerance and rel require aggregate')
|
|
266
|
+
args.expr = expression
|
|
267
|
+
} else {
|
|
268
|
+
throw new Error('assert requires expression or aggregate')
|
|
269
|
+
}
|
|
270
|
+
if (name !== undefined && name !== null) args.name = name
|
|
271
|
+
if (message) args.message = message
|
|
272
|
+
if (result !== undefined && result !== null) args.result = result
|
|
273
|
+
if (audit) args.audit = true
|
|
274
|
+
if (auditLimit !== undefined) args.audit_limit = auditLimit
|
|
275
|
+
if (auditIncludeRow !== undefined) args.audit_include_row = !!auditIncludeRow
|
|
276
|
+
if (auditColumns !== undefined) args.audit_columns = auditColumns
|
|
277
|
+
if (auditRedact !== undefined) args.audit_redact = auditRedact
|
|
278
|
+
if (auditHashColumns !== undefined) args.audit_hash_columns = auditHashColumns
|
|
279
|
+
if (auditMaxBytes !== undefined) args.audit_max_bytes = Number(auditMaxBytes)
|
|
280
|
+
if (auditMaxCellBytes !== undefined) args.audit_max_cell_bytes = Number(auditMaxCellBytes)
|
|
281
|
+
return { op: 'assert', args }
|
|
282
|
+
},
|
|
283
|
+
|
|
284
|
+
quarantine(expression, { name, message, auditIncludeRow, auditColumns, auditRedact, auditHashColumns, auditMaxBytes, auditMaxCellBytes } = {}) {
|
|
285
|
+
const args = { expr: expression }
|
|
286
|
+
if (name !== undefined && name !== null) args.name = name
|
|
287
|
+
if (message) args.message = message
|
|
288
|
+
if (auditIncludeRow !== undefined) args.audit_include_row = !!auditIncludeRow
|
|
289
|
+
if (auditColumns !== undefined) args.audit_columns = auditColumns
|
|
290
|
+
if (auditRedact !== undefined) args.audit_redact = auditRedact
|
|
291
|
+
if (auditHashColumns !== undefined) args.audit_hash_columns = auditHashColumns
|
|
292
|
+
if (auditMaxBytes !== undefined) args.audit_max_bytes = Number(auditMaxBytes)
|
|
293
|
+
if (auditMaxCellBytes !== undefined) args.audit_max_cell_bytes = Number(auditMaxCellBytes)
|
|
294
|
+
return { op: 'quarantine', args }
|
|
295
|
+
},
|
|
296
|
+
|
|
297
|
+
schema({ baseline, columns, required, nonNull, nullable, values, min, max, regex, mode = 'fail', name = 'schema', message = '', result = '_schema', audit = false, auditLimit, maxRegexPatternBytes, maxRegexCellBytes, allowExtraColumns, requireValuesSeen, auditIncludeRow, auditColumns, auditRedact, auditHashColumns, auditMaxBytes, auditMaxCellBytes } = {}) {
|
|
298
|
+
const args = { mode, action: mode }
|
|
299
|
+
if (baseline !== undefined) args.baseline = baseline
|
|
300
|
+
if (columns !== undefined) args.columns = columns
|
|
301
|
+
if (required !== undefined) args.required = required
|
|
302
|
+
if (nonNull !== undefined) args.non_null = nonNull
|
|
303
|
+
if (nullable !== undefined) args.nullable = nullable
|
|
304
|
+
if (values !== undefined) args.values = values
|
|
305
|
+
if (min !== undefined) args.min = min
|
|
306
|
+
if (max !== undefined) args.max = max
|
|
307
|
+
if (regex !== undefined) args.regex = regex
|
|
308
|
+
if (name !== undefined && name !== null) args.name = name
|
|
309
|
+
if (message) args.message = message
|
|
310
|
+
if (result !== undefined && result !== null) args.result = result
|
|
311
|
+
if (audit) args.audit = true
|
|
312
|
+
if (auditLimit !== undefined) args.audit_limit = auditLimit
|
|
313
|
+
if (auditIncludeRow !== undefined) args.audit_include_row = !!auditIncludeRow
|
|
314
|
+
if (auditColumns !== undefined) args.audit_columns = auditColumns
|
|
315
|
+
if (auditRedact !== undefined) args.audit_redact = auditRedact
|
|
316
|
+
if (auditHashColumns !== undefined) args.audit_hash_columns = auditHashColumns
|
|
317
|
+
if (auditMaxBytes !== undefined) args.audit_max_bytes = Number(auditMaxBytes)
|
|
318
|
+
if (auditMaxCellBytes !== undefined) args.audit_max_cell_bytes = Number(auditMaxCellBytes)
|
|
319
|
+
if (maxRegexPatternBytes !== undefined) args.max_regex_pattern_bytes = maxRegexPatternBytes
|
|
320
|
+
if (maxRegexCellBytes !== undefined) args.max_regex_cell_bytes = maxRegexCellBytes
|
|
321
|
+
if (allowExtraColumns !== undefined) args.allow_extra_columns = !!allowExtraColumns
|
|
322
|
+
if (requireValuesSeen !== undefined) args.require_values_seen = !!requireValuesSeen
|
|
323
|
+
return { op: 'schema', args }
|
|
324
|
+
},
|
|
325
|
+
|
|
326
|
+
schemaInfer({ rows } = {}) {
|
|
327
|
+
const args = {}
|
|
328
|
+
if (rows !== undefined) args.rows = rows
|
|
329
|
+
return { op: 'schema-infer', args }
|
|
330
|
+
},
|
|
331
|
+
|
|
332
|
+
tee({ expr, channel = 'samples', columns, limit = 1000, every = 1, name = 'tee', includeRow = true, auditIncludeRow, auditColumns, auditRedact, auditHashColumns, auditMaxBytes, auditMaxCellBytes } = {}) {
|
|
333
|
+
const args = { channel, limit, every, name, include_row: includeRow }
|
|
334
|
+
if (expr !== undefined && expr !== null) args.expr = expr
|
|
335
|
+
if (columns !== undefined && columns !== null) args.columns = columns
|
|
336
|
+
if (auditIncludeRow !== undefined) args.audit_include_row = !!auditIncludeRow
|
|
337
|
+
if (auditColumns !== undefined) args.audit_columns = auditColumns
|
|
338
|
+
if (auditRedact !== undefined) args.audit_redact = auditRedact
|
|
339
|
+
if (auditHashColumns !== undefined) args.audit_hash_columns = auditHashColumns
|
|
340
|
+
if (auditMaxBytes !== undefined) args.audit_max_bytes = Number(auditMaxBytes)
|
|
341
|
+
if (auditMaxCellBytes !== undefined) args.audit_max_cell_bytes = Number(auditMaxCellBytes)
|
|
342
|
+
return { op: 'tee', args }
|
|
343
|
+
},
|
|
344
|
+
|
|
345
|
+
trim(columns) {
|
|
346
|
+
const args = {}
|
|
347
|
+
if (columns) args.columns = columns
|
|
348
|
+
return { op: 'trim', args }
|
|
349
|
+
},
|
|
350
|
+
|
|
351
|
+
fillNull(mapping, { audit = false, auditLimit, auditIncludeRow, auditColumns, auditRedact, auditHashColumns, auditMaxBytes, auditMaxCellBytes } = {}) {
|
|
352
|
+
const args = { mapping }
|
|
353
|
+
if (audit) args.audit = true
|
|
354
|
+
if (auditLimit !== undefined) args.audit_limit = auditLimit
|
|
355
|
+
if (auditIncludeRow !== undefined) args.audit_include_row = !!auditIncludeRow
|
|
356
|
+
if (auditColumns !== undefined) args.audit_columns = auditColumns
|
|
357
|
+
if (auditRedact !== undefined) args.audit_redact = auditRedact
|
|
358
|
+
if (auditHashColumns !== undefined) args.audit_hash_columns = auditHashColumns
|
|
359
|
+
if (auditMaxBytes !== undefined) args.audit_max_bytes = Number(auditMaxBytes)
|
|
360
|
+
if (auditMaxCellBytes !== undefined) args.audit_max_cell_bytes = Number(auditMaxCellBytes)
|
|
361
|
+
return { op: 'fill-null', args }
|
|
362
|
+
},
|
|
363
|
+
|
|
364
|
+
cast(mapping, { onError, audit = false, auditLimit, auditIncludeRow, auditColumns, auditRedact, auditHashColumns, auditMaxBytes, auditMaxCellBytes } = {}) {
|
|
365
|
+
const args = { mapping }
|
|
366
|
+
if (onError !== undefined) args.on_error = onError
|
|
367
|
+
if (audit) args.audit = true
|
|
368
|
+
if (auditLimit !== undefined) args.audit_limit = auditLimit
|
|
369
|
+
if (auditIncludeRow !== undefined) args.audit_include_row = !!auditIncludeRow
|
|
370
|
+
if (auditColumns !== undefined) args.audit_columns = auditColumns
|
|
371
|
+
if (auditRedact !== undefined) args.audit_redact = auditRedact
|
|
372
|
+
if (auditHashColumns !== undefined) args.audit_hash_columns = auditHashColumns
|
|
373
|
+
if (auditMaxBytes !== undefined) args.audit_max_bytes = Number(auditMaxBytes)
|
|
374
|
+
if (auditMaxCellBytes !== undefined) args.audit_max_cell_bytes = Number(auditMaxCellBytes)
|
|
375
|
+
return { op: 'cast', args }
|
|
376
|
+
},
|
|
377
|
+
|
|
378
|
+
clip(column, { min, max } = {}) {
|
|
379
|
+
const args = { column }
|
|
380
|
+
if (min !== undefined) args.min = min
|
|
381
|
+
if (max !== undefined) args.max = max
|
|
382
|
+
return { op: 'clip', args }
|
|
383
|
+
},
|
|
384
|
+
|
|
385
|
+
replace(column, pattern, replacement, { regex = false, audit = false, auditLimit, auditIncludeRow, auditColumns, auditRedact, auditHashColumns, auditMaxBytes, auditMaxCellBytes } = {}) {
|
|
386
|
+
const args = { column, pattern, replacement }
|
|
387
|
+
if (regex) args.regex = true
|
|
388
|
+
if (audit) args.audit = true
|
|
389
|
+
if (auditLimit !== undefined) args.audit_limit = auditLimit
|
|
390
|
+
if (auditIncludeRow !== undefined) args.audit_include_row = !!auditIncludeRow
|
|
391
|
+
if (auditColumns !== undefined) args.audit_columns = auditColumns
|
|
392
|
+
if (auditRedact !== undefined) args.audit_redact = auditRedact
|
|
393
|
+
if (auditHashColumns !== undefined) args.audit_hash_columns = auditHashColumns
|
|
394
|
+
if (auditMaxBytes !== undefined) args.audit_max_bytes = Number(auditMaxBytes)
|
|
395
|
+
if (auditMaxCellBytes !== undefined) args.audit_max_cell_bytes = Number(auditMaxCellBytes)
|
|
396
|
+
return { op: 'replace', args }
|
|
397
|
+
},
|
|
398
|
+
|
|
399
|
+
hash(columns) {
|
|
400
|
+
const args = {}
|
|
401
|
+
if (columns) args.columns = columns
|
|
402
|
+
return { op: 'hash', args }
|
|
403
|
+
},
|
|
404
|
+
|
|
405
|
+
bin(column, boundaries, { missing, onTypeError } = {}) {
|
|
406
|
+
const args = { column, boundaries }
|
|
407
|
+
if (missing !== undefined) args.missing = missing
|
|
408
|
+
if (onTypeError !== undefined) args.on_type_error = onTypeError
|
|
409
|
+
return { op: 'bin', args }
|
|
410
|
+
},
|
|
411
|
+
|
|
412
|
+
ewma(column, alpha, { result, missing, onTypeError } = {}) {
|
|
413
|
+
const args = { column, alpha }
|
|
414
|
+
if (result !== undefined) args.result = result
|
|
415
|
+
if (missing !== undefined) args.missing = missing
|
|
416
|
+
if (onTypeError !== undefined) args.on_type_error = onTypeError
|
|
417
|
+
return { op: 'ewma', args }
|
|
418
|
+
},
|
|
419
|
+
|
|
420
|
+
anomaly(column, { threshold = 3.0, result, missing, onTypeError } = {}) {
|
|
421
|
+
const args = { column }
|
|
422
|
+
if (threshold !== undefined) args.threshold = threshold
|
|
423
|
+
if (result !== undefined) args.result = result
|
|
424
|
+
if (missing !== undefined) args.missing = missing
|
|
425
|
+
if (onTypeError !== undefined) args.on_type_error = onTypeError
|
|
426
|
+
return { op: 'anomaly', args }
|
|
427
|
+
},
|
|
428
|
+
|
|
429
|
+
fillDown(columns) {
|
|
430
|
+
const args = {}
|
|
431
|
+
if (columns) args.columns = columns
|
|
432
|
+
return { op: 'fill-down', args }
|
|
433
|
+
},
|
|
434
|
+
|
|
435
|
+
step(column, func, resultOrOptions) {
|
|
436
|
+
const args = { column, func }
|
|
437
|
+
const options = resultOrOptions && typeof resultOrOptions === 'object' ? resultOrOptions : { result: resultOrOptions }
|
|
438
|
+
const { result, missing, onTypeError } = options || {}
|
|
439
|
+
if (result) args.result = result
|
|
440
|
+
if (missing) args.missing = missing
|
|
441
|
+
if (onTypeError) args.on_type_error = onTypeError
|
|
442
|
+
return { op: 'step', args }
|
|
443
|
+
},
|
|
444
|
+
|
|
445
|
+
window(column, size, func, resultOrOptions) {
|
|
446
|
+
const args = { column, size, func }
|
|
447
|
+
const options = resultOrOptions && typeof resultOrOptions === 'object' ? resultOrOptions : { result: resultOrOptions }
|
|
448
|
+
const { result, missing, onTypeError } = options || {}
|
|
449
|
+
if (result !== undefined) args.result = result
|
|
450
|
+
if (missing !== undefined) args.missing = missing
|
|
451
|
+
if (onTypeError !== undefined) args.on_type_error = onTypeError
|
|
452
|
+
return { op: 'window', args }
|
|
453
|
+
},
|
|
454
|
+
|
|
455
|
+
rollingSum(column, size, { result, missing, onTypeError } = {}) {
|
|
456
|
+
const args = { column, size }
|
|
457
|
+
if (result !== undefined) args.result = result
|
|
458
|
+
if (missing !== undefined) args.missing = missing
|
|
459
|
+
if (onTypeError !== undefined) args.on_type_error = onTypeError
|
|
460
|
+
return { op: 'rolling-sum', args }
|
|
461
|
+
},
|
|
462
|
+
|
|
463
|
+
rollingMean(column, size, { result, missing, onTypeError } = {}) {
|
|
464
|
+
const args = { column, size }
|
|
465
|
+
if (result !== undefined) args.result = result
|
|
466
|
+
if (missing !== undefined) args.missing = missing
|
|
467
|
+
if (onTypeError !== undefined) args.on_type_error = onTypeError
|
|
468
|
+
return { op: 'rolling-mean', args }
|
|
469
|
+
},
|
|
470
|
+
|
|
471
|
+
rollingMin(column, size, { result, missing, onTypeError } = {}) {
|
|
472
|
+
const args = { column, size }
|
|
473
|
+
if (result !== undefined) args.result = result
|
|
474
|
+
if (missing !== undefined) args.missing = missing
|
|
475
|
+
if (onTypeError !== undefined) args.on_type_error = onTypeError
|
|
476
|
+
return { op: 'rolling-min', args }
|
|
477
|
+
},
|
|
478
|
+
|
|
479
|
+
rollingMax(column, size, { result, missing, onTypeError } = {}) {
|
|
480
|
+
const args = { column, size }
|
|
481
|
+
if (result !== undefined) args.result = result
|
|
482
|
+
if (missing !== undefined) args.missing = missing
|
|
483
|
+
if (onTypeError !== undefined) args.on_type_error = onTypeError
|
|
484
|
+
return { op: 'rolling-max', args }
|
|
485
|
+
},
|
|
486
|
+
|
|
487
|
+
rollingAny(column, size, { result, nulls = 'ignore' } = {}) {
|
|
488
|
+
const args = { column, size }
|
|
489
|
+
if (result) args.result = result
|
|
490
|
+
if (nulls !== 'ignore') args.nulls = nulls
|
|
491
|
+
return { op: 'rolling-any', args }
|
|
492
|
+
},
|
|
493
|
+
|
|
494
|
+
rollingAll(column, size, { result, nulls = 'ignore' } = {}) {
|
|
495
|
+
const args = { column, size }
|
|
496
|
+
if (result) args.result = result
|
|
497
|
+
if (nulls !== 'ignore') args.nulls = nulls
|
|
498
|
+
return { op: 'rolling-all', args }
|
|
499
|
+
},
|
|
500
|
+
|
|
501
|
+
explode(column, delimiter, options = {}) {
|
|
502
|
+
if (delimiter && typeof delimiter === 'object') {
|
|
503
|
+
options = delimiter
|
|
504
|
+
delimiter = undefined
|
|
505
|
+
}
|
|
506
|
+
const args = { column }
|
|
507
|
+
if (delimiter && delimiter !== ',') args.delimiter = delimiter
|
|
508
|
+
const { maxTokensPerRow, maxOutputRowsPerInputRow, maxOutputRowsPerBatch, maxTokenBytes } = options || {}
|
|
509
|
+
if (maxTokensPerRow !== undefined) args.max_tokens_per_row = maxTokensPerRow
|
|
510
|
+
if (maxOutputRowsPerInputRow !== undefined) args.max_output_rows_per_input_row = maxOutputRowsPerInputRow
|
|
511
|
+
if (maxOutputRowsPerBatch !== undefined) args.max_output_rows_per_batch = maxOutputRowsPerBatch
|
|
512
|
+
if (maxTokenBytes !== undefined) args.max_token_bytes = maxTokenBytes
|
|
513
|
+
return { op: 'explode', args }
|
|
514
|
+
},
|
|
515
|
+
|
|
516
|
+
split(column, names, delimiter) {
|
|
517
|
+
const args = { column, names }
|
|
518
|
+
if (delimiter && delimiter !== ' ') args.delimiter = delimiter
|
|
519
|
+
return { op: 'split', args }
|
|
520
|
+
},
|
|
521
|
+
|
|
522
|
+
unpivot(columns, { maxOutputRowsPerInputRow, maxOutputRowsPerBatch } = {}) {
|
|
523
|
+
const args = { columns }
|
|
524
|
+
if (maxOutputRowsPerInputRow !== undefined) args.max_output_rows_per_input_row = maxOutputRowsPerInputRow
|
|
525
|
+
if (maxOutputRowsPerBatch !== undefined) args.max_output_rows_per_batch = maxOutputRowsPerBatch
|
|
526
|
+
return { op: 'unpivot', args }
|
|
527
|
+
},
|
|
528
|
+
|
|
529
|
+
pivot(nameColumn, valueColumn, { agg, categories, maxCategories, sorted = false } = {}) {
|
|
530
|
+
const args = { name_column: nameColumn, value_column: valueColumn }
|
|
531
|
+
if (agg !== undefined) args.agg = agg
|
|
532
|
+
if (categories !== undefined) args.categories = categories
|
|
533
|
+
if (maxCategories !== undefined) args.max_categories = maxCategories
|
|
534
|
+
if (sorted) args.sorted = true
|
|
535
|
+
return { op: 'pivot', args }
|
|
536
|
+
},
|
|
537
|
+
|
|
538
|
+
interpolate(column, { method = 'linear', missing, onTypeError } = {}) {
|
|
539
|
+
const args = { column, method }
|
|
540
|
+
if (missing !== undefined) args.missing = missing
|
|
541
|
+
if (onTypeError !== undefined) args.on_type_error = onTypeError
|
|
542
|
+
return { op: 'interpolate', args }
|
|
543
|
+
},
|
|
544
|
+
|
|
545
|
+
normalize(columns, { method = 'minmax', audit = false, auditLimit, missing, onTypeError, auditIncludeRow, auditColumns, auditRedact, auditHashColumns, auditMaxBytes, auditMaxCellBytes } = {}) {
|
|
546
|
+
const cols = Array.isArray(columns)
|
|
547
|
+
? columns
|
|
548
|
+
: String(columns).split(',').map(c => c.trim()).filter(Boolean)
|
|
549
|
+
const args = { columns: cols, method }
|
|
550
|
+
if (audit) args.audit = true
|
|
551
|
+
if (auditLimit !== undefined) args.audit_limit = auditLimit
|
|
552
|
+
if (auditIncludeRow !== undefined) args.audit_include_row = !!auditIncludeRow
|
|
553
|
+
if (auditColumns !== undefined) args.audit_columns = auditColumns
|
|
554
|
+
if (auditRedact !== undefined) args.audit_redact = auditRedact
|
|
555
|
+
if (auditHashColumns !== undefined) args.audit_hash_columns = auditHashColumns
|
|
556
|
+
if (auditMaxBytes !== undefined) args.audit_max_bytes = Number(auditMaxBytes)
|
|
557
|
+
if (auditMaxCellBytes !== undefined) args.audit_max_cell_bytes = Number(auditMaxCellBytes)
|
|
558
|
+
if (missing !== undefined) args.missing = missing
|
|
559
|
+
if (onTypeError !== undefined) args.on_type_error = onTypeError
|
|
560
|
+
return { op: 'normalize', args }
|
|
561
|
+
},
|
|
562
|
+
|
|
563
|
+
acf(column, { lags = 20, missing, onTypeError } = {}) {
|
|
564
|
+
const args = { column, lags }
|
|
565
|
+
if (missing !== undefined) args.missing = missing
|
|
566
|
+
if (onTypeError !== undefined) args.on_type_error = onTypeError
|
|
567
|
+
return { op: 'acf', args }
|
|
568
|
+
},
|
|
569
|
+
|
|
570
|
+
top(n, column, desc = true) {
|
|
571
|
+
return { op: 'top', args: { n, column, desc } }
|
|
572
|
+
},
|
|
573
|
+
|
|
574
|
+
topK(n, column) {
|
|
575
|
+
return { op: 'top-k', args: { n, column, desc: true } }
|
|
576
|
+
},
|
|
577
|
+
|
|
578
|
+
bottomK(n, column) {
|
|
579
|
+
return { op: 'bottom-k', args: { n, column, desc: false } }
|
|
580
|
+
},
|
|
581
|
+
|
|
582
|
+
sliceHead(n) {
|
|
583
|
+
return { op: 'slice-head', args: { n } }
|
|
584
|
+
},
|
|
585
|
+
|
|
586
|
+
sliceTail(n) {
|
|
587
|
+
return { op: 'slice-tail', args: { n } }
|
|
588
|
+
},
|
|
589
|
+
|
|
590
|
+
sliceMin(column, n = 1, options = {}) {
|
|
591
|
+
const withTies = options && Object.prototype.hasOwnProperty.call(options, 'withTies') ? options.withTies : false
|
|
592
|
+
if (withTies) throw new Error('sliceMin withTies=true is not supported by bounded exact-N execution')
|
|
593
|
+
return { op: 'slice-min', args: { n, column, desc: false, with_ties: false } }
|
|
594
|
+
},
|
|
595
|
+
|
|
596
|
+
sliceMax(column, n = 1, options = {}) {
|
|
597
|
+
const withTies = options && Object.prototype.hasOwnProperty.call(options, 'withTies') ? options.withTies : false
|
|
598
|
+
if (withTies) throw new Error('sliceMax withTies=true is not supported by bounded exact-N execution')
|
|
599
|
+
return { op: 'slice-max', args: { n, column, desc: true, with_ties: false } }
|
|
600
|
+
},
|
|
601
|
+
|
|
602
|
+
sample(n, { seed = 0 } = {}) {
|
|
603
|
+
const args = { n }
|
|
604
|
+
if (seed !== 0) args.seed = seed
|
|
605
|
+
return { op: 'sample', args }
|
|
606
|
+
},
|
|
607
|
+
|
|
608
|
+
groupAgg(groupBy, aggs, { maxGroups, maxStateBytes, sorted = false } = {}) {
|
|
609
|
+
const args = { group_by: groupBy, aggs }
|
|
610
|
+
if (maxGroups !== undefined) args.max_groups = maxGroups
|
|
611
|
+
if (maxStateBytes !== undefined) args.max_state_bytes = maxStateBytes
|
|
612
|
+
if (sorted) args.sorted = true
|
|
613
|
+
return { op: 'group-agg', args }
|
|
614
|
+
},
|
|
615
|
+
|
|
616
|
+
frequency(columns, { maxValues, maxStateBytes, mode, approx, overflow, other, audit = false, auditLimit, auditIncludeRow, auditColumns, auditRedact, auditHashColumns, auditMaxBytes, auditMaxCellBytes } = {}) {
|
|
617
|
+
const args = {}
|
|
618
|
+
if (columns) args.columns = columns
|
|
619
|
+
if (maxValues !== undefined) args.max_values = maxValues
|
|
620
|
+
if (maxStateBytes !== undefined) args.max_state_bytes = maxStateBytes
|
|
621
|
+
if (mode !== undefined) args.mode = mode
|
|
622
|
+
if (approx !== undefined) args.approx = !!approx
|
|
623
|
+
if (overflow !== undefined) args.overflow = overflow
|
|
624
|
+
if (other !== undefined) args.other = other
|
|
625
|
+
if (audit) args.audit = true
|
|
626
|
+
if (auditLimit !== undefined) args.audit_limit = auditLimit
|
|
627
|
+
if (auditIncludeRow !== undefined) args.audit_include_row = !!auditIncludeRow
|
|
628
|
+
if (auditColumns !== undefined) args.audit_columns = auditColumns
|
|
629
|
+
if (auditRedact !== undefined) args.audit_redact = auditRedact
|
|
630
|
+
if (auditHashColumns !== undefined) args.audit_hash_columns = auditHashColumns
|
|
631
|
+
if (auditMaxBytes !== undefined) args.audit_max_bytes = Number(auditMaxBytes)
|
|
632
|
+
if (auditMaxCellBytes !== undefined) args.audit_max_cell_bytes = Number(auditMaxCellBytes)
|
|
633
|
+
return { op: 'frequency', args }
|
|
634
|
+
},
|
|
635
|
+
|
|
636
|
+
onehot(column, { drop = false, categories, maxCategories, unknown, maxStateBytes } = {}) {
|
|
637
|
+
const args = { column }
|
|
638
|
+
if (drop) args.drop = true
|
|
639
|
+
if (categories !== undefined) args.categories = categories
|
|
640
|
+
if (maxCategories !== undefined) args.max_categories = maxCategories
|
|
641
|
+
if (maxStateBytes !== undefined) args.max_state_bytes = maxStateBytes
|
|
642
|
+
if (unknown !== undefined) args.unknown = unknown
|
|
643
|
+
return { op: 'onehot', args }
|
|
644
|
+
},
|
|
645
|
+
|
|
646
|
+
labelEncode(column, { result, categories, maxCategories, unknown, maxStateBytes } = {}) {
|
|
647
|
+
const args = { column }
|
|
648
|
+
if (result) args.result = result
|
|
649
|
+
if (categories !== undefined) args.categories = categories
|
|
650
|
+
if (maxCategories !== undefined) args.max_categories = maxCategories
|
|
651
|
+
if (maxStateBytes !== undefined) args.max_state_bytes = maxStateBytes
|
|
652
|
+
if (unknown !== undefined) args.unknown = unknown
|
|
653
|
+
return { op: 'label-encode', args }
|
|
654
|
+
},
|
|
655
|
+
|
|
656
|
+
datetime(column, extractOrOptions, options = {}) {
|
|
657
|
+
const args = { column }
|
|
658
|
+
let opts = options || {}
|
|
659
|
+
if (Array.isArray(extractOrOptions) || typeof extractOrOptions === 'string') {
|
|
660
|
+
args.extract = extractOrOptions
|
|
661
|
+
} else if (extractOrOptions && typeof extractOrOptions === 'object') {
|
|
662
|
+
opts = extractOrOptions
|
|
663
|
+
} else if (extractOrOptions !== undefined && extractOrOptions !== null) {
|
|
664
|
+
args.extract = extractOrOptions
|
|
665
|
+
}
|
|
666
|
+
if (opts.extract !== undefined) args.extract = opts.extract
|
|
667
|
+
if (opts.missing !== undefined) args.missing = opts.missing
|
|
668
|
+
if (opts.onTypeError !== undefined) args.on_type_error = opts.onTypeError
|
|
669
|
+
if (opts.on_type_error !== undefined) args.on_type_error = opts.on_type_error
|
|
670
|
+
return { op: 'datetime', args }
|
|
671
|
+
},
|
|
672
|
+
|
|
673
|
+
reorder(columns) {
|
|
674
|
+
return { op: 'reorder', args: { columns } }
|
|
675
|
+
},
|
|
676
|
+
|
|
677
|
+
dedup(columns, { maxKeys, maxStateBytes, sorted = false, mode, approx = false, bloomBytes, bloomHashes } = {}) {
|
|
678
|
+
const args = {}
|
|
679
|
+
if (columns) args.columns = columns
|
|
680
|
+
if (mode !== undefined) args.mode = mode
|
|
681
|
+
if (approx) args.approx = true
|
|
682
|
+
if (bloomBytes !== undefined) args.bloom_bytes = bloomBytes
|
|
683
|
+
if (bloomHashes !== undefined) args.bloom_hashes = bloomHashes
|
|
684
|
+
if (maxKeys !== undefined) args.max_keys = maxKeys
|
|
685
|
+
if (maxStateBytes !== undefined) args.max_state_bytes = maxStateBytes
|
|
686
|
+
if (sorted) args.sorted = true
|
|
687
|
+
return { op: 'dedup', args }
|
|
688
|
+
},
|
|
689
|
+
|
|
690
|
+
grep(pattern, { invert = false, column = '_line', regex = false } = {}) {
|
|
691
|
+
const args = { pattern }
|
|
692
|
+
if (invert) args.invert = true
|
|
693
|
+
if (column !== '_line') args.column = column
|
|
694
|
+
if (regex) args.regex = true
|
|
695
|
+
return { op: 'grep', args }
|
|
696
|
+
},
|
|
697
|
+
|
|
698
|
+
flatten() {
|
|
699
|
+
return { op: 'flatten', args: {} }
|
|
700
|
+
},
|
|
701
|
+
|
|
702
|
+
jsonExtract(path, result, { column = '_line', type = 'string' } = {}) {
|
|
703
|
+
return { op: 'json-extract', args: { column, path, result, type } }
|
|
704
|
+
},
|
|
705
|
+
|
|
706
|
+
jsonFilter(path, { op = 'exists', value, column = '_line', type = 'auto' } = {}) {
|
|
707
|
+
const args = { column, path, op, type }
|
|
708
|
+
if (value !== undefined) args.value = value
|
|
709
|
+
return { op: 'json-filter', args }
|
|
710
|
+
},
|
|
711
|
+
|
|
712
|
+
jsonSchema(schema, { column = '_line', mode = 'annotate', result = '_valid', audit = false, auditLimit, auditIncludeRow, auditColumns, auditRedact, auditHashColumns, auditMaxBytes, auditMaxCellBytes } = {}) {
|
|
713
|
+
const args = { column, schema, mode, result }
|
|
714
|
+
if (audit) args.audit = true
|
|
715
|
+
if (auditLimit !== undefined) args.audit_limit = auditLimit
|
|
716
|
+
if (auditIncludeRow !== undefined) args.audit_include_row = !!auditIncludeRow
|
|
717
|
+
if (auditColumns !== undefined) args.audit_columns = auditColumns
|
|
718
|
+
if (auditRedact !== undefined) args.audit_redact = auditRedact
|
|
719
|
+
if (auditHashColumns !== undefined) args.audit_hash_columns = auditHashColumns
|
|
720
|
+
if (auditMaxBytes !== undefined) args.audit_max_bytes = Number(auditMaxBytes)
|
|
721
|
+
if (auditMaxCellBytes !== undefined) args.audit_max_cell_bytes = Number(auditMaxCellBytes)
|
|
722
|
+
return { op: 'json-schema', args }
|
|
723
|
+
},
|
|
724
|
+
|
|
725
|
+
jsonFlatten(fields, { column = '_line' } = {}) {
|
|
726
|
+
return { op: 'json-flatten', args: { column, fields } }
|
|
727
|
+
},
|
|
728
|
+
|
|
729
|
+
join(file, on, { how = 'inner', maxLookupRows, maxLookupKeys, maxLookupBytes, maxStateBytes, maxMatchesPerRow, maxOutputRows, sorted = false } = {}) {
|
|
730
|
+
const args = { file, on }
|
|
731
|
+
if (how !== 'inner') args.how = how
|
|
732
|
+
if (maxLookupRows !== undefined) args.max_lookup_rows = maxLookupRows
|
|
733
|
+
if (maxLookupKeys !== undefined) args.max_lookup_keys = maxLookupKeys
|
|
734
|
+
if (maxLookupBytes !== undefined) args.max_lookup_bytes = maxLookupBytes
|
|
735
|
+
if (maxStateBytes !== undefined) args.max_state_bytes = maxStateBytes
|
|
736
|
+
if (maxMatchesPerRow !== undefined) args.max_matches_per_row = maxMatchesPerRow
|
|
737
|
+
if (maxOutputRows !== undefined) args.max_output_rows = maxOutputRows
|
|
738
|
+
if (sorted) args.sorted = true
|
|
739
|
+
return { op: 'join', args }
|
|
740
|
+
},
|
|
741
|
+
|
|
742
|
+
semiJoin(file, on, { maxLookupRows, maxLookupKeys, maxLookupBytes, maxStateBytes, maxOutputRows, sorted = false } = {}) {
|
|
743
|
+
const args = { file, on }
|
|
744
|
+
if (maxLookupRows !== undefined) args.max_lookup_rows = maxLookupRows
|
|
745
|
+
if (maxLookupKeys !== undefined) args.max_lookup_keys = maxLookupKeys
|
|
746
|
+
if (maxLookupBytes !== undefined) args.max_lookup_bytes = maxLookupBytes
|
|
747
|
+
if (maxStateBytes !== undefined) args.max_state_bytes = maxStateBytes
|
|
748
|
+
if (maxOutputRows !== undefined) args.max_output_rows = maxOutputRows
|
|
749
|
+
if (sorted) args.sorted = true
|
|
750
|
+
return { op: 'semi-join', args }
|
|
751
|
+
},
|
|
752
|
+
|
|
753
|
+
antiJoin(file, on, { maxLookupRows, maxLookupKeys, maxLookupBytes, maxStateBytes, maxOutputRows, sorted = false } = {}) {
|
|
754
|
+
const args = { file, on }
|
|
755
|
+
if (maxLookupRows !== undefined) args.max_lookup_rows = maxLookupRows
|
|
756
|
+
if (maxLookupKeys !== undefined) args.max_lookup_keys = maxLookupKeys
|
|
757
|
+
if (maxLookupBytes !== undefined) args.max_lookup_bytes = maxLookupBytes
|
|
758
|
+
if (maxStateBytes !== undefined) args.max_state_bytes = maxStateBytes
|
|
759
|
+
if (maxOutputRows !== undefined) args.max_output_rows = maxOutputRows
|
|
760
|
+
if (sorted) args.sorted = true
|
|
761
|
+
return { op: 'anti-join', args }
|
|
762
|
+
},
|
|
763
|
+
|
|
764
|
+
intersect(file, { columns, maxLookupRows, maxLookupKeys, maxLookupBytes, maxOutputKeys, maxStateBytes, sorted = false } = {}) {
|
|
765
|
+
const args = { file }
|
|
766
|
+
if (columns !== undefined) args.columns = columns
|
|
767
|
+
if (maxLookupRows !== undefined) args.max_lookup_rows = maxLookupRows
|
|
768
|
+
if (maxLookupKeys !== undefined) args.max_lookup_keys = maxLookupKeys
|
|
769
|
+
if (maxLookupBytes !== undefined) args.max_lookup_bytes = maxLookupBytes
|
|
770
|
+
if (maxOutputKeys !== undefined) args.max_output_keys = maxOutputKeys
|
|
771
|
+
if (maxStateBytes !== undefined) args.max_state_bytes = maxStateBytes
|
|
772
|
+
if (sorted) args.sorted = true
|
|
773
|
+
return { op: 'intersect', args }
|
|
774
|
+
},
|
|
775
|
+
|
|
776
|
+
setdiff(file, { columns, maxLookupRows, maxLookupKeys, maxLookupBytes, maxOutputKeys, maxStateBytes, sorted = false } = {}) {
|
|
777
|
+
const args = { file }
|
|
778
|
+
if (columns !== undefined) args.columns = columns
|
|
779
|
+
if (maxLookupRows !== undefined) args.max_lookup_rows = maxLookupRows
|
|
780
|
+
if (maxLookupKeys !== undefined) args.max_lookup_keys = maxLookupKeys
|
|
781
|
+
if (maxLookupBytes !== undefined) args.max_lookup_bytes = maxLookupBytes
|
|
782
|
+
if (maxOutputKeys !== undefined) args.max_output_keys = maxOutputKeys
|
|
783
|
+
if (maxStateBytes !== undefined) args.max_state_bytes = maxStateBytes
|
|
784
|
+
if (sorted) args.sorted = true
|
|
785
|
+
return { op: 'setdiff', args }
|
|
786
|
+
},
|
|
787
|
+
|
|
788
|
+
intersectAll(file, { columns, maxLookupRows, maxLookupKeys, maxLookupBytes, maxStateBytes, sorted = false } = {}) {
|
|
789
|
+
const args = { file }
|
|
790
|
+
if (columns !== undefined) args.columns = columns
|
|
791
|
+
if (maxLookupRows !== undefined) args.max_lookup_rows = maxLookupRows
|
|
792
|
+
if (maxLookupKeys !== undefined) args.max_lookup_keys = maxLookupKeys
|
|
793
|
+
if (maxLookupBytes !== undefined) args.max_lookup_bytes = maxLookupBytes
|
|
794
|
+
if (maxStateBytes !== undefined) args.max_state_bytes = maxStateBytes
|
|
795
|
+
if (sorted) args.sorted = true
|
|
796
|
+
return { op: 'intersect-all', args }
|
|
797
|
+
},
|
|
798
|
+
|
|
799
|
+
setdiffAll(file, { columns, maxLookupRows, maxLookupKeys, maxLookupBytes, maxStateBytes, sorted = false } = {}) {
|
|
800
|
+
const args = { file }
|
|
801
|
+
if (columns !== undefined) args.columns = columns
|
|
802
|
+
if (maxLookupRows !== undefined) args.max_lookup_rows = maxLookupRows
|
|
803
|
+
if (maxLookupKeys !== undefined) args.max_lookup_keys = maxLookupKeys
|
|
804
|
+
if (maxLookupBytes !== undefined) args.max_lookup_bytes = maxLookupBytes
|
|
805
|
+
if (maxStateBytes !== undefined) args.max_state_bytes = maxStateBytes
|
|
806
|
+
if (sorted) args.sorted = true
|
|
807
|
+
return { op: 'setdiff-all', args }
|
|
808
|
+
},
|
|
809
|
+
|
|
810
|
+
union(file, { columns, maxLookupRows, maxLookupBytes, maxOutputKeys, maxStateBytes, sorted = false } = {}) {
|
|
811
|
+
const args = { file }
|
|
812
|
+
if (columns !== undefined) args.columns = columns
|
|
813
|
+
if (maxLookupRows !== undefined) args.max_lookup_rows = maxLookupRows
|
|
814
|
+
if (maxLookupBytes !== undefined) args.max_lookup_bytes = maxLookupBytes
|
|
815
|
+
if (maxOutputKeys !== undefined) args.max_output_keys = maxOutputKeys
|
|
816
|
+
if (maxStateBytes !== undefined) args.max_state_bytes = maxStateBytes
|
|
817
|
+
if (sorted) args.sorted = true
|
|
818
|
+
return { op: 'union', args }
|
|
819
|
+
},
|
|
820
|
+
|
|
821
|
+
unionAll(file, { maxLookupRows, maxLookupBytes } = {}) {
|
|
822
|
+
const args = { file }
|
|
823
|
+
if (maxLookupRows !== undefined) args.max_lookup_rows = maxLookupRows
|
|
824
|
+
if (maxLookupBytes !== undefined) args.max_lookup_bytes = maxLookupBytes
|
|
825
|
+
return { op: 'union-all', args }
|
|
826
|
+
},
|
|
827
|
+
|
|
828
|
+
stack(file, { tag, tagValue } = {}) {
|
|
829
|
+
const args = { file }
|
|
830
|
+
if (tag) args.tag = tag
|
|
831
|
+
if (tagValue) args.tag_value = tagValue
|
|
832
|
+
return { op: 'stack', args }
|
|
833
|
+
},
|
|
834
|
+
|
|
835
|
+
lead(column, { offset = 1, result } = {}) {
|
|
836
|
+
const args = { column }
|
|
837
|
+
if (offset !== 1) args.offset = offset
|
|
838
|
+
if (result) args.result = result
|
|
839
|
+
return { op: 'lead', args }
|
|
840
|
+
},
|
|
841
|
+
|
|
842
|
+
lag(column, { offset = 1, result } = {}) {
|
|
843
|
+
const args = { column }
|
|
844
|
+
if (offset !== 1) args.offset = offset
|
|
845
|
+
if (result) args.result = result
|
|
846
|
+
return { op: 'lag', args }
|
|
847
|
+
},
|
|
848
|
+
|
|
849
|
+
shift(column, { offset = 1, result, type = 'lag' } = {}) {
|
|
850
|
+
const args = { column }
|
|
851
|
+
if (offset !== 1) args.offset = offset
|
|
852
|
+
if (result) args.result = result
|
|
853
|
+
if (type !== 'lag') args.type = type
|
|
854
|
+
return { op: 'shift', args }
|
|
855
|
+
},
|
|
856
|
+
|
|
857
|
+
rowid(columns, { result, sorted = false, maxKeys, maxStateBytes } = {}) {
|
|
858
|
+
const args = {}
|
|
859
|
+
if (columns !== undefined && columns !== null) args.columns = Array.isArray(columns) ? columns : [columns]
|
|
860
|
+
if (result) args.result = result
|
|
861
|
+
if (sorted) args.sorted = true
|
|
862
|
+
if (maxKeys !== undefined) args.max_keys = maxKeys
|
|
863
|
+
if (maxStateBytes !== undefined) args.max_state_bytes = maxStateBytes
|
|
864
|
+
return { op: 'rowid', args }
|
|
865
|
+
},
|
|
866
|
+
|
|
867
|
+
rleid(columns, { result } = {}) {
|
|
868
|
+
const args = { columns: Array.isArray(columns) ? columns : [columns] }
|
|
869
|
+
if (result) args.result = result
|
|
870
|
+
return { op: 'rleid', args }
|
|
871
|
+
},
|
|
872
|
+
|
|
873
|
+
dateTrunc(column, trunc, { result, missing, onTypeError, on_type_error } = {}) {
|
|
874
|
+
const args = { column, trunc }
|
|
875
|
+
if (result) args.result = result
|
|
876
|
+
if (missing !== undefined) args.missing = missing
|
|
877
|
+
if (onTypeError !== undefined) args.on_type_error = onTypeError
|
|
878
|
+
if (on_type_error !== undefined) args.on_type_error = on_type_error
|
|
879
|
+
return { op: 'date-trunc', args }
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
const io = {
|
|
884
|
+
read: {
|
|
885
|
+
file(path) {
|
|
886
|
+
return { op: 'io.read.file', args: { path } }
|
|
887
|
+
}
|
|
888
|
+
},
|
|
889
|
+
write: {
|
|
890
|
+
stdout() {
|
|
891
|
+
return { op: 'io.write.stdout', args: {} }
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
const {
|
|
897
|
+
TranfiTransformError,
|
|
898
|
+
TransformRecipe,
|
|
899
|
+
TransformAnalyzer,
|
|
900
|
+
TransformPlan,
|
|
901
|
+
TransformApply,
|
|
902
|
+
safeTransformLimits
|
|
903
|
+
} = require('./transform.js')
|
|
904
|
+
|
|
905
|
+
module.exports = {
|
|
906
|
+
Pipeline,
|
|
907
|
+
PipelineResult,
|
|
908
|
+
compileDsl,
|
|
909
|
+
compileToSql,
|
|
910
|
+
loadRecipe,
|
|
911
|
+
saveRecipe,
|
|
912
|
+
recipes,
|
|
913
|
+
pipeline,
|
|
914
|
+
param,
|
|
915
|
+
expr,
|
|
916
|
+
codec,
|
|
917
|
+
ops,
|
|
918
|
+
io,
|
|
919
|
+
TranfiTransformError,
|
|
920
|
+
TransformRecipe,
|
|
921
|
+
TransformAnalyzer,
|
|
922
|
+
TransformPlan,
|
|
923
|
+
TransformApply,
|
|
924
|
+
safeTransformLimits
|
|
925
|
+
}
|