databonk 0.0.4 → 0.2.1
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/README.md +491 -96
- package/dist/dataframe-Bz1B7bIr.d.cts +1001 -0
- package/dist/dataframe-Bz1B7bIr.d.ts +1001 -0
- package/dist/index.cjs +5 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +366 -0
- package/dist/index.d.ts +354 -31
- package/dist/index.js +4 -40
- package/dist/index.js.map +1 -1
- package/dist/parallel-fv5h4BkA.d.cts +152 -0
- package/dist/parallel-fv5h4BkA.d.ts +152 -0
- package/dist/parquet.cjs +3 -0
- package/dist/parquet.cjs.map +1 -0
- package/dist/parquet.d.cts +57 -0
- package/dist/parquet.d.ts +57 -0
- package/dist/parquet.js +3 -0
- package/dist/parquet.js.map +1 -0
- package/dist/scalar.wasm +0 -0
- package/dist/simd-threads.wasm +0 -0
- package/dist/simd.wasm +0 -0
- package/dist/workers.cjs +102 -0
- package/dist/workers.cjs.map +1 -0
- package/dist/workers.d.cts +74 -0
- package/dist/workers.d.ts +74 -0
- package/dist/workers.js +102 -0
- package/dist/workers.js.map +1 -0
- package/package.json +93 -32
- package/build/release.d.ts +0 -719
- package/build/release.js +0 -774
- package/build/release.wasm +0 -0
- package/build/release.wasm.map +0 -1
- package/build/release.wat +0 -22633
- package/dist/dataframe.d.ts +0 -82
- package/dist/dataframe.d.ts.map +0 -1
- package/dist/dataframe.js +0 -318
- package/dist/dataframe.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/loader.d.ts +0 -86
- package/dist/loader.d.ts.map +0 -1
- package/dist/loader.js +0 -147
- package/dist/loader.js.map +0 -1
- package/dist/shared-memory.d.ts +0 -64
- package/dist/shared-memory.d.ts.map +0 -1
- package/dist/shared-memory.js +0 -113
- package/dist/shared-memory.js.map +0 -1
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import { D as DType, C as Column, a as Cell, E as Expr, F as FrameView, b as DfRuntime, c as DataFrame, d as FrameOptions } from './dataframe-Bz1B7bIr.cjs';
|
|
2
|
+
export { A as AggName, e as AggOp, f as AggRequest, g as AggSpec, h as ArithOp, B as BoolOp, i as ColumnBuffer, j as ColumnInput, k as ColumnView, l as CompareOp, m as DTYPES, n as DTypeInfo, o as DictUnifyResult, p as Dictionary, q as DtProxy, r as ExprLike, s as ExprNode, t as FrameWasm, G as GroupBy, u as GroupBySource, J as JoinHow, v as JoinOptions, w as JoinSource, K as KernelFn, x as KernelWasm, L as LoadOptions, M as MemoryContext, N as NamedColumn, R as Row, y as RowCursor, S as ScalarValue, z as Schema, H as Series, I as SeriesStrProxy, O as SortOptions, P as StrOp, Q as StrProxy, T as TExpr, U as TypedArrayCtor, V as ViewDType, W as ViewOf, X as WasmExports, Y as WasmMemoryModule, Z as WithColumnOptions, _ as aggResult, $ as callKernel, a0 as col, a1 as columnToArray, a2 as createColumn, a3 as createMemoryContext, a4 as createViewOf, a5 as decodeDictionary, a6 as decodeSlot, a7 as decodeStats, a8 as defaultRuntime, a9 as detectSimd, aa as dtypeInfo, ab as freeColumn, ac as freeDictionary, ad as inferType, ae as init, af as lit, ag as loadRuntime, ah as loadWasmModule, ai as resolve, aj as runtimeFromExports, ak as schemaOf, al as scope, am as sliceColumn, an as toExpr, ao as unifyDictionaries, ap as useRuntime, aq as writeDictionary, ar as writeDictionaryFromRawBytes } from './dataframe-Bz1B7bIr.cjs';
|
|
3
|
+
export { T as ThreadsConfig, a as ThreadsHandle } from './parallel-fv5h4BkA.cjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Arrow validity-bitmap helpers (ABI §4.1): **LSB-first, `1 = valid`, `0 = null`**.
|
|
7
|
+
*
|
|
8
|
+
* A bitmap is `ceil(len / 8)` bytes; element `i` is valid iff
|
|
9
|
+
* `bitmap[i >> 3] & (1 << (i & 7))` is nonzero. Bits past `len` in the final byte
|
|
10
|
+
* are padding and are written `0` (kernels must not depend on them). These helpers
|
|
11
|
+
* operate on a `Uint8Array` view obtained through `viewOf` — never a cached view.
|
|
12
|
+
*
|
|
13
|
+
* NOTE ON SLICES: a sliced column shares its parent's bitmap and reads it at a
|
|
14
|
+
* *bit offset* (`Column.validityBitOffset`). Callers pass `bitOffset + i` here, so
|
|
15
|
+
* these primitives stay offset-agnostic (`i` is an absolute bit index).
|
|
16
|
+
*/
|
|
17
|
+
/** Bytes needed for a `len`-bit validity bitmap: `ceil(len / 8)`. */
|
|
18
|
+
declare function validityBytes(len: number): number;
|
|
19
|
+
/** True iff bit `i` is set (element valid) in an LSB-first bitmap. */
|
|
20
|
+
declare function getBit(bitmap: Uint8Array, i: number): boolean;
|
|
21
|
+
/** Set bit `i` (mark element valid). */
|
|
22
|
+
declare function setBit(bitmap: Uint8Array, i: number): void;
|
|
23
|
+
/** Clear bit `i` (mark element null). */
|
|
24
|
+
declare function clearBit(bitmap: Uint8Array, i: number): void;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Expression-layer errors (Phase 3, P3.1). Spec §4 ergonomics: dtype mismatches
|
|
28
|
+
* name **both** dtypes and the operation; unknown column names suggest the nearest
|
|
29
|
+
* match. All expression-time failures are {@link ExprError} so the frame layer can
|
|
30
|
+
* catch and re-surface them uniformly.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/** Base class for every expression compile/eval error. */
|
|
34
|
+
declare class ExprError extends Error {
|
|
35
|
+
constructor(message: string);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A binary op was handed two dtypes it cannot combine (dtypes.md §3.1: only
|
|
39
|
+
* int→float widening is implicit). Message names both dtypes and the op.
|
|
40
|
+
*/
|
|
41
|
+
declare function dtypeMismatch(op: string, left: DType, right: DType, hint?: string): ExprError;
|
|
42
|
+
/** An op was applied to a dtype it does not support at all (e.g. arithmetic on utf8). */
|
|
43
|
+
declare function unsupportedDtype(op: string, dtype: DType, hint?: string): ExprError;
|
|
44
|
+
/** A cast that is not in the v1 matrix (dtypes.md §2, the ✗ cells). */
|
|
45
|
+
declare function unsupportedCast(from: DType, to: DType): ExprError;
|
|
46
|
+
/** Column `name` was not found; suggest the closest known column if any. */
|
|
47
|
+
declare function unknownColumn(name: string, known: readonly string[]): ExprError;
|
|
48
|
+
/** A literal value's JS type does not match the dtype it must adopt. */
|
|
49
|
+
declare function badLiteral(value: unknown, dtype: DType, op: string): ExprError;
|
|
50
|
+
/** Closest known name to `name` within a small edit distance, else `null`. */
|
|
51
|
+
declare function nearest(name: string, known: readonly string[]): string | null;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Compiler runtime (Phase 3, P3.1 deliverable §3 buffer lifecycle).
|
|
55
|
+
*
|
|
56
|
+
* A {@link Runtime} wraps a {@link FrameView}'s memory context + kernel exports and
|
|
57
|
+
* is the single owner of every **temporary** the compiler allocates. It:
|
|
58
|
+
*
|
|
59
|
+
* - allocates/free's through the arena, tracking live temp pointers so the plan
|
|
60
|
+
* leaves **zero** leaked buffers (verified against the arena high-water / free
|
|
61
|
+
* balance in the leak tests),
|
|
62
|
+
* - dispatches kernels by ABI name (ABI §6) and records an ordered {@link Trace}
|
|
63
|
+
* of kernel calls + allocations so fusion is verifiable by plan inspection,
|
|
64
|
+
* - hands out `viewOf` views (never cached — ADR-001).
|
|
65
|
+
*
|
|
66
|
+
* Ownership model: a pointer is in {@link Runtime.owned} iff the runtime allocated it
|
|
67
|
+
* and has neither freed nor *transferred* it. Source-column buffers are never owned.
|
|
68
|
+
* At the end of a plan the result's buffers are transferred out; everything else is
|
|
69
|
+
* freed.
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
/** Derived, test-friendly counters over a {@link Trace}. */
|
|
73
|
+
interface ExecStats {
|
|
74
|
+
/** Total kernel invocations. */
|
|
75
|
+
readonly kernelCalls: number;
|
|
76
|
+
/** Kernel names in call order. */
|
|
77
|
+
readonly kernels: readonly string[];
|
|
78
|
+
/** Total temp allocations. */
|
|
79
|
+
readonly allocations: number;
|
|
80
|
+
/** Data-buffer allocations only (the elementwise-fusion metric). */
|
|
81
|
+
readonly dataAllocations: number;
|
|
82
|
+
/** Mask-buffer allocations only (the compare→filter fusion metric). */
|
|
83
|
+
readonly maskAllocations: number;
|
|
84
|
+
/** Free calls issued. */
|
|
85
|
+
readonly frees: number;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Expression compiler + executor (Phase 3, P3.1 deliverables §3/§4).
|
|
90
|
+
*
|
|
91
|
+
* `compile(expr, frame)` type-checks (`./dtypes.ts`) then lowers the typed IR to an
|
|
92
|
+
* ordered sequence of Phase-2 kernel calls over the frame's {@link Column}s, and runs
|
|
93
|
+
* it. `compileFilter(predicate, frame)` produces a reusable {@link Selection} for the
|
|
94
|
+
* `df.filter` path.
|
|
95
|
+
*
|
|
96
|
+
* ## Validity handling (dtypes.md §5)
|
|
97
|
+
* Elementwise arithmetic/comparison kernels are data-only; null propagation is a
|
|
98
|
+
* separate `validity_and` / unary copy. Integer `div`/`mod` additionally null out
|
|
99
|
+
* zero-divisor rows (dtypes.md §3.2) via a `divisor != 0` mask AND'd into validity —
|
|
100
|
+
* the data-only kernels cannot express that themselves.
|
|
101
|
+
*
|
|
102
|
+
* ## Fusion (spec P3.1)
|
|
103
|
+
* - **compare → filter**: a comparison lowers straight to a 1-bit mask that `filter`
|
|
104
|
+
* consumes; no bool column is materialised (see {@link compileFilter} /
|
|
105
|
+
* {@link Selection.compact}). One mask, one compaction per column.
|
|
106
|
+
* - **elementwise chains**: an op whose operand is an *owned* temp writes its output
|
|
107
|
+
* **in place** into that buffer, so a linear chain reuses ONE data buffer instead
|
|
108
|
+
* of allocating one per node (see {@link Runtime}).
|
|
109
|
+
*
|
|
110
|
+
* ## Buffer lifecycle
|
|
111
|
+
* Every temporary is owned by the {@link Runtime}; the result's buffers are transferred
|
|
112
|
+
* out (fully owned by the returned {@link Column}) and everything else is freed — no
|
|
113
|
+
* leaks (verified against arena stats in the leak tests).
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
/** Whether a compiled expression yields a column or a single scalar (aggregation). */
|
|
117
|
+
type ResultKind = 'column' | 'scalar';
|
|
118
|
+
/** A scalar (aggregation) result. */
|
|
119
|
+
interface ScalarResult {
|
|
120
|
+
readonly value: Cell;
|
|
121
|
+
readonly dtype: DType;
|
|
122
|
+
}
|
|
123
|
+
/** The outcome of {@link CompiledPlan.execute}. */
|
|
124
|
+
interface PlanResult {
|
|
125
|
+
readonly kind: ResultKind;
|
|
126
|
+
/** Present iff `kind === 'column'`. Caller owns it — free via `freeColumn`. */
|
|
127
|
+
readonly column?: Column;
|
|
128
|
+
/** Present iff `kind === 'scalar'`. */
|
|
129
|
+
readonly scalar?: ScalarResult;
|
|
130
|
+
/** Kernel-call + allocation counters for the run (plan inspection). */
|
|
131
|
+
readonly stats: ExecStats;
|
|
132
|
+
}
|
|
133
|
+
/** A type-checked, ready-to-run expression. */
|
|
134
|
+
interface CompiledPlan {
|
|
135
|
+
/** Result dtype (`'bool'` for predicates; the scalar dtype for aggregations). */
|
|
136
|
+
readonly dtype: DType;
|
|
137
|
+
/** Whether {@link execute} yields a column or a scalar. */
|
|
138
|
+
readonly resultKind: ResultKind;
|
|
139
|
+
/** Run the plan over the bound frame, returning the result + stats. */
|
|
140
|
+
execute(): PlanResult;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Type-check `expr` against `frame` and bind it for execution. Throws
|
|
144
|
+
* {@link ExprError} on any dtype/column error (before running anything).
|
|
145
|
+
*/
|
|
146
|
+
declare function compile(expr: Expr, frame: FrameView): CompiledPlan;
|
|
147
|
+
/**
|
|
148
|
+
* A compiled selection over a frame: the effective row mask plus a `compact` that
|
|
149
|
+
* materialises the kept rows of any column. Fusion (a): a bare comparison predicate
|
|
150
|
+
* lowers to ONE mask; each `compact` is ONE `filter` kernel — no bool column.
|
|
151
|
+
*/
|
|
152
|
+
interface Selection {
|
|
153
|
+
/** Number of selected rows. */
|
|
154
|
+
readonly count: number;
|
|
155
|
+
/** Compact `col` to the selected rows (caller owns the result — `freeColumn`). */
|
|
156
|
+
compact(col: Column): Column;
|
|
157
|
+
/** Release the mask + scratch. Call once after all `compact`s. */
|
|
158
|
+
free(): void;
|
|
159
|
+
/** Live kernel/alloc counters (accumulates across `compact` calls). */
|
|
160
|
+
readonly stats: ExecStats;
|
|
161
|
+
}
|
|
162
|
+
/** A type-checked predicate ready to produce a {@link Selection}. */
|
|
163
|
+
interface CompiledFilter {
|
|
164
|
+
execute(): Selection;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Type-check `predicate` (must be boolean) and bind it as a filter. The `df.filter`
|
|
168
|
+
* path calls `execute()` once, then `compact`s each surviving column.
|
|
169
|
+
*/
|
|
170
|
+
declare function compileFilter(predicate: Expr, frame: FrameView): CompiledFilter;
|
|
171
|
+
|
|
172
|
+
/** Frame-layer errors (spec §4): unknown column suggests the nearest name (shared
|
|
173
|
+
* Levenshtein), dtype mismatch names both dtypes + the op. FrameError extends Error. */
|
|
174
|
+
|
|
175
|
+
declare class FrameError extends Error {
|
|
176
|
+
constructor(message: string);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* RFC-4180 CSV parser with typed column inference.
|
|
181
|
+
*
|
|
182
|
+
* Key features:
|
|
183
|
+
* - Quoted fields, escaped quotes (""), embedded newlines and delimiters.
|
|
184
|
+
* - CRLF and bare LF line endings; lone CR treated as data.
|
|
185
|
+
* - Streaming-friendly internal design: `ChunkParser` is a stateful, chunk-fed
|
|
186
|
+
* parser (feed(s)/finish()). `fromCSV` drives it synchronously over the full text.
|
|
187
|
+
* ReadableStream adapter is a v2 nice-to-have (see ponytail note below).
|
|
188
|
+
*
|
|
189
|
+
* Type inference ladder (applied column-by-column over a sample of up to
|
|
190
|
+
* `INFER_ROWS` rows after null-value stripping):
|
|
191
|
+
*
|
|
192
|
+
* 1. i32 — integer in [-(2^31), 2^31-1], no decimal point, no exponent.
|
|
193
|
+
* 2. i64 — integer text exceeding Number.MAX_SAFE_INTEGER (|x| > 2^53-1, per ADR-009).
|
|
194
|
+
* Promotes when any non-null cell is a valid strict-integer string whose
|
|
195
|
+
* absolute value is above 9_007_199_254_740_991 (2^53−1) but within i64 range.
|
|
196
|
+
* Once promoted, the column stays i64 even if later cells are in safe range.
|
|
197
|
+
* Cells whose BigInt value overflows i64 → utf8 fallback.
|
|
198
|
+
* 3. f64 — any string parseable by `Number()` that is finite (or ±Infinity),
|
|
199
|
+
* i.e. `!isNaN(n)` after trimming.
|
|
200
|
+
* 4. bool — case-insensitive "true" / "false".
|
|
201
|
+
* 5. utf8 — fallback.
|
|
202
|
+
*
|
|
203
|
+
* Explicit dtype overrides (`dtypes` option):
|
|
204
|
+
* - `'i64'` — parse via BigInt(text); throws on non-integer strings.
|
|
205
|
+
* - `'date32'` — parse via strict 'yyyy-MM-dd'; throws on invalid format.
|
|
206
|
+
* - `'timestamp'` — parse via strict ISO-8601 with 'Z' or explicit UTC offset;
|
|
207
|
+
* throws on ambiguous local-time strings (no silent tz guessing).
|
|
208
|
+
*
|
|
209
|
+
* Null values: the `nullValues` option (default `['', 'null', 'NA']`) is
|
|
210
|
+
* checked BEFORE inference. A null-value cell becomes `null` in any dtype column.
|
|
211
|
+
*
|
|
212
|
+
* v2 nice-to-have (not shipped): ReadableStream adapter wrapping ChunkParser.
|
|
213
|
+
* // ponytail: fromCSVStream(stream, opts) → v2 when ReadableStream usage is confirmed
|
|
214
|
+
*/
|
|
215
|
+
|
|
216
|
+
interface FromCsvOptions {
|
|
217
|
+
/** Column delimiter (default: ','). */
|
|
218
|
+
readonly delimiter?: string;
|
|
219
|
+
/** If true (default), treat first row as column headers. */
|
|
220
|
+
readonly header?: boolean;
|
|
221
|
+
/**
|
|
222
|
+
* Override column names (used when header=false, or to rename columns).
|
|
223
|
+
* When header=true, these override the parsed header names.
|
|
224
|
+
*/
|
|
225
|
+
readonly columns?: readonly string[];
|
|
226
|
+
/** Force specific dtypes (column name → dtype). Skips inference for those columns. */
|
|
227
|
+
readonly dtypes?: Readonly<Record<string, DType>>;
|
|
228
|
+
/**
|
|
229
|
+
* Values treated as null (case-sensitive). Default: `['', 'null', 'NA']`.
|
|
230
|
+
* An empty string means the empty field is null (the default for CSV).
|
|
231
|
+
*/
|
|
232
|
+
readonly nullValues?: readonly string[];
|
|
233
|
+
/** Skip this many rows from the top (before header if present). */
|
|
234
|
+
readonly skipRows?: number;
|
|
235
|
+
/** Maximum number of data rows to read (not counting header or skipped rows). */
|
|
236
|
+
readonly maxRows?: number;
|
|
237
|
+
/** Runtime to use. If omitted, uses the default runtime. */
|
|
238
|
+
readonly runtime?: DfRuntime;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Stateful RFC-4180 CSV parser.
|
|
242
|
+
* Feed text chunks with `feed(s)` and call `finish()` to flush the last row.
|
|
243
|
+
* Each completed row is passed to the `onRow` callback.
|
|
244
|
+
*
|
|
245
|
+
* Design: simple state machine over a single `remaining` string. Performance is
|
|
246
|
+
* not critical here (CSV ingestion is I/O-bound); correctness is.
|
|
247
|
+
*/
|
|
248
|
+
declare class ChunkParser {
|
|
249
|
+
private buf;
|
|
250
|
+
private row;
|
|
251
|
+
private field;
|
|
252
|
+
private inQuote;
|
|
253
|
+
private readonly delim;
|
|
254
|
+
private readonly onRow;
|
|
255
|
+
constructor(delimiter: string, onRow: (row: string[]) => void);
|
|
256
|
+
feed(chunk: string): void;
|
|
257
|
+
finish(): void;
|
|
258
|
+
private parse;
|
|
259
|
+
private emitRow;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Parse a CSV string into a DataFrame.
|
|
263
|
+
*
|
|
264
|
+
* @param text - Full CSV text (a chunk-fed path for streaming is internal).
|
|
265
|
+
* @param opts - Parsing and inference options.
|
|
266
|
+
*
|
|
267
|
+
* @throws If there are ragged rows (inconsistent column count) or unterminated quotes.
|
|
268
|
+
*/
|
|
269
|
+
declare function fromCSV(text: string, opts?: FromCsvOptions): DataFrame;
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* JSON I/O thin wrappers.
|
|
273
|
+
*
|
|
274
|
+
* The spec (§4 + §7) asks for fromJSON/toJSON — but DataFrame.fromRecords and
|
|
275
|
+
* df.toRecords() already ARE the JSON path:
|
|
276
|
+
*
|
|
277
|
+
* df.toRecords() → Array<Record<string, Cell>> — serialize with JSON.stringify
|
|
278
|
+
* DataFrame.fromRecords() → DataFrame — parse with JSON.parse first
|
|
279
|
+
*
|
|
280
|
+
* This module exports `fromJSON` and `toJSON` as thin wrappers so callers have a
|
|
281
|
+
* discoverable one-liner, but the parallel implementation is intentionally avoided:
|
|
282
|
+
* these delegates call through to the existing frame-layer implementation (no duplicate
|
|
283
|
+
* column-building code). They add value only in ergonomics, not behavior.
|
|
284
|
+
*
|
|
285
|
+
* fromRecords / toRecords remain the canonical JSON path per the spec.
|
|
286
|
+
*/
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Parse a JSON array-of-records string into a DataFrame.
|
|
290
|
+
* Equivalent to `DataFrame.fromRecords(JSON.parse(json), opts)`.
|
|
291
|
+
*
|
|
292
|
+
* @param json - A JSON string encoding an array of plain objects.
|
|
293
|
+
* @param opts - Forwarded to DataFrame.fromRecords.
|
|
294
|
+
* @throws SyntaxError if `json` is not valid JSON.
|
|
295
|
+
* @throws TypeError if the parsed value is not an array.
|
|
296
|
+
*/
|
|
297
|
+
declare function fromJSON(json: string, opts?: FrameOptions): DataFrame;
|
|
298
|
+
/**
|
|
299
|
+
* Serialize a DataFrame to a compact JSON string (array of record objects).
|
|
300
|
+
* Equivalent to `JSON.stringify(df.toRecords())`.
|
|
301
|
+
*
|
|
302
|
+
* @param df - The DataFrame to serialize.
|
|
303
|
+
* @returns A JSON string. Null cells serialize as JSON `null`.
|
|
304
|
+
*/
|
|
305
|
+
declare function toJSON(df: DataFrame): string;
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Arrow IPC stream encode/decode for databonk DataFrames (ADR-002, ADR-009, ADR-010).
|
|
309
|
+
*
|
|
310
|
+
* Our layout is Arrow-compatible by design:
|
|
311
|
+
* - Numeric columns: contiguous TypedArray → Arrow primitive buffer (zero-transform).
|
|
312
|
+
* - Validity bitmaps: LSB-first, 1=valid — already Arrow format (zero-transform).
|
|
313
|
+
* - utf8 columns: i32 indices + (i32 offsets + u8 bytes) dict → Arrow Dict<Int32, Utf8>.
|
|
314
|
+
* - bool: u8[n] per-element → bit-pack to Arrow's 1-bit-per-element format (one transform).
|
|
315
|
+
* - i64 → Arrow Int(64, signed); date32 → Arrow Date(DAY); timestamp → Arrow Timestamp(MILLI, tz?).
|
|
316
|
+
*
|
|
317
|
+
* IPC stream per message: [int32 -1] [int32 meta_size] [meta bytes, pad→8B] [body bytes, pad→8B]
|
|
318
|
+
* EOS: [int32 -1] [int32 0]
|
|
319
|
+
*
|
|
320
|
+
* FlatBuffers field-index constants — sourced from the Arrow FlatBuffers IDL:
|
|
321
|
+
* Message: version(0), header_type(1), header(2), bodyLength(3)
|
|
322
|
+
* Schema: endianness(0), fields(1)
|
|
323
|
+
* Field: name(0), nullable(1), type_type(2), type(3), dictionary(4), children(5)
|
|
324
|
+
* RecordBatch: length(0), nodes(1), buffers(2)
|
|
325
|
+
* DictionaryBatch: id(0), data(1), isDelta(2)
|
|
326
|
+
* DictionaryEncoding: id(0), indexType(1), isOrdered(2)
|
|
327
|
+
* Int: bitWidth(0), isSigned(1)
|
|
328
|
+
* FloatingPoint: precision(0)
|
|
329
|
+
* Date: unit(0) — DateUnit: DAY=0, MILLISECOND=1 (FlatBuffers default=1)
|
|
330
|
+
* Timestamp: unit(0) — TimeUnit: SECOND=0, MILLISECOND=1, MICROSECOND=2, NANOSECOND=3;
|
|
331
|
+
* timezone(1) — optional IANA tz string
|
|
332
|
+
*
|
|
333
|
+
* MessageHeader union tags: Schema=1, DictionaryBatch=2, RecordBatch=3
|
|
334
|
+
* Type union tags: Int=2, FloatingPoint=3, Utf8=5, Bool=6, Date=8, Timestamp=10, LargeUtf8=20
|
|
335
|
+
* MetadataVersion V5=4
|
|
336
|
+
* FloatingPoint.Precision: HALF=0, SINGLE=1, DOUBLE=2
|
|
337
|
+
*/
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Encode a DataFrame to an Arrow IPC stream (Uint8Array).
|
|
341
|
+
*
|
|
342
|
+
* Stream: Schema message → DictionaryBatch per utf8 column → RecordBatch → EOS.
|
|
343
|
+
* Dictionary-encoded columns use Arrow Dict<Int32, Utf8>; our offsets/bytes
|
|
344
|
+
* buffers pass through directly (ADR-002 "nearly free").
|
|
345
|
+
* Bool columns are repacked from u8 to bit-packed (the ONE real transform).
|
|
346
|
+
*/
|
|
347
|
+
declare function toArrow(df: DataFrame): Uint8Array;
|
|
348
|
+
/**
|
|
349
|
+
* Decode an Arrow IPC stream buffer into a DataFrame.
|
|
350
|
+
*
|
|
351
|
+
* Supported Arrow types: Int32, Int64, UInt32, Float32, Float64, Bool,
|
|
352
|
+
* Dict<Int32, Utf8> (written by our toArrow), plain Utf8 (builds a dict internally),
|
|
353
|
+
* Date32(DAY) (→ date32), Timestamp(any unit, optional tz) (→ timestamp, rescaled to ms).
|
|
354
|
+
* Any other type throws a clear error naming the type tag.
|
|
355
|
+
*/
|
|
356
|
+
declare function fromArrow(buf: Uint8Array, rt: DfRuntime): DataFrame;
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* dataframe — columnar WASM dataframe library
|
|
360
|
+
*/
|
|
361
|
+
|
|
362
|
+
declare const VERSION = "0.2.0";
|
|
363
|
+
/** Returns a greeting string. Placeholder retained for the scaffold smoke test. */
|
|
364
|
+
declare function hello(name?: string): string;
|
|
365
|
+
|
|
366
|
+
export { Cell, ChunkParser, Column, type CompiledFilter, type CompiledPlan, DType, DataFrame, DfRuntime, type ExecStats, Expr, ExprError, FrameError, FrameOptions, FrameView, type FromCsvOptions, type PlanResult, type ResultKind, type ScalarResult, type Selection, VERSION, badLiteral, clearBit, compile, compileFilter, dtypeMismatch, fromArrow, fromCSV, fromJSON, getBit, hello, nearest, setBit, toArrow, toJSON, unknownColumn, unsupportedCast, unsupportedDtype, validityBytes };
|