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
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* op_quarantine.c -- Route matching rows to the errors side channel.
|
|
3
|
+
*
|
|
4
|
+
* Config: {"expr":"col('age') < 0", "name":"rule", "message":"bad row"}
|
|
5
|
+
* Keeps rows where expr is false. Rows where expr is true, or where the
|
|
6
|
+
* predicate cannot be evaluated, are dropped from main and emitted to errors.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#include "internal.h"
|
|
10
|
+
#include "cJSON.h"
|
|
11
|
+
#include <stdio.h>
|
|
12
|
+
#include <stdlib.h>
|
|
13
|
+
#include <string.h>
|
|
14
|
+
|
|
15
|
+
#ifndef HAVE_STRDUP
|
|
16
|
+
extern char *strdup(const char *);
|
|
17
|
+
#endif
|
|
18
|
+
|
|
19
|
+
typedef struct {
|
|
20
|
+
tf_expr *expr;
|
|
21
|
+
char *expr_text;
|
|
22
|
+
char *name;
|
|
23
|
+
char *message;
|
|
24
|
+
size_t row_index;
|
|
25
|
+
size_t checked_rows;
|
|
26
|
+
size_t kept_rows;
|
|
27
|
+
size_t quarantined_rows;
|
|
28
|
+
tf_audit_options audit_opts;
|
|
29
|
+
} quarantine_state;
|
|
30
|
+
|
|
31
|
+
static int emit_quarantine_record(quarantine_state *st, const tf_batch *b, size_t row,
|
|
32
|
+
tf_side_channels *side, const char *reason) {
|
|
33
|
+
if (!side || !side->errors) return TF_OK;
|
|
34
|
+
cJSON *obj = cJSON_CreateObject();
|
|
35
|
+
if (!obj) return TF_ERROR;
|
|
36
|
+
int rc = TF_ERROR;
|
|
37
|
+
if (tf_json_add_string(obj, "type", "quarantine") != TF_OK ||
|
|
38
|
+
tf_json_add_string(obj, "op", "quarantine") != TF_OK ||
|
|
39
|
+
tf_json_add_string(obj, "event", "row_quarantined") != TF_OK ||
|
|
40
|
+
tf_json_add_string(obj, "reason", reason ? reason : "predicate_true") != TF_OK ||
|
|
41
|
+
tf_json_add_string(obj, "severity", "error") != TF_OK ||
|
|
42
|
+
tf_json_add_string(obj, "name", st->name ? st->name : "quarantine") != TF_OK ||
|
|
43
|
+
tf_json_add_string(obj, "expr", st->expr_text ? st->expr_text : "") != TF_OK ||
|
|
44
|
+
tf_json_add_number(obj, "row", (double)st->row_index) != TF_OK) {
|
|
45
|
+
goto done;
|
|
46
|
+
}
|
|
47
|
+
if (st->message && st->message[0] &&
|
|
48
|
+
tf_json_add_string(obj, "message", st->message) != TF_OK) {
|
|
49
|
+
goto done;
|
|
50
|
+
}
|
|
51
|
+
cJSON *row_obj = tf_audit_row_to_json(b, row, &st->audit_opts);
|
|
52
|
+
if (row_obj) {
|
|
53
|
+
if (tf_json_add_item(obj, "data", row_obj) != TF_OK) goto done;
|
|
54
|
+
} else if (st->audit_opts.include_row) {
|
|
55
|
+
goto done;
|
|
56
|
+
}
|
|
57
|
+
rc = tf_buffer_write_json_line(side->errors, obj);
|
|
58
|
+
done:
|
|
59
|
+
cJSON_Delete(obj);
|
|
60
|
+
return rc;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static int quarantine_process(tf_step *self, tf_batch *in, tf_batch **out,
|
|
64
|
+
tf_side_channels *side) {
|
|
65
|
+
quarantine_state *st = self->state;
|
|
66
|
+
*out = NULL;
|
|
67
|
+
|
|
68
|
+
tf_batch *ob = tf_batch_create(in->n_cols, in->n_rows > 0 ? in->n_rows : 1);
|
|
69
|
+
if (!ob) return TF_ERROR;
|
|
70
|
+
if (tf_batch_clone_schema(ob, in) != TF_OK) { tf_batch_free(ob); return TF_ERROR; }
|
|
71
|
+
|
|
72
|
+
size_t out_row = 0;
|
|
73
|
+
for (size_t r = 0; r < in->n_rows; r++) {
|
|
74
|
+
st->row_index++;
|
|
75
|
+
st->checked_rows++;
|
|
76
|
+
bool should_quarantine = false;
|
|
77
|
+
int eval_ok = tf_expr_eval(st->expr, in, r, &should_quarantine) == TF_OK;
|
|
78
|
+
if (!eval_ok || should_quarantine) {
|
|
79
|
+
st->quarantined_rows++;
|
|
80
|
+
if (emit_quarantine_record(st, in, r, side, eval_ok ? "predicate_true" : "predicate_error") != TF_OK) {
|
|
81
|
+
tf_batch_free(ob);
|
|
82
|
+
return TF_ERROR;
|
|
83
|
+
}
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (tf_batch_copy_row(ob, out_row, in, r) != TF_OK) {
|
|
88
|
+
tf_batch_free(ob);
|
|
89
|
+
return TF_ERROR;
|
|
90
|
+
}
|
|
91
|
+
if (tf_batch_expose_row(ob, out_row) != TF_OK) {
|
|
92
|
+
tf_batch_free(ob);
|
|
93
|
+
return TF_ERROR;
|
|
94
|
+
}
|
|
95
|
+
out_row++;
|
|
96
|
+
st->kept_rows++;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (out_row > 0 || in->n_rows == 0) *out = ob;
|
|
100
|
+
else tf_batch_free(ob);
|
|
101
|
+
return TF_OK;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
static int quarantine_flush(tf_step *self, tf_batch **out, tf_side_channels *side) {
|
|
105
|
+
(void)self; (void)side;
|
|
106
|
+
*out = NULL;
|
|
107
|
+
return TF_OK;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
static int quarantine_append_stats(tf_step *self, tf_buffer *out) {
|
|
111
|
+
if (!self || !self->state || !out) return TF_ERROR;
|
|
112
|
+
quarantine_state *st = self->state;
|
|
113
|
+
char buf[192];
|
|
114
|
+
snprintf(buf, sizeof(buf),
|
|
115
|
+
",\"checked_rows\":%zu,\"kept_rows\":%zu,\"quarantined_rows\":%zu",
|
|
116
|
+
st->checked_rows, st->kept_rows, st->quarantined_rows);
|
|
117
|
+
return tf_buffer_write_str(out, buf);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
static void quarantine_destroy(tf_step *self) {
|
|
121
|
+
if (!self) return;
|
|
122
|
+
quarantine_state *st = self->state;
|
|
123
|
+
if (st) {
|
|
124
|
+
tf_expr_free(st->expr);
|
|
125
|
+
free(st->expr_text);
|
|
126
|
+
free(st->name);
|
|
127
|
+
free(st->message);
|
|
128
|
+
tf_audit_options_free(&st->audit_opts);
|
|
129
|
+
free(st);
|
|
130
|
+
}
|
|
131
|
+
free(self);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
tf_step *tf_quarantine_create(const cJSON *args) {
|
|
135
|
+
if (!args) return NULL;
|
|
136
|
+
cJSON *expr_json = cJSON_GetObjectItemCaseSensitive(args, "expr");
|
|
137
|
+
if (!cJSON_IsString(expr_json) || !expr_json->valuestring[0]) {
|
|
138
|
+
tf_set_last_error("quarantine: expr is required");
|
|
139
|
+
return NULL;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
tf_expr *expr = tf_expr_parse(expr_json->valuestring);
|
|
143
|
+
if (!expr) return NULL;
|
|
144
|
+
|
|
145
|
+
quarantine_state *st = calloc(1, sizeof(quarantine_state));
|
|
146
|
+
if (!st) { tf_expr_free(expr); return NULL; }
|
|
147
|
+
tf_audit_options_init(&st->audit_opts, 1);
|
|
148
|
+
st->expr = expr;
|
|
149
|
+
st->expr_text = strdup(expr_json->valuestring);
|
|
150
|
+
cJSON *name_json = cJSON_GetObjectItemCaseSensitive(args, "name");
|
|
151
|
+
cJSON *message_json = cJSON_GetObjectItemCaseSensitive(args, "message");
|
|
152
|
+
st->name = strdup(cJSON_IsString(name_json) && name_json->valuestring[0] ? name_json->valuestring : "quarantine");
|
|
153
|
+
st->message = strdup(cJSON_IsString(message_json) ? message_json->valuestring : "");
|
|
154
|
+
if (!st->expr_text || !st->name || !st->message) {
|
|
155
|
+
tf_expr_free(expr);
|
|
156
|
+
free(st->expr_text);
|
|
157
|
+
free(st->name);
|
|
158
|
+
free(st->message);
|
|
159
|
+
tf_audit_options_free(&st->audit_opts);
|
|
160
|
+
free(st);
|
|
161
|
+
return NULL;
|
|
162
|
+
}
|
|
163
|
+
if (tf_audit_options_parse(&st->audit_opts, args, "quarantine") != TF_OK) {
|
|
164
|
+
tf_expr_free(expr);
|
|
165
|
+
free(st->expr_text);
|
|
166
|
+
free(st->name);
|
|
167
|
+
free(st->message);
|
|
168
|
+
tf_audit_options_free(&st->audit_opts);
|
|
169
|
+
free(st);
|
|
170
|
+
return NULL;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
tf_step *step = calloc(1, sizeof(tf_step));
|
|
174
|
+
if (!step) {
|
|
175
|
+
tf_expr_free(st->expr);
|
|
176
|
+
free(st->expr_text);
|
|
177
|
+
free(st->name);
|
|
178
|
+
free(st->message);
|
|
179
|
+
tf_audit_options_free(&st->audit_opts);
|
|
180
|
+
free(st);
|
|
181
|
+
return NULL;
|
|
182
|
+
}
|
|
183
|
+
step->process = quarantine_process;
|
|
184
|
+
step->flush = quarantine_flush;
|
|
185
|
+
step->append_stats = quarantine_append_stats;
|
|
186
|
+
step->destroy = quarantine_destroy;
|
|
187
|
+
step->state = st;
|
|
188
|
+
return step;
|
|
189
|
+
}
|