databonk 0.0.4 → 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/README.md +491 -96
- package/dist/dataframe-BggBYXYm.d.cts +886 -0
- package/dist/dataframe-BggBYXYm.d.ts +886 -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
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* enableThreads — opt-in shared-memory parallel mode (ADR-006 / P5.1).
|
|
3
|
+
*
|
|
4
|
+
* Detection:
|
|
5
|
+
* - Browser: requires `crossOriginIsolated === true` (COOP+COEP headers).
|
|
6
|
+
* - Node.js: `SharedArrayBuffer` is always available (no isolation needed).
|
|
7
|
+
* If isolation is absent → console.warn + returns `false`.
|
|
8
|
+
*
|
|
9
|
+
* When enabled:
|
|
10
|
+
* - Loads `simd-threads.wasm` with a SAB-backed `WebAssembly.Memory`.
|
|
11
|
+
* - Calls `__wasm_init_memory()` (if exported) on the main instance to apply
|
|
12
|
+
* any passive data segments. Workers instantiate the same binary with the
|
|
13
|
+
* same shared memory but skip `__wasm_init_memory` — the arena statics are
|
|
14
|
+
* already zero-initialised by wasm's memory-zero guarantee, so re-applying
|
|
15
|
+
* the data section from workers is neither needed nor safe.
|
|
16
|
+
* - Spawns a pool of `workers` (default 4) kernel workers.
|
|
17
|
+
* - Provides parallel chunked dispatch for elementwise and reduction kernels.
|
|
18
|
+
*
|
|
19
|
+
* Allocator invariant (ADR-006):
|
|
20
|
+
* Workers NEVER call alloc/free/realloc. All memory allocation is done by
|
|
21
|
+
* the main thread before dispatching work. This means:
|
|
22
|
+
* • Workers only read from data buffers (reductions) or write to pre-allocated
|
|
23
|
+
* output buffers (elementwise).
|
|
24
|
+
* • There are no data races on the arena state (HEAP_TOP / FREE_HEAD / GENERATION).
|
|
25
|
+
*
|
|
26
|
+
* Bit-exactness note:
|
|
27
|
+
* f64 sum/mean with parallel dispatch is NOT bit-identical to single-thread.
|
|
28
|
+
* Single-thread uses 2-stripe accumulation over all elements; parallel dispatch
|
|
29
|
+
* computes per-chunk partial sums (also 2-striped within each chunk) and then
|
|
30
|
+
* combines them left-to-right. The combination order differs, producing
|
|
31
|
+
* different floating-point rounding. Integer sums are always exact (no FP).
|
|
32
|
+
* This is an ADR-006-scope deviation; results are still IEEE-754 correct and
|
|
33
|
+
* deterministic for a fixed worker count. See docs/threads.md for details.
|
|
34
|
+
*
|
|
35
|
+
* Chunk boundary alignment:
|
|
36
|
+
* All chunk boundaries are multiples of 8 elements so that validity-bitmap byte
|
|
37
|
+
* offsets are integer-aligned. The sub-bitmap pointer for chunk starting at
|
|
38
|
+
* element `s` (a multiple of 8) is `vpPtr + s/8`, which correctly addresses
|
|
39
|
+
* the first byte of that chunk's portion of the Arrow-LSB bitmap.
|
|
40
|
+
*/
|
|
41
|
+
/** Configuration for {@link enableThreads}. */
|
|
42
|
+
interface ThreadsConfig {
|
|
43
|
+
/** Number of kernel workers (default 4). */
|
|
44
|
+
workers?: number;
|
|
45
|
+
/**
|
|
46
|
+
* Directory containing `simd-threads.wasm`.
|
|
47
|
+
* Node: filesystem path. Browser: base URL.
|
|
48
|
+
* Default: resolved relative to the loader module (same as scalar/simd.wasm).
|
|
49
|
+
*/
|
|
50
|
+
wasmDir?: string | URL;
|
|
51
|
+
/** Worker request timeout in ms (default 30 000). 0 = no timeout. */
|
|
52
|
+
timeoutMs?: number;
|
|
53
|
+
/** Initial shared memory pages (64 KiB each; default 16 = 1 MiB). */
|
|
54
|
+
initialPages?: number;
|
|
55
|
+
/** Maximum shared memory pages (default 16384 = 1 GiB). Must match --max-memory in build.sh. */
|
|
56
|
+
maxPages?: number;
|
|
57
|
+
}
|
|
58
|
+
/** Handle returned by a successful {@link enableThreads} call. */
|
|
59
|
+
interface ThreadsHandle {
|
|
60
|
+
/** Always `true` — threads are active. */
|
|
61
|
+
readonly enabled: true;
|
|
62
|
+
/** Number of active worker slots. */
|
|
63
|
+
readonly workers: number;
|
|
64
|
+
/**
|
|
65
|
+
* The SAB-backed shared WebAssembly.Memory used by all workers.
|
|
66
|
+
* Column data for parallel operations must reside in this memory.
|
|
67
|
+
* Use {@link alloc} to allocate buffers here.
|
|
68
|
+
*/
|
|
69
|
+
readonly memory: WebAssembly.Memory;
|
|
70
|
+
/**
|
|
71
|
+
* Allocate `bytes` in the shared memory arena (main-thread-only).
|
|
72
|
+
* Returns a 16-byte-aligned pointer, or throws on OOM.
|
|
73
|
+
* Workers NEVER call alloc — only the main thread does (ADR-006 invariant).
|
|
74
|
+
*/
|
|
75
|
+
alloc(bytes: number): number;
|
|
76
|
+
/** Free a pointer previously returned by {@link alloc}. */
|
|
77
|
+
free(ptr: number): void;
|
|
78
|
+
/**
|
|
79
|
+
* Call a kernel function synchronously on the main thread (single-thread path).
|
|
80
|
+
* Useful for correctness comparison: `callKernel('sum_f64_null', ptr, 0, len)`.
|
|
81
|
+
*/
|
|
82
|
+
callKernel(fn: string, ...args: number[]): number;
|
|
83
|
+
/**
|
|
84
|
+
* Parallel f64 sum over elements [0, len). Null lanes (vpPtr ≠ 0) are skipped.
|
|
85
|
+
* Returns the sum of non-null values, or 0 if all null.
|
|
86
|
+
* NOTE: result may differ from single-thread due to FP accumulation order; see
|
|
87
|
+
* docs/threads.md for the formal deviation note.
|
|
88
|
+
*/
|
|
89
|
+
sumF64(dataPtr: number, vpPtr: number, len: number): Promise<number>;
|
|
90
|
+
/**
|
|
91
|
+
* Parallel f64 mean. Returns NaN if len == 0 or all null.
|
|
92
|
+
* Computed as totalSum / totalCount (exact weights via count_null per chunk).
|
|
93
|
+
*/
|
|
94
|
+
meanF64(dataPtr: number, vpPtr: number, len: number): Promise<number>;
|
|
95
|
+
/**
|
|
96
|
+
* Parallel f64 min (NaN-aware, null-skipping).
|
|
97
|
+
* Returns NaN if no valid non-NaN elements exist.
|
|
98
|
+
*/
|
|
99
|
+
minF64(dataPtr: number, vpPtr: number, len: number): Promise<number>;
|
|
100
|
+
/**
|
|
101
|
+
* Parallel f64 max (NaN-aware, null-skipping).
|
|
102
|
+
* Returns NaN if no valid non-NaN elements exist.
|
|
103
|
+
*/
|
|
104
|
+
maxF64(dataPtr: number, vpPtr: number, len: number): Promise<number>;
|
|
105
|
+
/**
|
|
106
|
+
* Parallel elementwise add_f64 over pre-allocated buffers in shared memory.
|
|
107
|
+
* Workers write directly to the shared output buffer (zero-copy).
|
|
108
|
+
*/
|
|
109
|
+
addF64(aPtr: number, bPtr: number, outPtr: number, len: number): Promise<void>;
|
|
110
|
+
/** Parallel elementwise sub_f64 (shared memory). */
|
|
111
|
+
subF64(aPtr: number, bPtr: number, outPtr: number, len: number): Promise<void>;
|
|
112
|
+
/** Parallel elementwise mul_f64 (shared memory). */
|
|
113
|
+
mulF64(aPtr: number, bPtr: number, outPtr: number, len: number): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* Run a generic parallel elementwise binary kernel by name.
|
|
116
|
+
* The kernel must have signature (i32 a, i32 b, i32 out, i32 len) -> ().
|
|
117
|
+
*/
|
|
118
|
+
parallelElementwiseBinary(fn: string, aPtr: number, bPtr: number, outPtr: number, len: number, elemBytes: number): Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* Run a generic parallel reduction kernel by name.
|
|
121
|
+
* The kernel must have signature (i32 data, i32 vp, i32 len) -> <scalar>.
|
|
122
|
+
* Returns an array of per-chunk partial results (caller combines).
|
|
123
|
+
*/
|
|
124
|
+
parallelReduce(fn: string, dataPtr: number, vpPtr: number, len: number, elemBytes: number): Promise<number[]>;
|
|
125
|
+
/** Terminate all workers. The handle must not be used after this. */
|
|
126
|
+
terminate(): void;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Split [0, len) into at most `numWorkers` chunks, each starting at a
|
|
130
|
+
* multiple of 8 elements (for Arrow-LSB validity-bitmap byte alignment).
|
|
131
|
+
* Returns an array of [start, end) pairs.
|
|
132
|
+
*/
|
|
133
|
+
declare function splitChunks(len: number, numWorkers: number): Array<[number, number]>;
|
|
134
|
+
/**
|
|
135
|
+
* Opt-in parallel mode (ADR-006).
|
|
136
|
+
*
|
|
137
|
+
* Returns a {@link ThreadsHandle} when threads are available and enabled,
|
|
138
|
+
* or `false` (with a console.warn) when cross-origin isolation is absent.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```ts
|
|
142
|
+
* const th = await enableThreads({ workers: 4 });
|
|
143
|
+
* if (th) {
|
|
144
|
+
* const sum = await th.sumF64(ptr, vp, len);
|
|
145
|
+
* // ...
|
|
146
|
+
* th.terminate();
|
|
147
|
+
* }
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
declare function enableThreads(config?: ThreadsConfig): Promise<ThreadsHandle | false>;
|
|
151
|
+
|
|
152
|
+
export { type ThreadsConfig as T, type ThreadsHandle as a, enableThreads as e, splitChunks as s };
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* enableThreads — opt-in shared-memory parallel mode (ADR-006 / P5.1).
|
|
3
|
+
*
|
|
4
|
+
* Detection:
|
|
5
|
+
* - Browser: requires `crossOriginIsolated === true` (COOP+COEP headers).
|
|
6
|
+
* - Node.js: `SharedArrayBuffer` is always available (no isolation needed).
|
|
7
|
+
* If isolation is absent → console.warn + returns `false`.
|
|
8
|
+
*
|
|
9
|
+
* When enabled:
|
|
10
|
+
* - Loads `simd-threads.wasm` with a SAB-backed `WebAssembly.Memory`.
|
|
11
|
+
* - Calls `__wasm_init_memory()` (if exported) on the main instance to apply
|
|
12
|
+
* any passive data segments. Workers instantiate the same binary with the
|
|
13
|
+
* same shared memory but skip `__wasm_init_memory` — the arena statics are
|
|
14
|
+
* already zero-initialised by wasm's memory-zero guarantee, so re-applying
|
|
15
|
+
* the data section from workers is neither needed nor safe.
|
|
16
|
+
* - Spawns a pool of `workers` (default 4) kernel workers.
|
|
17
|
+
* - Provides parallel chunked dispatch for elementwise and reduction kernels.
|
|
18
|
+
*
|
|
19
|
+
* Allocator invariant (ADR-006):
|
|
20
|
+
* Workers NEVER call alloc/free/realloc. All memory allocation is done by
|
|
21
|
+
* the main thread before dispatching work. This means:
|
|
22
|
+
* • Workers only read from data buffers (reductions) or write to pre-allocated
|
|
23
|
+
* output buffers (elementwise).
|
|
24
|
+
* • There are no data races on the arena state (HEAP_TOP / FREE_HEAD / GENERATION).
|
|
25
|
+
*
|
|
26
|
+
* Bit-exactness note:
|
|
27
|
+
* f64 sum/mean with parallel dispatch is NOT bit-identical to single-thread.
|
|
28
|
+
* Single-thread uses 2-stripe accumulation over all elements; parallel dispatch
|
|
29
|
+
* computes per-chunk partial sums (also 2-striped within each chunk) and then
|
|
30
|
+
* combines them left-to-right. The combination order differs, producing
|
|
31
|
+
* different floating-point rounding. Integer sums are always exact (no FP).
|
|
32
|
+
* This is an ADR-006-scope deviation; results are still IEEE-754 correct and
|
|
33
|
+
* deterministic for a fixed worker count. See docs/threads.md for details.
|
|
34
|
+
*
|
|
35
|
+
* Chunk boundary alignment:
|
|
36
|
+
* All chunk boundaries are multiples of 8 elements so that validity-bitmap byte
|
|
37
|
+
* offsets are integer-aligned. The sub-bitmap pointer for chunk starting at
|
|
38
|
+
* element `s` (a multiple of 8) is `vpPtr + s/8`, which correctly addresses
|
|
39
|
+
* the first byte of that chunk's portion of the Arrow-LSB bitmap.
|
|
40
|
+
*/
|
|
41
|
+
/** Configuration for {@link enableThreads}. */
|
|
42
|
+
interface ThreadsConfig {
|
|
43
|
+
/** Number of kernel workers (default 4). */
|
|
44
|
+
workers?: number;
|
|
45
|
+
/**
|
|
46
|
+
* Directory containing `simd-threads.wasm`.
|
|
47
|
+
* Node: filesystem path. Browser: base URL.
|
|
48
|
+
* Default: resolved relative to the loader module (same as scalar/simd.wasm).
|
|
49
|
+
*/
|
|
50
|
+
wasmDir?: string | URL;
|
|
51
|
+
/** Worker request timeout in ms (default 30 000). 0 = no timeout. */
|
|
52
|
+
timeoutMs?: number;
|
|
53
|
+
/** Initial shared memory pages (64 KiB each; default 16 = 1 MiB). */
|
|
54
|
+
initialPages?: number;
|
|
55
|
+
/** Maximum shared memory pages (default 16384 = 1 GiB). Must match --max-memory in build.sh. */
|
|
56
|
+
maxPages?: number;
|
|
57
|
+
}
|
|
58
|
+
/** Handle returned by a successful {@link enableThreads} call. */
|
|
59
|
+
interface ThreadsHandle {
|
|
60
|
+
/** Always `true` — threads are active. */
|
|
61
|
+
readonly enabled: true;
|
|
62
|
+
/** Number of active worker slots. */
|
|
63
|
+
readonly workers: number;
|
|
64
|
+
/**
|
|
65
|
+
* The SAB-backed shared WebAssembly.Memory used by all workers.
|
|
66
|
+
* Column data for parallel operations must reside in this memory.
|
|
67
|
+
* Use {@link alloc} to allocate buffers here.
|
|
68
|
+
*/
|
|
69
|
+
readonly memory: WebAssembly.Memory;
|
|
70
|
+
/**
|
|
71
|
+
* Allocate `bytes` in the shared memory arena (main-thread-only).
|
|
72
|
+
* Returns a 16-byte-aligned pointer, or throws on OOM.
|
|
73
|
+
* Workers NEVER call alloc — only the main thread does (ADR-006 invariant).
|
|
74
|
+
*/
|
|
75
|
+
alloc(bytes: number): number;
|
|
76
|
+
/** Free a pointer previously returned by {@link alloc}. */
|
|
77
|
+
free(ptr: number): void;
|
|
78
|
+
/**
|
|
79
|
+
* Call a kernel function synchronously on the main thread (single-thread path).
|
|
80
|
+
* Useful for correctness comparison: `callKernel('sum_f64_null', ptr, 0, len)`.
|
|
81
|
+
*/
|
|
82
|
+
callKernel(fn: string, ...args: number[]): number;
|
|
83
|
+
/**
|
|
84
|
+
* Parallel f64 sum over elements [0, len). Null lanes (vpPtr ≠ 0) are skipped.
|
|
85
|
+
* Returns the sum of non-null values, or 0 if all null.
|
|
86
|
+
* NOTE: result may differ from single-thread due to FP accumulation order; see
|
|
87
|
+
* docs/threads.md for the formal deviation note.
|
|
88
|
+
*/
|
|
89
|
+
sumF64(dataPtr: number, vpPtr: number, len: number): Promise<number>;
|
|
90
|
+
/**
|
|
91
|
+
* Parallel f64 mean. Returns NaN if len == 0 or all null.
|
|
92
|
+
* Computed as totalSum / totalCount (exact weights via count_null per chunk).
|
|
93
|
+
*/
|
|
94
|
+
meanF64(dataPtr: number, vpPtr: number, len: number): Promise<number>;
|
|
95
|
+
/**
|
|
96
|
+
* Parallel f64 min (NaN-aware, null-skipping).
|
|
97
|
+
* Returns NaN if no valid non-NaN elements exist.
|
|
98
|
+
*/
|
|
99
|
+
minF64(dataPtr: number, vpPtr: number, len: number): Promise<number>;
|
|
100
|
+
/**
|
|
101
|
+
* Parallel f64 max (NaN-aware, null-skipping).
|
|
102
|
+
* Returns NaN if no valid non-NaN elements exist.
|
|
103
|
+
*/
|
|
104
|
+
maxF64(dataPtr: number, vpPtr: number, len: number): Promise<number>;
|
|
105
|
+
/**
|
|
106
|
+
* Parallel elementwise add_f64 over pre-allocated buffers in shared memory.
|
|
107
|
+
* Workers write directly to the shared output buffer (zero-copy).
|
|
108
|
+
*/
|
|
109
|
+
addF64(aPtr: number, bPtr: number, outPtr: number, len: number): Promise<void>;
|
|
110
|
+
/** Parallel elementwise sub_f64 (shared memory). */
|
|
111
|
+
subF64(aPtr: number, bPtr: number, outPtr: number, len: number): Promise<void>;
|
|
112
|
+
/** Parallel elementwise mul_f64 (shared memory). */
|
|
113
|
+
mulF64(aPtr: number, bPtr: number, outPtr: number, len: number): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* Run a generic parallel elementwise binary kernel by name.
|
|
116
|
+
* The kernel must have signature (i32 a, i32 b, i32 out, i32 len) -> ().
|
|
117
|
+
*/
|
|
118
|
+
parallelElementwiseBinary(fn: string, aPtr: number, bPtr: number, outPtr: number, len: number, elemBytes: number): Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* Run a generic parallel reduction kernel by name.
|
|
121
|
+
* The kernel must have signature (i32 data, i32 vp, i32 len) -> <scalar>.
|
|
122
|
+
* Returns an array of per-chunk partial results (caller combines).
|
|
123
|
+
*/
|
|
124
|
+
parallelReduce(fn: string, dataPtr: number, vpPtr: number, len: number, elemBytes: number): Promise<number[]>;
|
|
125
|
+
/** Terminate all workers. The handle must not be used after this. */
|
|
126
|
+
terminate(): void;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Split [0, len) into at most `numWorkers` chunks, each starting at a
|
|
130
|
+
* multiple of 8 elements (for Arrow-LSB validity-bitmap byte alignment).
|
|
131
|
+
* Returns an array of [start, end) pairs.
|
|
132
|
+
*/
|
|
133
|
+
declare function splitChunks(len: number, numWorkers: number): Array<[number, number]>;
|
|
134
|
+
/**
|
|
135
|
+
* Opt-in parallel mode (ADR-006).
|
|
136
|
+
*
|
|
137
|
+
* Returns a {@link ThreadsHandle} when threads are available and enabled,
|
|
138
|
+
* or `false` (with a console.warn) when cross-origin isolation is absent.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```ts
|
|
142
|
+
* const th = await enableThreads({ workers: 4 });
|
|
143
|
+
* if (th) {
|
|
144
|
+
* const sum = await th.sumF64(ptr, vp, len);
|
|
145
|
+
* // ...
|
|
146
|
+
* th.terminate();
|
|
147
|
+
* }
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
declare function enableThreads(config?: ThreadsConfig): Promise<ThreadsHandle | false>;
|
|
151
|
+
|
|
152
|
+
export { type ThreadsConfig as T, type ThreadsHandle as a, enableThreads as e, splitChunks as s };
|
package/dist/parquet.cjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
'use strict';var index_js=require('hyparquet/src/index.js'),index_js$1=require('hyparquet-writer/src/index.js');var b={f64:{name:"f64",size:8,view:"f64",ctor:Float64Array,wasm:"f64",float:true},f32:{name:"f32",size:4,view:"f32",ctor:Float32Array,wasm:"f32",float:true},i32:{name:"i32",size:4,view:"i32",ctor:Int32Array,wasm:"i32",float:false},u32:{name:"u32",size:4,view:"u32",ctor:Uint32Array,wasm:"u32",float:false},bool:{name:"bool",size:1,view:"bool",ctor:Uint8Array,wasm:"bool",float:false},utf8:{name:"utf8",size:4,view:"i32",ctor:Int32Array,wasm:"utf8",float:false},i64:{name:"i64",size:8,view:"i64",ctor:BigInt64Array,wasm:"i64",float:false},date32:{name:"date32",size:4,view:"i32",ctor:Int32Array,wasm:"i32",float:false},timestamp:{name:"timestamp",size:8,view:"i64",ctor:BigInt64Array,wasm:"i64",float:false}};function A(t){return t+7>>3}function D(t,e){return (t[e>>3]&1<<(e&7))!==0}function O(t,e){let n=e>>3;t[n]=(t[n]??0)|1<<(e&7);}var Ke=new TextEncoder,Ye=new TextDecoder,ne=new WeakMap;function We(t){let e=ne.get(t);return e===void 0&&(e={slots:new Array(t.count),stats:{hits:0,misses:0}},ne.set(t,e)),e}function Pt(t,e){let n=e.length,r=e.map(u=>Ke.encode(u)),o=0;for(let u of r)o+=u.length;let i=t.mod.alloc((n+1)*4),a=t.mod.alloc(o),s=t.viewOf({ptr:i,length:n+1,dtype:"i32"}),l=t.viewOf({ptr:a,length:o,dtype:"u8"});s[0]=0;let c=0;for(let u=0;u<n;u++){let p=r[u];l.set(p,c),c+=p.length,s[u+1]=c;}return {count:n,offsetsPtr:i,bytesPtr:a,bytesLen:o}}function j(t,e,n){let r=We(e),o=r.slots[n];if(o!==void 0)return r.stats.hits++,o;r.stats.misses++;let i=t.viewOf({ptr:e.offsetsPtr,length:e.count+1,dtype:"i32"}),a=i[n],s=i[n+1],l;if(s<=a)l="";else {let c=t.viewOf({ptr:e.bytesPtr,length:e.bytesLen,dtype:"u8"});l=Ye.decode(c.subarray(a,s));}return r.slots[n]=l,l}function X(t,e){let n=new Array(e.count);for(let r=0;r<e.count;r++)n[r]=j(t,e,r);return n}function re(t,e,n){let r=X(t,e),o=X(t,n),i=[],a=new Map,s=u=>{let p=a.get(u);return p===void 0&&(p=i.length,i.push(u),a.set(u,p)),p},l=new Int32Array(r.length),c=new Int32Array(o.length);for(let u=0;u<r.length;u++)l[u]=s(r[u]);for(let u=0;u<o.length;u++)c[u]=s(o[u]);return {merged:i,remapA:l,remapB:c}}function oe(t,e){t.viewOf.forget({ptr:e.offsetsPtr,length:e.count+1,dtype:"i32"}),t.viewOf.forget({ptr:e.bytesPtr,length:e.bytesLen,dtype:"u8"}),t.mod.free(e.offsetsPtr),t.mod.free(e.bytesPtr);}function W(t){return t==null}function H(t,e,n,r,o,i){return {dtype:t,length:e,dataPtr:n,validityPtr:r,validityBitOffset:0,dict:o,owned:true,...i!==void 0?{tz:i}:{}}}function v(t,e,n,r){return e==="utf8"?Qe(t,n):e==="bool"?Ge(t,n):e==="i64"?Ze(t,n):e==="timestamp"||e==="date32"?Xe(t,e,n,r):Je(t,e,n)}function He(t,e){switch(t){case "f64":return e instanceof Float64Array;case "f32":return e instanceof Float32Array;case "i32":return e instanceof Int32Array;case "u32":return e instanceof Uint32Array;default:return false}}function Je(t,e,n){let r=b[e],o=n.length;if(He(e,n)){let u=t.mod.alloc(o*r.size);return t.viewOf({ptr:u,length:o,dtype:r.view}).set(n),H(e,o,u,0,null)}let i=0;for(let u=0;u<o;u++)W(n[u])&&i++;let a=t.mod.alloc(o*r.size),s=i>0?t.mod.alloc(A(o)):0,l=t.viewOf({ptr:a,length:o,dtype:r.view}),c=null;s!==0&&(c=t.viewOf({ptr:s,length:A(o),dtype:"u8"}),c.fill(0));for(let u=0;u<o;u++){let p=n[u];W(p)?l[u]=0:(l[u]=p,c&&O(c,u));}return H(e,o,a,s,null)}function Ge(t,e){let n=e.length;if(e instanceof Uint8Array){let l=t.mod.alloc(n);return t.viewOf({ptr:l,length:n,dtype:"bool"}).set(e),H("bool",n,l,0,null)}let r=0;for(let l=0;l<n;l++)W(e[l])&&r++;let o=t.mod.alloc(n),i=r>0?t.mod.alloc(A(n)):0,a=t.viewOf({ptr:o,length:n,dtype:"bool"}),s=null;i!==0&&(s=t.viewOf({ptr:i,length:A(n),dtype:"u8"}),s.fill(0));for(let l=0;l<n;l++){let c=e[l];W(c)?a[l]=0:(a[l]=c?1:0,s&&O(s,l));}return H("bool",n,o,i,null)}function Ze(t,e){let n=e.length;if(e instanceof BigInt64Array){let l=t.mod.alloc(n*8);return t.viewOf({ptr:l,length:n,dtype:"i64"}).set(e),H("i64",n,l,0,null)}let r=0;for(let l=0;l<n;l++){let c=e[l];if(W(c)){r++;continue}if(typeof c=="number"){if(!Number.isInteger(c))throw new RangeError(`i64 column: non-integer number ${c} at index ${l} \u2014 use BigInt or null`);if(!Number.isSafeInteger(c))throw new RangeError(`i64 column: unsafe integer ${c} at index ${l} \u2014 use BigInt (e.g. ${c}n)`)}}let o=t.mod.alloc(n*8),i=r>0?t.mod.alloc(A(n)):0,a=t.viewOf({ptr:o,length:n,dtype:"i64"}),s=null;i!==0&&(s=t.viewOf({ptr:i,length:A(n),dtype:"u8"}),s.fill(0));for(let l=0;l<n;l++){let c=e[l];W(c)?a[l]=0n:(a[l]=typeof c=="bigint"?c:BigInt(c),s&&O(s,l));}return H("i64",n,o,i,null)}function Xe(t,e,n,r){let o=e==="timestamp",i=o?8:4,a=n.length,s=o?"i64":"i32";if(o?n instanceof BigInt64Array:n instanceof Int32Array){let m=t.mod.alloc(Math.max(a*i,1));return t.viewOf({ptr:m,length:a,dtype:s}).set(n),H(e,a,m,0,null,r)}let l=0;for(let m=0;m<a;m++)W(n[m])&&l++;let c=t.mod.alloc(Math.max(a*i,1)),u=l>0?t.mod.alloc(A(a)):0,p=t.viewOf({ptr:c,length:a,dtype:s}),f=null;u&&(f=t.viewOf({ptr:u,length:A(a),dtype:"u8"}),f.fill(0));for(let m=0;m<a;m++){let d=n[m];W(d)?p[m]=o?0n:0:(p[m]=o?typeof d=="bigint"?d:BigInt(d):d,f&&O(f,m));}return H(e,a,c,u,null,r)}function Qe(t,e){let n=e.length,r=new Map,o=[],i=new Int32Array(n),a=new Uint8Array(n),s=0;for(let f=0;f<n;f++){let m=e[f];if(W(m))s++,a[f]=1,i[f]=0;else {let d=m,y=r.get(d);y===void 0&&(y=o.length,o.push(d),r.set(d,y)),i[f]=y;}}let l=t.mod.alloc(n*4),c=s>0?t.mod.alloc(A(n)):0,u=Pt(t,o);if(t.viewOf({ptr:l,length:n,dtype:"i32"}).set(i),c!==0){let f=t.viewOf({ptr:c,length:A(n),dtype:"u8"});f.fill(0);for(let m=0;m<n;m++)a[m]===0&&O(f,m);}return H("utf8",n,l,c,u)}function z(t,e){let{length:n,validityPtr:r,validityBitOffset:o}=e,i=r===0?null:t.viewOf({ptr:r,length:A(o+n),dtype:"u8"}),a=new Array(n);if(e.dtype==="utf8"){let u=t.viewOf({ptr:e.dataPtr,length:n,dtype:"i32"}),p=e.dict;for(let f=0;f<n;f++)a[f]=i&&!D(i,o+f)?null:j(t,p,u[f]);return a}if(e.dtype==="i64"||e.dtype==="timestamp"){let u=t.viewOf({ptr:e.dataPtr,length:n,dtype:"i64"});for(let p=0;p<n;p++)a[p]=i&&!D(i,o+p)?null:u[p];return a}if(e.dtype==="date32"){let u=t.viewOf({ptr:e.dataPtr,length:n,dtype:"i32"});for(let p=0;p<n;p++)a[p]=i&&!D(i,o+p)?null:u[p];return a}let s=b[e.dtype],l=t.viewOf({ptr:e.dataPtr,length:n,dtype:s.view}),c=e.dtype==="bool";for(let u=0;u<n;u++)i&&!D(i,o+u)?a[u]=null:a[u]=c?l[u]!==0:l[u];return a}function Vt(t,e,n){let r=Math.max(0,Math.min(e,t.length)),i=Math.max(r,Math.min(n,t.length))-r,a=b[t.dtype].size;return {dtype:t.dtype,length:i,dataPtr:t.dataPtr+r*a,validityPtr:t.validityPtr,validityBitOffset:t.validityBitOffset+r,dict:t.dict,owned:false,...t.tz!==void 0?{tz:t.tz}:{}}}function Q(t,e){if(!e.owned)return;let n=b[e.dtype];t.viewOf.forget({ptr:e.dataPtr,length:e.length,dtype:n.view}),t.mod.free(e.dataPtr),e.validityPtr!==0&&(t.viewOf.forget({ptr:e.validityPtr,length:A(e.validityBitOffset+e.length),dtype:"u8"}),t.mod.free(e.validityPtr)),e.dict!==null&&oe(t,e.dict);}function pt(t){return t instanceof V?t:ie(t)}var V=class t{node;constructor(e){this.node=Object.freeze(e),Object.freeze(this);}add(e){return ct("add",this,e)}sub(e){return ct("sub",this,e)}mul(e){return ct("mul",this,e)}div(e){return ct("div",this,e)}mod(e){return ct("mod",this,e)}neg(){return new t({kind:"neg",operand:this})}gt(e){return rt("gt",this,e)}ge(e){return rt("ge",this,e)}lt(e){return rt("lt",this,e)}le(e){return rt("le",this,e)}eq(e){return rt("eq",this,e)}ne(e){return rt("ne",this,e)}and(e){return new t({kind:"bool",op:"and",left:this,right:pt(e)})}or(e){return new t({kind:"bool",op:"or",left:this,right:pt(e)})}not(){return new t({kind:"not",operand:this})}isNull(){return new t({kind:"isNull",operand:this})}notNull(){return this.isNull().not()}fillNull(e){return new t({kind:"fillNull",operand:this,value:e})}cast(e){return new t({kind:"cast",operand:this,to:e})}sum(){return q("sum",this)}mean(){return q("mean",this)}min(){return q("min",this)}max(){return q("max",this)}count(){return q("count",this)}nunique(){return q("nunique",this)}std(){return q("std",this)}var(){return q("var",this)}first(){return q("first",this)}last(){return q("last",this)}get dt(){return new Nt(this)}toString(){return R(this.node)}},Nt=class{constructor(e){this.operand=e;}operand;year(){return K("year",this.operand)}month(){return K("month",this.operand)}day(){return K("day",this.operand)}hour(){return K("hour",this.operand)}minute(){return K("minute",this.operand)}second(){return K("second",this.operand)}millisecond(){return K("millisecond",this.operand)}weekday(){return K("weekday",this.operand)}dayOfYear(){return K("dayOfYear",this.operand)}quarter(){return K("quarter",this.operand)}};function ie(t,e){return new V({kind:"lit",value:t,dtype:null})}function ct(t,e,n){return new V({kind:"arith",op:t,left:e,right:pt(n)})}function rt(t,e,n){return new V({kind:"compare",op:t,left:e,right:pt(n)})}function q(t,e){return new V({kind:"agg",op:t,operand:e})}function K(t,e){return new V({kind:"dt",component:t,operand:e})}var tn={add:"+",sub:"-",mul:"*",div:"/",mod:"%"};function Ft(t){return typeof t=="string"?JSON.stringify(t):String(t)}function R(t){switch(t.kind){case "col":return `col(${JSON.stringify(t.name)})`;case "lit":return t.dtype?`lit(${Ft(t.value)}, ${t.dtype})`:`lit(${Ft(t.value)})`;case "arith":return `(${R(t.left.node)} ${tn[t.op]} ${R(t.right.node)})`;case "neg":return `(-${R(t.operand.node)})`;case "compare":return `${R(t.left.node)}.${t.op}(${R(t.right.node)})`;case "bool":return `${R(t.left.node)}.${t.op}(${R(t.right.node)})`;case "not":return `${R(t.operand.node)}.not()`;case "isNull":return `${R(t.operand.node)}.isNull()`;case "fillNull":return `${R(t.operand.node)}.fillNull(${Ft(t.value)})`;case "cast":return `${R(t.operand.node)}.cast(${t.to})`;case "agg":return `${R(t.operand.node)}.${t.op}()`;case "dt":return `${R(t.operand.node)}.dt.${t.component}()`}}var S=class extends Error{constructor(e){super(e),this.name="ExprError";}};function tt(t,e,n,r){let o=r?` ${r}`:"";return new S(`dtype mismatch in '${t}': cannot combine ${e} and ${n}.${o}`)}function P(t,e,n){let r=n?` ${n}`:"";return new S(`operation '${t}' is not supported for dtype ${e}.${r}`)}function $t(t,e){return new S(`cast from ${t} to ${e} is not supported in v1`+(t==="utf8"||e==="utf8"?" (numeric\u2194utf8 conversion is not a kernel cast; use CSV inference / toString).":"."))}function Lt(t,e){let n=Et(t,e),r=n?` Did you mean '${n}'?`:"",o=e.length?` Known columns: ${e.map(i=>`'${i}'`).join(", ")}.`:"";return new S(`unknown column '${t}'.${r}${o}`)}function Z(t,e,n){return new S(`literal ${JSON.stringify(t)} is not a valid ${e} value for '${n}'.`)}function Et(t,e){let n=null,r=1/0;for(let i of e){let a=en(t,i);a<r&&(r=a,n=i);}let o=Math.max(2,Math.ceil(t.length/3));return n!==null&&r<=o?n:null}function en(t,e){let n=t.length,r=e.length;if(n===0)return r;if(r===0)return n;let o=new Array(r+1),i=new Array(r+1);for(let a=0;a<=r;a++)o[a]=a;for(let a=1;a<=n;a++){i[0]=a;let s=t.charCodeAt(a-1);for(let l=1;l<=r;l++){let c=s===e.charCodeAt(l-1)?0:1;i[l]=Math.min(o[l]+1,i[l-1]+1,o[l-1]+c);}[o,i]=[i,o];}return o[r]}var nn=new Set(["f64","f32","i32","u32","i64"]),ae=new Set(["i32","u32","i64"]),dt=new Set(["f64","f32"]),ot=new Set(["date32","timestamp"]);function J(t){return nn.has(t)}function Ut(t,e){return Number.isInteger(t)?e==="i32"?t>=-2147483648&&t<=2147483647:t>=0&&t<=4294967295:false}function It(t){let e=t.node;return e.kind==="lit"&&e.dtype===null&&typeof e.value=="number"?e.value:null}function M(t,e){return {kind:"lit",value:t,dtype:e}}function Tt(t,e){return t.dtype===e?t:{kind:"cast",dtype:e,from:t.dtype,operand:t}}function yt(t,e){return E(t,e)}function jt(t,e){return yt(t,e).dtype}function E(t,e){let n=t.node;switch(n.kind){case "col":{let r=e.dtypeOf(n.name);if(r===void 0)throw Lt(n.name,e.columnNames());return {kind:"col",name:n.name,dtype:r}}case "lit":return n.dtype!==null?M(n.value,n.dtype):typeof n.value=="bigint"?M(n.value,"i64"):typeof n.value=="number"?M(n.value,Number.isInteger(n.value)?"i32":"f64"):M(n.value,typeof n.value=="string"?"utf8":"bool");case "arith":return rn(n.op,n.left,n.right,e);case "neg":return ln(n.operand,e);case "compare":return cn(n.op,n.left,n.right,e);case "bool":return mn(n.op,n.left,n.right,e);case "not":return fn(n.operand,e);case "isNull":return {kind:"isNull",dtype:"bool",operand:E(n.operand,e)};case "fillNull":return dn(n.operand,n.value,e);case "cast":return gn(n.operand,n.to,e);case "agg":return wn(n.op,n.operand,e);case "dt":return un(n.component,n.operand,e)}}function rn(t,e,n,r){let o=It(e),i=It(n);if(o!==null&&i!==null){let c=Number.isInteger(o)?"i32":"f64",u=Number.isInteger(i)?"i32":"f64",p=c===u?c:"f64";return {kind:"arith",op:t,dtype:p,left:M(o,p),right:M(i,p)}}if(o!==null||i!==null){let c=o??i,u=E(o!==null?n:e,r),{opDtype:p,colTarget:f}=on(t,c,u.dtype),m=Tt(u,f),d=M(c,p);return {kind:"arith",op:t,dtype:p,left:o!==null?d:m,right:o!==null?m:d}}let a=E(e,r),s=E(n,r),l=an(t,a.dtype,s.dtype);return {kind:"arith",op:t,dtype:l,left:Tt(a,l),right:Tt(s,l)}}function on(t,e,n){if(n==="timestamp")return {opDtype:"timestamp",colTarget:"timestamp"};if(n==="date32")return {opDtype:"date32",colTarget:"date32"};if(!J(n))throw P(t,n,"arithmetic");return dt.has(n)?{opDtype:n,colTarget:n}:n==="i64"?Number.isSafeInteger(e)?{opDtype:"i64",colTarget:"i64"}:{opDtype:"f64",colTarget:"f64"}:Ut(e,n)?{opDtype:n,colTarget:n}:{opDtype:"f64",colTarget:"f64"}}function an(t,e,n){if(ot.has(e)||ot.has(n))return sn(t,e,n);if(!J(e))throw P(t,e,"arithmetic");if(!J(n))throw P(t,n,"arithmetic");if(e===n)return e;if(e==="i64"&&(n==="i32"||n==="u32")||n==="i64"&&(e==="i32"||e==="u32"))return "i64";if(e==="i64"&&dt.has(n)||n==="i64"&&dt.has(e)||(e==="i32"||e==="u32")&&n==="f64"||(n==="i32"||n==="u32")&&e==="f64")return "f64";if((e==="i32"||e==="u32")&&n==="f32"||(n==="i32"||n==="u32")&&e==="f32")return "f32";throw tt(t,e,n,"insert an explicit .cast() (only int\u2192float widening is implicit).")}function sn(t,e,n){if(t==="sub"&&e==="timestamp"&&n==="timestamp")return "i64";if((t==="add"||t==="sub")&&e==="timestamp"&&ae.has(n)||t==="add"&&ae.has(e)&&n==="timestamp")return "timestamp";if(t==="sub"&&e==="date32"&&n==="date32")return "i32";if((t==="add"||t==="sub")&&e==="date32"&&(n==="i32"||n==="u32")||t==="add"&&(e==="i32"||e==="u32")&&n==="date32")return "date32";throw new S(`${t}(${e},${n})`)}function ln(t,e){let n=E(t,e);if(!J(n.dtype))throw P("neg",n.dtype);return {kind:"neg",dtype:n.dtype,operand:n}}function un(t,e,n){let r=E(e,n);if(!ot.has(r.dtype))throw P("dt",r.dtype);return {kind:"dt",component:t,dtype:"i32",operand:r}}function cn(t,e,n,r){let o=t==="eq"||t==="ne",i=mt(e)??mt(n),a=ft(e)??ft(n),s=It(e),l=It(n);if(s!==null&&l!==null){let f=Number.isInteger(s)&&Number.isInteger(l)?"i32":"f64";return et(t,f,M(s,f),M(l,f))}if(s!==null||l!==null){let f=s??l,m=E(s!==null?n:e,r);if(m.dtype==="date32"){let h=M(f,"date32");return et(t,"date32",s!==null?h:m,s!==null?m:h)}if(m.dtype==="timestamp"){let h=M(f,"timestamp");return et(t,"timestamp",s!==null?h:m,s!==null?m:h)}if(!J(m.dtype))throw tt(t,s!==null?"f64":m.dtype,s!==null?m.dtype:"f64","cannot compare a number to a non-numeric column.");let d=pn(f,m.dtype),y=Tt(m,d),w=M(f,d);return et(t,d,s!==null?w:y,s!==null?y:w)}if(i!==null){let f=E(mt(e)!==null?n:e,r);if(f.dtype!=="utf8")throw tt(t,"utf8",f.dtype,"cannot compare a string to a non-utf8 column.");if(!o)throw P(t,"utf8","string ordering");let m=M(i,"utf8");return et(t,"utf8",mt(e)!==null?m:f,mt(e)!==null?f:m)}if(a!==null){let f=E(ft(e)!==null?n:e,r);if(f.dtype!=="bool")throw tt(t,"bool",f.dtype,"cannot compare a boolean to a non-bool column.");if(!o)throw P(t,"bool");let m=M(a,"bool");return et(t,"bool",ft(e)!==null?m:f,ft(e)!==null?f:m)}let c=E(e,r),u=E(n,r);if(c.dtype!==u.dtype)throw tt(t,c.dtype,u.dtype,"cast");let p=c.dtype;if(p==="utf8"||p==="bool")throw P(t,p,"column-vs-column");return et(t,p,c,u)}function et(t,e,n,r){return {kind:"compare",op:t,dtype:"bool",operandDtype:e,left:n,right:r}}function pn(t,e){return dt.has(e)?e:e==="i64"?Number.isSafeInteger(t)?"i64":"f64":Ut(t,e)?e:"f64"}function mt(t){let e=t.node;return e.kind==="lit"&&typeof e.value=="string"?e.value:null}function ft(t){let e=t.node;return e.kind==="lit"&&typeof e.value=="boolean"?e.value:null}function mn(t,e,n,r){let o=E(e,r),i=E(n,r);if(o.dtype!=="bool")throw P(t,o.dtype,"boolean");if(i.dtype!=="bool")throw P(t,i.dtype,"boolean");return {kind:"bool",op:t,dtype:"bool",left:o,right:i}}function fn(t,e){let n=E(t,e);if(n.dtype!=="bool")throw P("not",n.dtype,"boolean");return {kind:"not",dtype:"bool",operand:n}}function dn(t,e,n){let r=E(t,n);return yn(e,r.dtype),{kind:"fillNull",dtype:r.dtype,operand:r,value:e}}function yn(t,e){if(e==="utf8"){if(typeof t!="string")throw Z(t,e,"fillNull");return}if(e==="bool"){if(typeof t!="boolean")throw Z(t,e,"fillNull");return}if(e==="i64"||e==="timestamp"){if(typeof t!="bigint"&&typeof t!="number")throw Z(t,e,"fillNull");if(typeof t=="number"&&!Number.isSafeInteger(t))throw Z(t,e,"fillNull");return}if(typeof t!="number")throw Z(t,e,"fillNull");if((e==="i32"||e==="u32")&&!Ut(t,e))throw Z(t,e,"fillNull")}var hn={f64:new Set(["f64","f32","i32","u32","bool","i64"]),f32:new Set(["f64","f32","i32","u32","bool","i64"]),i32:new Set(["f64","f32","i32","u32","bool","i64","date32"]),u32:new Set(["f64","f32","i32","u32","bool","i64"]),bool:new Set(["f64","f32","i32","u32","bool","i64"]),utf8:new Set(["utf8"]),i64:new Set(["f64","f32","i32","u32","bool","i64","timestamp"]),date32:new Set(["i32","timestamp","date32"]),timestamp:new Set(["i64","date32","timestamp"])};function gn(t,e,n){let r=E(t,n),o=r.dtype;if(!hn[o]?.has(e))throw $t(o,e);return {kind:"cast",dtype:e,from:o,operand:r}}function wn(t,e,n){let r=E(e,n),o=ht(t,r.dtype);return {kind:"agg",op:t,dtype:o,operandDtype:r.dtype,operand:r}}function ht(t,e){switch(t){case "count":return "i32";case "nunique":if(J(e)||e==="utf8"||ot.has(e))return "i32";throw P("nunique",e);case "sum":if(dt.has(e))return e;if(e==="i64")return "i64";if(e==="i32"||e==="u32")return "f64";throw P("sum",e);case "mean":case "std":case "var":if(J(e))return "f64";throw P(t,e);case "min":case "max":if(J(e)||ot.has(e))return e;throw P(t,e);case "first":case "last":if(J(e)||e==="utf8"||ot.has(e))return e;throw P(t,e)}}function se(t,e,n){let r=t[e];if(typeof r!="function")throw new Error(`kernel export not found: ${e}`);return r(...n)}function le(t,e,n){let r=t[e];if(typeof r!="function")throw new Error(`kernel export not found: ${e}`);return r(...n)}function Ot(t){let e=0,n=0;for(let r of t.allocs)r.purpose==="data"?e++:r.purpose==="mask"&&n++;return {kernelCalls:t.kernels.length,kernels:t.kernels.slice(),allocations:t.allocs.length,dataAllocations:e,maskAllocations:n,frees:t.frees}}var gt=class{ctx;wasm;len;owned=new Set;trace={kernels:[],allocs:[],frees:0};viewed=[];constructor(e){this.ctx=e.ctx,this.wasm=e.wasm,this.len=e.length;}get validityBytes(){return A(this.len)}alloc(e,n){let r=this.ctx.mod.alloc(e);if(r===0)throw new Error(`out of wasm memory allocating ${e} bytes`);return this.owned.add(r),this.trace.allocs.push({bytes:e,purpose:n}),r}track(e,n,r){e!==0&&(this.owned.add(e),this.trace.allocs.push({bytes:n,purpose:r}));}free(e){e!==0&&this.owned.delete(e)&&(this.forgetViews(e),this.ctx.mod.free(e),this.trace.frees++);}transfer(e){this.owned.delete(e),this.forgetViews(e);}freeAll(){for(let e of this.viewed)this.ctx.viewOf.forget(e);this.viewed.length=0;for(let e of this.owned)this.ctx.mod.free(e),this.trace.frees++;this.owned.clear();}call(e,...n){return this.trace.kernels.push(e),se(this.wasm,e,n)}callBigInt(e,...n){return this.trace.kernels.push(e),le(this.wasm,e,n)}view(e,n,r){let o={ptr:e,length:n,dtype:r};return this.viewed.push(o),this.ctx.viewOf(o)}forgetViews(e){for(let n=this.viewed.length-1;n>=0;n--){let r=this.viewed[n];r.ptr===e&&(this.ctx.viewOf.forget(r),this.viewed.splice(n,1));}}},_={ptr:0,owns:false};function T(t,e){e.owns&&t.free(e.ptr);}function ue(t,e,n){if(e===0)return _;if((n&7)===0)return {ptr:e+(n>>3),owns:false};let r=t.validityBytes,o=t.alloc(r,"validity"),i=t.view(e,A(n+t.len),"u8"),a=t.view(o,r,"u8");a.fill(0);for(let s=0;s<t.len;s++)D(i,n+s)&&O(a,s);return {ptr:o,owns:true}}function ce(t,e,n){if(n===0)return 0;let r=t.view(e,A(n),"u8"),o=0;for(let i=0;i<n;i++)r[i>>3]>>(i&7)&1&&o++;return o}var zt=86400000n,bn=[0,31,59,90,120,151,181,212,243,273,304,334];function pe(t){let e=t+719468,n=Math.floor(e/146097),r=e-n*146097,o=Math.floor((r-Math.floor(r/1460)+Math.floor(r/36524)-Math.floor(r/146096))/365),i=o+n*400,a=r-(365*o+Math.floor(o/4)-Math.floor(o/100)),s=Math.floor((5*a+2)/153),l=a-Math.floor((153*s+2)/5)+1,c=s<10?s+3:s-9;return {year:i+(c<=2?1:0),month:c,day:l}}function me(t,e,n){let r=t-(e<=2?1:0),o=Math.floor(r/400),i=r-o*400,a=Math.floor((153*(e>2?e-3:e+9)+2)/5)+n-1,s=i*365+Math.floor(i/4)-Math.floor(i/100)+a;return o*146097+s-719468}function xn(t){return t%4===0&&t%100!==0||t%400===0}function Rt(t,e,n){let r=(bn[e-1]??0)+n;return e>2&&xn(t)?r+1:r}function St(t){return ((t+3)%7+7)%7+1}function An(t){let e=t/zt;return t%zt!==0n&&t<0n&&(e-=1n),Number(e)}function fe(t){let{year:e,month:n,day:r}=pe(t);return {year:e,month:n,day:r,hour:0,minute:0,second:0,millisecond:0,weekday:St(t),dayOfYear:Rt(e,n,r),quarter:Math.ceil(n/3)}}function de(t){let e=typeof t=="bigint"?t:BigInt(Math.trunc(t)),n=An(e),r=Number(e-BigInt(n)*zt),{year:o,month:i,day:a}=pe(n),s=Math.floor(r/36e5),l=r%36e5,c=Math.floor(l/6e4),u=l%6e4,p=Math.floor(u/1e3),f=u%1e3;return {year:o,month:i,day:a,hour:s,minute:c,second:p,millisecond:f,weekday:St(n),dayOfYear:Rt(o,i,a),quarter:Math.ceil(i/3)}}var ye=new Map;function vn(t){let e=ye.get(t);if(e!==void 0)return e;let n;try{n=new Intl.DateTimeFormat("en",{timeZone:t,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hourCycle:"h23"});}catch(r){throw new RangeError(`Invalid IANA timezone: "${t}". ${r instanceof Error?r.message:String(r)}`)}return ye.set(t,n),n}function he(t,e){let r=vn(e).formatToParts(t),o=0,i=0,a=0,s=0,l=0,c=0;for(let f of r)switch(f.type){case "year":o=parseInt(f.value,10);break;case "month":i=parseInt(f.value,10);break;case "day":a=parseInt(f.value,10);break;case "hour":s=parseInt(f.value,10);break;case "minute":l=parseInt(f.value,10);break;case "second":c=parseInt(f.value,10);break}let u=(t%1e3+1e3)%1e3,p=me(o,i,a);return {year:o,month:i,day:a,hour:s,minute:l,second:c,millisecond:u,weekday:St(p),dayOfYear:Rt(o,i,a),quarter:Math.ceil(i/3)}}function Dn(t,e){return ((t[e>>3]??0)&1<<(e&7))!==0}function it(t,e,n,r){let o=t.length,i=new Int32Array(o),a=t instanceof Int32Array,s=typeof r=="string"&&r.length>0;for(let l=0;l<o;l++){if(e!==null&&!Dn(e,l))continue;let c;if(a)c=fe(t[l]??0);else if(s){let u=Number(t[l]??0n);c=he(u,r);}else {let u=t[l]??0n;c=de(u);}i[l]=c[n];}return {data:i,validity:e}}function xt(t,e){let n=yt(t,e),r=n.kind==="agg"?"scalar":"column";return {dtype:n.dtype,resultKind:r,execute(){let o=new gt(e);try{if(n.kind==="agg")return {kind:"scalar",scalar:Ht(o,e,n),stats:Ot(o.trace)};let i=U(o,e,n);return {kind:"column",column:ve(o,i),stats:Ot(o.trace)}}finally{o.freeAll();}}}}function Wt(t,e){let n=yt(t,e);if(n.dtype!=="bool")throw new S(`filter predicate must be boolean, got ${n.dtype}. Use a comparison / boolean expression.`);return {execute(){let r=new gt(e),o=qn(r,U(r,e,n)),i;if(o.validity.ptr===0)i=o.maskPtr;else if(o.ownsMask)r.call("validity_and",o.maskPtr,o.validity.ptr,o.maskPtr,r.len),T(r,o.validity),i=o.maskPtr;else {let s=r.alloc(r.validityBytes,"mask");r.call("validity_and",o.maskPtr,o.validity.ptr,s,r.len),T(r,o.validity),i=s;}let a=ce(r,i,r.len);return Cn(r,e,i,a)}}}function Cn(t,e,n,r){let o=null,i=()=>{if(o)return o;let a=new Int32Array(r),s=t.view(n,A(t.len),"u8"),l=0;for(let c=0;c<t.len;c++)s[c>>3]>>(c&7)&1&&(a[l++]=c);return o=a,a};return {count:r,compact(a){let s=b[a.dtype],l=e.ctx.mod.alloc(Math.max(r*s.size,1)),c=t.call(`filter_${Kn(a.dtype)}`,a.dataPtr,n,l,t.len);if(c!==r)throw new Error(`filter count mismatch: kernel ${c}, expected ${r}`);let u=0;if(a.validityPtr!==0){let f=i(),m=t.view(a.validityPtr,A(a.validityBitOffset+t.len),"u8"),d=0,y=A(r),w=e.ctx.mod.alloc(Math.max(y,1)),h=t.view(w,y,"u8");h.fill(0);for(let g=0;g<r;g++)D(m,a.validityBitOffset+f[g])?O(h,g):d++;d===0?(e.ctx.viewOf.forget({ptr:w,length:y,dtype:"u8"}),e.ctx.mod.free(w)):u=w;}let p=a.dict?De(e.ctx,a.dict):null;return {dtype:a.dtype,length:r,dataPtr:l,validityPtr:u,validityBitOffset:0,dict:p,owned:true}},free(){t.freeAll();},get stats(){return Ot(t.trace)}}}var kn={gt:"lt",lt:"gt",ge:"le",le:"ge",eq:"eq",ne:"ne"},Pn=new Set(["add","mul"]),En=new Set(["f64_i32","f64_u32","f64_bool","f32_i32","f32_u32","f32_bool","i32_u32","u32_i32","f64_i64","f32_i64"]),qt=86400000n;function U(t,e,n){switch(n.kind){case "col":return Tn(t,e,n.name,n.dtype);case "lit":return Mt(t,n.value,n.dtype);case "arith":return In(t,e,n);case "neg":return Rn(t,e,n.dtype,n.operand);case "compare":return Sn(t,e,n);case "bool":return Bn(t,e,n.op,n.left,n.right);case "not":return Vn(t,e,n.operand);case "isNull":return Fn(t,e,n.operand);case "fillNull":return Nn(t,e,n.dtype,n.operand,n.value);case "cast":return Un(t,e,n.from,n.dtype,n.operand);case "agg":{let r=Ht(t,e,n);return Mt(t,r.value,n.dtype)}case "dt":return jn(t,e,n.component,n.operand)}}function Tn(t,e,n,r){let o=e.getColumn(n);if(!o)throw new S(`column '${n}' vanished during execution`);let i=ue(t,o.validityPtr,o.validityBitOffset);return r==="bool"?{rep:"boolcol",dataPtr:o.dataPtr,ownsData:false,validity:i}:{rep:"column",dtype:r,dataPtr:o.dataPtr,ownsData:false,validity:i,dict:o.dict,ownsDict:false}}function N(t,e,n){let r=U(t,e,n);if(r.rep!=="column")throw new Error(`internal: expected numeric column, got ${r.rep}`);return r}function wt(t){return t.kind==="lit"||t.kind==="agg"||t.kind==="cast"&&wt(t.operand)}function In(t,e,n){let r=n.dtype,o=wt(n.left),i=wt(n.right);if(o&&i){let l=Mt(t,Y(t,e,n.left),r);return Kt(t,e,n.op,l,Y(t,e,n.right),r)}if(i){let l=N(t,e,n.left);return Kt(t,e,n.op,l,Y(t,e,n.right),r)}if(o){let l=N(t,e,n.right);return On(t,e,n.op,Y(t,e,n.left),l,r)}let a=N(t,e,n.left),s=N(t,e,n.right);return be(t,e,n.op,a,s,r)}function Kt(t,e,n,r,o,i){let a=b[i].size,s=r.ownsData?r.dataPtr:t.alloc(t.len*a,"data");if(o===null||(n==="div"||n==="mod")&&((i==="i32"||i==="u32")&&o===0||i==="i64"&&o===0n))return T(t,r.validity),Jn(t,s,t.len*a),$(i,s,nt(t),null,false);let c=b[i].wasm;if(c==="i64"){let u=typeof o=="bigint"?o:BigInt(o);t.callBigInt(`${n}_i64_scalar`,r.dataPtr,u,s,t.len);}else t.call(`${n}_${c}_scalar`,r.dataPtr,o,s,t.len);return $(i,s,r.validity,null,false)}function On(t,e,n,r,o,i){if(Pn.has(n))return Kt(t,e,n,o,r,i);let a=Mt(t,r,i);return be(t,e,n,a,o,i)}function be(t,e,n,r,o,i){let a=b[i].size,s=(n==="div"||n==="mod")&&(i==="i32"||i==="u32"||i==="i64"),l=_;if(s){let f=t.alloc(t.validityBytes,"mask");i==="i64"?t.callBigInt("ne_i64_scalar_mask",o.dataPtr,0n,f,t.len):t.call(`ne_${i}_scalar_mask`,o.dataPtr,0,f,t.len),l={ptr:f,owns:true};}let c=r.ownsData?r.dataPtr:o.ownsData?o.dataPtr:t.alloc(t.len*a,"data"),u=b[i].wasm;t.call(`${n}_${u}`,r.dataPtr,o.dataPtr,c,t.len),c!==r.dataPtr&&r.ownsData&&t.free(r.dataPtr),c!==o.dataPtr&&o.ownsData&&t.free(o.dataPtr);let p=Yt(t,r.validity,o.validity);return s&&(p=Yt(t,p,l)),$(i,c,p,null,false)}function Rn(t,e,n,r){let o=N(t,e,r),i=b[n].size,a=o.ownsData?o.dataPtr:t.alloc(t.len*i,"data");return t.call(`neg_${n}`,o.dataPtr,a,t.len),$(n,a,o.validity,null,false)}function Sn(t,e,n){let r=n.operandDtype,o=wt(n.left),i=wt(n.right);if(o&&i){let u=Y(t,e,n.left),p=Y(t,e,n.right);return Hn(t,Wn(n.op,u,p))}if(r==="bool")return _n(t,e,n,o);if(r==="utf8")return Mn(t,e,n,o);let a=b[r].wasm,s=t.alloc(t.validityBytes,"mask");if(o||i){let u=N(t,e,o?n.right:n.left),p=Y(t,e,o?n.left:n.right);if(p===null)return T(t,u.validity),t.free(u.ownsData?u.dataPtr:0),t.view(s,t.validityBytes,"u8").fill(0),{rep:"mask",maskPtr:s,ownsMask:true,validity:nt(t)};let f=o?kn[n.op]:n.op;if(a==="i64"){let m=typeof p=="bigint"?p:BigInt(p);t.callBigInt(`${f}_i64_scalar_mask`,u.dataPtr,m,s,t.len);}else t.call(`${f}_${a}_scalar_mask`,u.dataPtr,p,s,t.len);return u.ownsData&&t.free(u.dataPtr),{rep:"mask",maskPtr:s,ownsMask:true,validity:u.validity}}let l=N(t,e,n.left),c=N(t,e,n.right);return t.call(`${n.op}_${a}_mask`,l.dataPtr,c.dataPtr,s,t.len),l.ownsData&&t.free(l.dataPtr),c.ownsData&&t.free(c.dataPtr),{rep:"mask",maskPtr:s,ownsMask:true,validity:Yt(t,l.validity,c.validity)}}function Mn(t,e,n,r){let o=N(t,e,r?n.right:n.left),i=Y(t,e,r?n.left:n.right),a=t.alloc(t.validityBytes,"mask"),s=t.view(a,t.validityBytes,"u8");if(i===null)return s.fill(0),o.ownsData&&t.free(o.dataPtr),T(t,o.validity),o.ownsDict&&bt(e,o.dict),{rep:"mask",maskPtr:a,ownsMask:true,validity:nt(t)};let c=(o.dict?X(e.ctx,o.dict):[]).indexOf(i);return c>=0?t.call(`${n.op}_i32_scalar_mask`,o.dataPtr,c,a,t.len):s.fill(n.op==="ne"?255:0),o.ownsData&&t.free(o.dataPtr),o.ownsDict&&bt(e,o.dict),{rep:"mask",maskPtr:a,ownsMask:true,validity:o.validity}}function _n(t,e,n,r){let o=Y(t,e,r?n.left:n.right),i=at(t,U(t,e,r?n.right:n.left));return (n.op==="eq"?o===false:o===true)?xe(t,i):i}function Bn(t,e,n,r,o){let i=at(t,U(t,e,r)),a=at(t,U(t,e,o)),s=n==="and"?"and_kleene":"or_kleene",l=i.ownsData?i.dataPtr:a.ownsData?a.dataPtr:t.alloc(t.len,"data"),c=i.validity.ptr===0&&a.validity.ptr===0,u;if(c){let p=t.alloc(t.validityBytes,"scratch");t.call(s,i.dataPtr,0,a.dataPtr,0,l,p,t.len),t.free(p),u=_;}else {let p=t.alloc(t.validityBytes,"validity");t.call(s,i.dataPtr,i.validity.ptr,a.dataPtr,a.validity.ptr,l,p,t.len),T(t,i.validity),T(t,a.validity),u={ptr:p,owns:true};}return l!==i.dataPtr&&i.ownsData&&t.free(i.dataPtr),l!==a.dataPtr&&a.ownsData&&t.free(a.dataPtr),{rep:"boolcol",dataPtr:l,ownsData:true,validity:u}}function Vn(t,e,n){return xe(t,at(t,U(t,e,n)))}function xe(t,e){let n=e.ownsData?e.dataPtr:t.alloc(t.len,"data"),r;if(e.validity.ptr===0){let o=t.alloc(t.validityBytes,"scratch");t.call("not_bool",e.dataPtr,0,n,o,t.len),t.free(o),r=_;}else {let o=t.alloc(t.validityBytes,"validity");t.call("not_bool",e.dataPtr,e.validity.ptr,n,o,t.len),T(t,e.validity),r={ptr:o,owns:true};}return n!==e.dataPtr&&e.ownsData&&t.free(e.dataPtr),{rep:"boolcol",dataPtr:n,ownsData:true,validity:r}}function Fn(t,e,n){let r=U(t,e,n),o=Jt(r),i=t.alloc(t.len,"data");return t.call("is_null",o.ptr,i,t.len),Ae(t,e,r),{rep:"boolcol",dataPtr:i,ownsData:true,validity:_}}function Nn(t,e,n,r,o){if(n==="bool")return $n(t,e,r,o);if(n==="utf8")return Ln(t,e,r,o);let i=N(t,e,r);if(i.validity.ptr===0)return i;let a=b[n].size,s=i.ownsData?i.dataPtr:t.alloc(t.len*a,"data"),l=b[n].wasm;if(l==="i64"){let c=typeof o=="bigint"?o:BigInt(o);t.callBigInt("fill_null_i64",i.dataPtr,i.validity.ptr,c,s,t.len);}else t.call(`fill_null_${l}`,i.dataPtr,i.validity.ptr,o,s,t.len);return T(t,i.validity),$(n,s,_,null,false)}function $n(t,e,n,r){let o=at(t,U(t,e,n));if(o.validity.ptr===0)return o;let i=o.ownsData?o.dataPtr:t.alloc(t.len,"data"),a=t.view(o.dataPtr,t.len,"u8"),s=t.view(o.validity.ptr,t.validityBytes,"u8"),l=t.view(i,t.len,"u8"),c=r?1:0;for(let u=0;u<t.len;u++)l[u]=D(s,u)?a[u]:c;return T(t,o.validity),{rep:"boolcol",dataPtr:i,ownsData:true,validity:_}}function Ln(t,e,n,r){let o=N(t,e,n);if(o.validity.ptr===0)return o;let i=o.dict?X(e.ctx,o.dict):[],a=i.indexOf(r),s=o.dict,l=o.ownsDict;a<0&&(a=i.length,s=Pt(e.ctx,[...i,r]),t.track(s.offsetsPtr,(s.count+1)*4,"dict"),t.track(s.bytesPtr,Math.max(s.bytesLen,1),"dict"),o.ownsDict&&bt(e,o.dict),l=true);let c=o.ownsData?o.dataPtr:t.alloc(t.len*4,"data"),u=t.view(o.dataPtr,t.len,"i32"),p=t.view(o.validity.ptr,t.validityBytes,"u8"),f=t.view(c,t.len,"i32");for(let m=0;m<t.len;m++)f[m]=D(p,m)?u[m]:a;return T(t,o.validity),$("utf8",c,_,s,l)}function Un(t,e,n,r,o){let i=U(t,e,o);if(n===r)return i;let a=(i.rep==="boolcol",i.dataPtr),s=(i.rep==="boolcol",i.ownsData),l=Jt(i);if(n==="date32"&&r==="i32"||n==="i32"&&r==="date32"||n==="timestamp"&&r==="i64"||n==="i64"&&r==="timestamp")return {...i,dtype:r};if(n==="date32"&&r==="timestamp"){let d=t.alloc(t.len*8,"data"),y=t.alloc(t.validityBytes,"scratch");return t.call("cast_i32_i64",a,l.ptr,d,y,t.len),t.free(y),t.callBigInt("mul_i64_scalar",d,qt,d,t.len),s&&t.free(a),$("timestamp",d,l,null,false)}if(n==="timestamp"&&r==="date32"){let d=t.view(a,t.len,"i64"),y=t.alloc(t.len*4,"data"),w=t.view(y,t.len,"i32");for(let h=0;h<t.len;h++){let g=d[h],x=g/qt;g%qt!==0n&&g<0n&&(x-=1n),w[h]=Number(x);}return s&&t.free(a),$("date32",y,l,null,false)}let c=b[r].size,p=s&&b[n].size===c?a:t.alloc(t.len*c,"data"),f=En.has(`${n}_${r}`),m;if(f){let d=t.alloc(t.validityBytes,"validity");t.call(`cast_${n}_${r}`,a,l.ptr,p,d,t.len),T(t,l),m={ptr:d,owns:true};}else {let d=t.alloc(t.validityBytes,"scratch");t.call(`cast_${n}_${r}`,a,l.ptr,p,d,t.len),t.free(d),m=l;}return p!==a&&s&&t.free(a),r==="bool"?{rep:"boolcol",dataPtr:p,ownsData:true,validity:m}:$(r,p,m,null,false)}function jn(t,e,n,r){let o=N(t,e,r),i=t.len,a;if(r.kind==="col"){let p=e.getColumn(r.name);p?.tz&&(a=p.tz);}let s=null;o.validity.ptr!==0&&(s=t.view(o.validity.ptr,t.validityBytes,"u8"));let l;if(o.dtype==="date32"){let p=t.view(o.dataPtr,i,"i32");l=it(p,s,n);}else {let p=t.view(o.dataPtr,i,"i64");l=it(p,s,n,a);}let c=t.alloc(i*4,"data");return t.view(c,i,"i32").set(l.data),o.ownsData&&t.free(o.dataPtr),o.ownsDict&&o.dict&&bt(e,o.dict),$("i32",c,o.validity,null,false)}function Ht(t,e,n){let r=U(t,e,n.operand),o=Jt(r),i=r.rep==="mask"?0:(r.rep==="boolcol",r.dataPtr),a=r.rep==="column"?r.dict:null,s=n.operandDtype,l=s==="utf8"?"i32":s,c=t.len,u=o.ptr===0?c:t.call("count_null",o.ptr,c),p=zn(t,e,n.op,s,l,i,o.ptr,c,u,a);return Ae(t,e,r),{value:p,dtype:n.dtype}}function zn(t,e,n,r,o,i,a,s,l,c){let u=r==="utf8"?"i32":b[r].wasm,p=f=>o==="u32"?f>>>0:f;switch(n){case "count":return l;case "nunique":return t.call(`nunique_${u}_null`,i,a,s);case "sum":return u==="i64"?t.callBigInt("sum_i64_null",i,a,s):t.call(`sum_${r}_null`,i,a,s);case "mean":return l>=1?t.call(`mean_${r}_null`,i,a,s):null;case "std":return l>=2?t.call(`std_${r}_null`,i,a,s):null;case "var":return l>=2?t.call(`var_${r}_null`,i,a,s):null;case "min":case "max":return l?u==="i64"?t.callBigInt(`${n}_i64_null`,i,a,s):p(t.call(`${n}_${u}_null`,i,a,s)):null;case "first":case "last":{let f=t.alloc(4,"scratch");t.view(f,1,"i32")[0]=0;let m;u==="i64"?m=t.callBigInt(`${n}_i64_null`,i,a,s,f):m=t.call(`${n}_${u}_null`,i,a,s,f);let d=t.view(f,1,"i32")[0]!==0;return t.free(f),d?u==="i64"?m:r==="utf8"?j(e.ctx,c,m):p(m):null}}}function at(t,e){if(e.rep==="boolcol")return e;if(e.rep==="mask"){let n=t.alloc(t.len,"data");return t.call("expand_mask_bool",e.maskPtr,n,t.len),e.ownsMask&&t.free(e.maskPtr),{rep:"boolcol",dataPtr:n,ownsData:true,validity:e.validity}}throw new Error("internal: expected a boolean value")}function qn(t,e){if(e.rep==="mask")return e;if(e.rep==="boolcol"){let n=t.alloc(t.validityBytes,"mask"),r=t.view(e.dataPtr,t.len,"u8"),o=t.view(n,t.validityBytes,"u8");o.fill(0);for(let i=0;i<t.len;i++)r[i]&&O(o,i);return e.ownsData&&t.free(e.dataPtr),{rep:"mask",maskPtr:n,ownsMask:true,validity:e.validity}}throw new Error("internal: expected a boolean value")}function Jt(t){return t.validity}function Kn(t){return t==="bool"?"u8":t==="utf8"?"i32":b[t].wasm}function Y(t,e,n){if(n.kind==="lit")return n.dtype==="i64"&&typeof n.value=="number"?BigInt(n.value):n.value;if(n.kind==="agg")return Ht(t,e,n).value;if(n.kind==="cast")return Yn(Y(t,e,n.operand),n.from,n.dtype);throw new Error(`internal: ${n.kind} is not a scalar operand`)}var ge=9223372036854776e3;function Yn(t,e,n){if(t===null)return null;if(e===n)return t;if(e==="i64"){let i=t;return n==="f64"?Number(i):n==="f32"?Math.fround(Number(i)):n==="i32"?Number(BigInt.asIntN(32,i)):n==="u32"?Number(BigInt.asUintN(32,i)):n==="bool"?i!==0n:null}if(n==="i64"){if(typeof t=="boolean")return t?1n:0n;let i=t;if(!Number.isFinite(i))return null;let a=Math.trunc(i);return a>=ge||a<-ge?null:BigInt(a)}if(n==="bool")return typeof t=="number"&&Number.isNaN(t)?null:t!==0&&t!==false;let r=typeof t=="boolean"?t?1:0:t;if(n==="f64")return r;if(n==="f32")return Math.fround(r);if(!Number.isFinite(r))return null;let o=Math.trunc(r);return n==="i32"?o>=-2147483648&&o<=2147483647?o:null:r<0?null:o<=4294967295?o:null}function Wn(t,e,n){if(e===null||n===null)return null;let r=e,o=n;switch(t){case "gt":return r>o;case "ge":return r>=o;case "lt":return r<o;case "le":return r<=o;case "eq":return r===o;case "ne":return r!==o}}function Mt(t,e,n){if(n==="utf8")throw new S("broadcasting a utf8 scalar to a column is not supported in P3.1.");if(n==="bool"){let s=t.alloc(t.len,"data");return t.view(s,t.len,"u8").fill(e===null?0:e?1:0),{rep:"boolcol",dataPtr:s,ownsData:true,validity:e===null?nt(t):_}}let r=b[n].size,o=t.alloc(t.len*r,"data");if(n==="i64"||n==="timestamp"){let s=t.view(o,t.len,"i64"),l=e===null?0n:typeof e=="bigint"?e:BigInt(e);for(let c=0;c<t.len;c++)s[c]=l;return $(n,o,e===null?nt(t):_,null,false)}let i=t.view(o,t.len,b[n].view),a=e===null?0:e;for(let s=0;s<t.len;s++)i[s]=a;return $(n,o,e===null?nt(t):_,null,false)}function Hn(t,e){let n=t.alloc(t.validityBytes,"mask");return t.view(n,t.validityBytes,"u8").fill(e===true?255:0),{rep:"mask",maskPtr:n,ownsMask:true,validity:e===null?nt(t):_}}function Yt(t,e,n){if(e.ptr===0&&n.ptr===0)return _;if(n.ptr===0)return e;if(e.ptr===0)return n;let r=t.alloc(t.validityBytes,"validity");return t.call("validity_and",e.ptr,n.ptr,r,t.len),T(t,e),T(t,n),{ptr:r,owns:true}}function nt(t){let e=t.alloc(t.validityBytes,"validity");return t.view(e,t.validityBytes,"u8").fill(0),{ptr:e,owns:true}}function Jn(t,e,n){t.view(e,n,"u8").fill(0);}function $(t,e,n,r,o){return {rep:"column",dtype:t,dataPtr:e,ownsData:true,validity:n,dict:r,ownsDict:o}}function Ae(t,e,n){if(n.rep==="mask"){n.ownsMask&&t.free(n.maskPtr),T(t,n.validity);return}if(n.rep==="boolcol"){n.ownsData&&t.free(n.dataPtr),T(t,n.validity);return}n.ownsData&&t.free(n.dataPtr),T(t,n.validity),n.ownsDict&&bt(e,n.dict);}function bt(t,e){e&&(t.ctx.viewOf.forget({ptr:e.offsetsPtr,length:e.count+1,dtype:"i32"}),t.ctx.viewOf.forget({ptr:e.bytesPtr,length:e.bytesLen,dtype:"u8"}),t.ctx.mod.free(e.offsetsPtr),t.ctx.mod.free(e.bytesPtr));}function ve(t,e){if(e.rep==="mask")return ve(t,at(t,e));let n=t.ctx,r=e.rep==="boolcol"?"bool":e.dtype,o=b[r],i;e.ownsData?(i=e.dataPtr,t.transfer(e.dataPtr)):(i=n.mod.alloc(Math.max(t.len*o.size,1)),we(t,e.dataPtr,i,t.len*o.size));let a=e.validity,s=0;a.ptr!==0&&(a.owns?(s=a.ptr,t.transfer(a.ptr)):(s=n.mod.alloc(Math.max(t.validityBytes,1)),we(t,a.ptr,s,t.validityBytes)));let l=null;return e.rep==="column"&&e.dict&&(e.ownsDict?(l=e.dict,t.transfer(e.dict.offsetsPtr),t.transfer(e.dict.bytesPtr)):l=De(n,e.dict)),{dtype:r,length:t.len,dataPtr:i,validityPtr:s,validityBitOffset:0,dict:l,owned:true}}function we(t,e,n,r){if(r<=0)return;let o=t.view(e,r,"u8");t.view(n,r,"u8").set(o);}function De(t,e){let n=(e.count+1)*4,r=t.mod.alloc(Math.max(n,1)),o=t.mod.alloc(Math.max(e.bytesLen,1));return t.viewOf({ptr:r,length:e.count+1,dtype:"i32"}).set(t.viewOf({ptr:e.offsetsPtr,length:e.count+1,dtype:"i32"})),e.bytesLen>0&&t.viewOf({ptr:o,length:e.bytesLen,dtype:"u8"}).set(t.viewOf({ptr:e.bytesPtr,length:e.bytesLen,dtype:"u8"})),{count:e.count,offsetsPtr:r,bytesPtr:o,bytesLen:e.bytesLen}}var I=class extends Error{constructor(e){super(e),this.name="FrameError";}};function G(t,e){let n=Et(t,e),r=n?` Did you mean '${n}'?`:"",o=e.length?` Available columns: ${e.map(i=>`'${i}'`).join(", ")}.`:"";return new I(`unknown column '${t}'.${r}${o}`)}function Ce(t,e,n,r){let o=r?` ${r}`:"";return new I(`dtype mismatch in '${t}': ${e} vs ${n}.${o}`)}function B(t,e){let n=t[e];if(typeof n!="function")throw new I(`kernel export not found: ${e}`);return n}typeof process<"u"&&process.versions!=null&&process.versions.node!=null;function Gt(){throw new I("no DataFrame runtime is loaded \u2014 call `await init()` first (or pass a runtime).");}var At=class{col;ctx;refs;constructor(e,n){this.ctx=e,this.col=n,this.refs=1;}retain(){return this.refs++,this}release(){this.refs<=0||--this.refs===0&&Q(this.ctx,this.col);}};function Zt(t){if(t instanceof BigInt64Array)return "i64";if(t instanceof Float64Array)return "f64";if(t instanceof Float32Array)return "f32";if(t instanceof Int32Array)return "i32";if(t instanceof Uint32Array)return "u32";if(t instanceof Uint8Array)return "bool";let e=t;for(let n=0;n<e.length;n++){let r=e[n];if(r!=null){if(typeof r=="bigint")return "i64";if(typeof r=="number")return "f64";if(typeof r=="boolean")return "bool";if(typeof r=="string")return "utf8"}}return "f64"}var Gn=new Set(["year","month","day","weekday","dayOfYear","quarter"]),Xt=class{constructor(e){this.series=e;}series;extract(e){let{dtype:n}=this.series;if(n==="date32"){if(!Gn.has(e))throw new TypeError(`dt.${e} is not supported for date32 columns (time-of-day fields are always 0 for date32; use year/month/day/weekday/dayOfYear/quarter, or cast to timestamp first).`)}else if(n!=="timestamp")throw new TypeError(`dt accessor requires a date32 or timestamp column, got ${n}.`);let r=this.series.col,o=this.series.ctx,i=r.length,a=n==="timestamp"&&r.tz?r.tz:void 0,s=null;if(r.validityPtr!==0){let p=r.validityBitOffset,f=Math.ceil((p+i)/8),m=o.viewOf({ptr:r.validityPtr,length:f,dtype:"u8"});if(p===0)s=m;else {let d=new Uint8Array(Math.ceil(i/8));for(let y=0;y<i;y++){let w=p+y;m[w>>3]>>(w&7)&1&&(d[y>>3]|=1<<(y&7));}s=d;}}let l;if(n==="date32"){let p=o.viewOf({ptr:r.dataPtr,length:i,dtype:"i32"});({data:l}=it(p,s,e));}else {let p=o.viewOf({ptr:r.dataPtr,length:i,dtype:"i64"});({data:l}=it(p,s,e,a));}let c=new Array(i);if(s!==null)for(let p=0;p<i;p++){let f=(s[p>>3]??0)>>(p&7)&1;c[p]=f?l[p]??0:null;}else for(let p=0;p<i;p++)c[p]=l[p]??0;let u=v(o,"i32",c);return new vt(o,`${this.series.name}.dt.${e}`,u)}year(){return this.extract("year")}month(){return this.extract("month")}day(){return this.extract("day")}hour(){return this.extract("hour")}minute(){return this.extract("minute")}second(){return this.extract("second")}millisecond(){return this.extract("millisecond")}weekday(){return this.extract("weekday")}dayOfYear(){return this.extract("dayOfYear")}quarter(){return this.extract("quarter")}},vt=class{name;dtype;length;ctx;column;constructor(e,n,r){this.ctx=e,this.name=n,this.dtype=r.dtype,this.length=r.length,this.column=r;}get col(){return this.column}toArray(){return z(this.ctx,this.column)}get(e){return e<0||e>=this.length?null:this.toArray()[e]??null}values(){return this.ctx.viewOf({ptr:this.column.dataPtr,length:this.length,dtype:b[this.dtype].view})}get dt(){if(this.dtype!=="date32"&&this.dtype!=="timestamp")throw new TypeError(`dt accessor requires a date32 or timestamp column, got ${this.dtype}.`);return new Xt(this)}[Symbol.iterator](){return this.toArray()[Symbol.iterator]()}toString(){return `Series '${this.name}' (${this.dtype}, ${this.length} rows)`}};function Pe(t){return t==="bool"?"u8":t==="utf8"?"i32":b[t].wasm}function st(t,e){if(e.validityPtr===0)return {ptr:0,owns:false};let n=e.validityBitOffset;if((n&7)===0)return {ptr:e.validityPtr+(n>>3),owns:false};let r=e.length,o=A(r),i=t.mod.alloc(Math.max(o,1)),a=t.viewOf({ptr:e.validityPtr,length:A(n+r),dtype:"u8"}),s=t.viewOf({ptr:i,length:o,dtype:"u8"});s.fill(0);for(let l=0;l<r;l++)D(a,n+l)&&O(s,l);return {ptr:i,owns:true}}function lt(t,e){e.owns&&e.ptr!==0&&(t.viewOf.forget({ptr:e.ptr,length:1,dtype:"u8"}),t.mod.free(e.ptr));}function Ee(t,e){let n=(e.count+1)*4,r=t.mod.alloc(Math.max(n,1)),o=t.mod.alloc(Math.max(e.bytesLen,1));return t.viewOf({ptr:r,length:e.count+1,dtype:"i32"}).set(t.viewOf({ptr:e.offsetsPtr,length:e.count+1,dtype:"i32"})),e.bytesLen>0&&t.viewOf({ptr:o,length:e.bytesLen,dtype:"u8"}).set(t.viewOf({ptr:e.bytesPtr,length:e.bytesLen,dtype:"u8"})),{count:e.count,offsetsPtr:r,bytesPtr:o,bytesLen:e.bytesLen}}function Te(t,e){return Math.max(e*b[t].size,1)}function Qt(t,e,n,r){let{ctx:o,wasm:i}=t,a=Pe(e.dtype),s=o.mod.alloc(Te(e.dtype,r));B(i,`gather_${a}`)(e.dataPtr,n,r,s);let l=0;if(e.validityPtr!==0){let u=st(o,e),p=A(r),f=o.mod.alloc(Math.max(p,1));o.viewOf({ptr:f,length:Math.max(p,1),dtype:"u8"}).fill(0),B(i,"gather_validity")(u.ptr,n,r,f),lt(o,u),l=f;}let c=e.dict?Ee(o,e.dict):null;return {dtype:e.dtype,length:r,dataPtr:s,validityPtr:l,validityBitOffset:0,dict:c,owned:true}}function Ie(t,e,n){let{ctx:r,wasm:o}=t,i=e.length>0?e[0].length:0,a=r.mod.alloc(Math.max(i*4,1)),s=r.viewOf({ptr:a,length:i,dtype:"i32"});for(let u=0;u<i;u++)s[u]=u;let l=B(o,"argsort_i32").length>=6,c=l?r.mod.alloc(Math.max(i*4,1)):0;try{for(let u=e.length-1;u>=0;u--)Zn(t,e[u],n[u]===!0,a,i,c,l);}finally{c!==0&&(r.viewOf.forget({ptr:c,length:i,dtype:"i32"}),r.mod.free(c));}return {ptr:a,len:i}}function te(t,e,n,r,o,i,a,s,l){let c=B(t,e);l?c(n,r,o,i,a,s):c(n,r,o,i,a);}function Zn(t,e,n,r,o,i,a){let{ctx:s,wasm:l}=t,c=n?1:0,u=st(s,e);try{if(e.dtype==="utf8"){let p=Xn(t,e,o);try{te(l,"argsort_i32",p,u.ptr,r,o,c,i,a);}finally{s.viewOf.forget({ptr:p,length:o,dtype:"i32"}),s.mod.free(p);}}else if(e.dtype==="bool"){let p=Qn(t,e,o);try{te(l,"argsort_i32",p,u.ptr,r,o,c,i,a);}finally{s.viewOf.forget({ptr:p,length:o,dtype:"i32"}),s.mod.free(p);}}else {let p=b[e.dtype].wasm;te(l,`argsort_${p}`,e.dataPtr,u.ptr,r,o,c,i,a);}}finally{lt(s,u);}}function Xn(t,e,n){let{ctx:r}=t,o=e.dict?X(r,e.dict):[],i=o.map((u,p)=>p).sort((u,p)=>{let f=o[u],m=o[p];return f<m?-1:f>m?1:0}),a=new Int32Array(o.length);for(let u=0;u<i.length;u++)a[i[u]]=u;let s=r.mod.alloc(Math.max(n*4,1)),l=r.viewOf({ptr:e.dataPtr,length:n,dtype:"i32"}),c=r.viewOf({ptr:s,length:n,dtype:"i32"});for(let u=0;u<n;u++){let p=l[u];c[u]=p>=0&&p<a.length?a[p]:0;}return s}function Qn(t,e,n){let{ctx:r}=t,o=r.mod.alloc(Math.max(n*4,1)),i=r.viewOf({ptr:e.dataPtr,length:n,dtype:"bool"}),a=r.viewOf({ptr:o,length:n,dtype:"i32"});for(let s=0;s<n;s++)a[s]=i[s];return o}function ee(t,e){let n=0,r={};for(let{name:o,col:i}of e){let a=i.length,s=i.validityBitOffset,l=i.validityPtr===0?null:t.viewOf({ptr:i.validityPtr,length:A(s+a),dtype:"u8"});if(i.dtype==="utf8"){let c=t.viewOf({ptr:i.dataPtr,length:a,dtype:"i32"}),u=i.dict;Object.defineProperty(r,o,{enumerable:true,get(){return l&&!D(l,s+n)?null:j(t,u,c[n])}});}else if(i.dtype==="bool"){let c=t.viewOf({ptr:i.dataPtr,length:a,dtype:"bool"});Object.defineProperty(r,o,{enumerable:true,get(){return l&&!D(l,s+n)?null:c[n]!==0}});}else if(i.dtype==="i64"){let c=t.viewOf({ptr:i.dataPtr,length:a,dtype:"i64"});Object.defineProperty(r,o,{enumerable:true,get(){return l&&!D(l,s+n)?null:c[n]}});}else {let c=t.viewOf({ptr:i.dataPtr,length:a,dtype:b[i.dtype].view});Object.defineProperty(r,o,{enumerable:true,get(){return l&&!D(l,s+n)?null:c[n]}});}}return {at(o){return n=o,r}}}function Oe(t){if(t<=1)return 1;let e=1;for(;e<t;)e<<=1;return e}var Re=4,Dt=16;function Ct(t,e){if(e===0)return t.alloc(0);let n=t.alloc(e);if(n===0)throw new Error(`[hash stubs] OOM: alloc(${e}) returned 0`);return new Uint8Array(t.memory.buffer,n,e).fill(0),n}function Se(t,e,n,r,o){let i=Math.max(Re,Oe(2*Math.max(n,1))),a=0;try{for(a=Ct(t,i*Dt);;){let s=t.group_build(e,n,a,i,r);if(s!==-1)return s;t.free(a),a=0,i*=2,a=Ct(t,i*Dt);}}finally{a!==0&&t.free(a);}}function Me(t,e,n,r,o,i,a,s,l){let c=Math.max(Re,Oe(2*Math.max(s,1))),u=Math.max(1,o+s),p=0,f=0,m=0;try{if(p=Ct(t,c*Dt),f=t.alloc(u*4),f===0)throw new Error("[hash stubs] OOM: out_l_idx alloc failed");if(m=t.alloc(u*4),m===0)throw new Error("[hash stubs] OOM: out_r_idx alloc failed");for(;;){let d=e(n,r,o,i,a,s,p,c,f,m,u);if(d===-1){t.free(p),p=0,c*=2,p=Ct(t,c*Dt);continue}if(d>u){if(t.free(f),f=0,t.free(m),m=0,u=d,f=t.alloc(u*4),f===0)throw new Error("[hash stubs] OOM: out_l_idx resize failed");if(m=t.alloc(u*4),m===0)throw new Error("[hash stubs] OOM: out_r_idx resize failed");t.free(p),p=0,p=Ct(t,c*Dt);continue}let y=new Int32Array(t.memory.buffer,f,d).slice(),w=new Int32Array(t.memory.buffer,m,d).slice();return {count:d,lIdx:y,rIdx:w}}}finally{p!==0&&t.free(p),f!==0&&t.free(f),m!==0&&t.free(m);}}function _e(t,e,n,r,o,i,a,s){return Me(t,(l,c,u,p,f,m,d,y,w,h,g)=>t.join_hash_inner(l,c,u,p,f,m,d,y,w,h,g),e,n,r,o,i,a)}function Be(t,e,n,r,o,i,a,s){return Me(t,(l,c,u,p,f,m,d,y,w,h,g)=>t.join_hash_left(l,c,u,p,f,m,d,y,w,h,g),e,n,r,o,i,a)}var tr=new Set(["sum","mean","min","max","count","size","nunique","std","var","first","last"]),_t=class{src;keys;constructor(e,n){this.src=e,this.keys=n;for(let r of n)if(e.dtypeOf(r)===void 0)throw G(r,e.columnNames())}agg(e){let{rt:n}=this.src,{ctx:r}=n,o=this.src.length,i=this.keys.map(c=>this.src.getColumn(c)),a=this.buildPlan(e),s=nr(n,i),l=[];try{let c=s.firstRow,u=[];for(let m=0;m<this.keys.length;m++){let d=or(n,i[m],c);l.push(d),u.push({name:this.keys[m],col:d});}let p=r.viewOf({ptr:s.groupIdsPtr,length:o,dtype:"i32"});for(let m of a){let d=ir(n,m,p,s.groupCount,o);l.push(d),u.push({name:m.outName,col:d});}let f=this.src.buildResult(u);return l.length=0,f}finally{for(let c of l)Q(r,c);for(let c of a)c.ownsOperand&&c.operand&&Q(r,c.operand);r.viewOf.forget({ptr:s.groupIdsPtr,length:o,dtype:"i32"}),r.mod.free(s.groupIdsPtr);}}buildPlan(e){let n=[];for(let[r,o]of Object.entries(e))if(o instanceof V)n.push(this.exprPlan(r,o));else if(Array.isArray(o))for(let i of o)n.push(this.columnPlan(`${r}_${i}`,r,i));else n.push(this.columnPlan(r,r,o));return n}columnPlan(e,n,r){if(!tr.has(r))throw new I(`unknown aggregation '${r}' for '${n}'.`);if(r==="size")return {outName:e,op:r,operand:null,operandDtype:"i32",ownsOperand:false,resultDtype:"i32"};let o=this.src.getColumn(n);if(!o)throw G(n,this.src.columnNames());let i=er(r,o.dtype);return {outName:e,op:r,operand:o,operandDtype:o.dtype,ownsOperand:false,resultDtype:i}}exprPlan(e,n){let r=n.node;if(r.kind!=="agg")throw new I(`agg value for '${e}' must be a top-level aggregation (e.g. col('a').sum()).`);let o=r.op,i=jt(r.operand,this.src),a=ht(o,i),s=xt(r.operand,this.src).execute();if(s.kind!=="column"||!s.column)throw new I(`aggregation operand for '${e}' did not produce a column.`);return {outName:e,op:o,operand:s.column,operandDtype:i,ownsOperand:true,resultDtype:a}}};function er(t,e){return t==="size"?"i32":ht(t,e)}function nr(t,e){let{ctx:n,wasm:r}=t,o=e.length>0?e[0].length:0,i=n.mod.alloc(Math.max(o*8,1));try{for(let p=0;p<e.length;p++){let f=e[p],m=rr(t,f,o),d=st(n,f);try{if(p===0)B(r,`hash_${m.tok}`)(m.ptr,d.ptr,i,o);else {let y=n.mod.alloc(Math.max(o*8,1));try{B(r,`hash_${m.tok}`)(m.ptr,d.ptr,y,o),B(r,"hash_combine")(i,y,o);}finally{n.viewOf.forget({ptr:y,length:o,dtype:"u8"}),n.mod.free(y);}}}finally{lt(n,d),m.free();}}let a=n.mod.alloc(Math.max(o*4,1)),s=Se(r,i,o,a),l=n.viewOf({ptr:a,length:o,dtype:"i32"}),c=new Int32Array(s),u=0;for(let p=0;p<o&&u<s;p++)l[p]===u&&(c[u++]=p);return {groupIdsPtr:a,groupCount:s,firstRow:c}}finally{n.viewOf.forget({ptr:i,length:o,dtype:"u8"}),n.mod.free(i);}}function rr(t,e,n){let{ctx:r}=t;if(e.dtype==="utf8")return {ptr:e.dataPtr,tok:"i32",free(){}};if(e.dtype==="bool"){let o=r.mod.alloc(Math.max(n*4,1)),i=r.viewOf({ptr:e.dataPtr,length:n,dtype:"bool"}),a=r.viewOf({ptr:o,length:n,dtype:"i32"});for(let s=0;s<n;s++)a[s]=i[s];return {ptr:o,tok:"i32",free(){r.viewOf.forget({ptr:o,length:n,dtype:"i32"}),r.mod.free(o);}}}return {ptr:e.dataPtr,tok:b[e.dtype].wasm,free(){}}}function or(t,e,n){let{ctx:r}=t,o=n.length,i=e.validityPtr===0?null:r.viewOf({ptr:e.validityPtr,length:A(e.validityBitOffset+e.length),dtype:"u8"}),a=e.validityBitOffset;if(e.dtype==="utf8"){let u=r.viewOf({ptr:e.dataPtr,length:e.length,dtype:"i32"}),p=e.dict,f=new Array(o);for(let m=0;m<o;m++){let d=n[m];f[m]=i&&!D(i,a+d)?null:j(r,p,u[d]);}return v(r,"utf8",f)}if(e.dtype==="i64"){let u=r.viewOf({ptr:e.dataPtr,length:e.length,dtype:"i64"}),p=new Array(o);for(let f=0;f<o;f++){let m=n[f];p[f]=i&&!D(i,a+m)?null:u[m];}return v(r,"i64",p)}let s=e.dtype==="bool",l=r.viewOf({ptr:e.dataPtr,length:e.length,dtype:b[e.dtype].view}),c=new Array(o);for(let u=0;u<o;u++){let p=n[u];i&&!D(i,a+p)?c[u]=null:c[u]=s?l[p]!==0:l[p];}return v(r,e.dtype,c)}function ir(t,e,n,r,o){let{ctx:i}=t,{op:a}=e;if(a==="size"){let h=new Array(r).fill(0);for(let g=0;g<o;g++){let x=n[g];h[x]=h[x]+1;}return v(i,"i32",h)}let s=e.operand,l=s.validityPtr===0?null:i.viewOf({ptr:s.validityPtr,length:A(s.validityBitOffset+o),dtype:"u8"}),c=s.validityBitOffset,u=h=>l===null||D(l,c+h);if(a==="count"){let h=new Array(r).fill(0);for(let g=0;g<o;g++)if(u(g)){let x=n[g];h[x]=h[x]+1;}return v(i,"i32",h)}if(a==="first"||a==="last")return lr(t,e,n,r,o,u);if(a==="nunique")return sr(t,e,n,r,o,u);if(a==="std"||a==="var")return ar(t,e,n,r,o,u);if(s.dtype==="i64"){let h=i.viewOf({ptr:s.dataPtr,length:o,dtype:"i64"});if(a==="sum"){let C=new Array(r).fill(0n);for(let k=0;k<o;k++)if(u(k)){let L=n[k];C[L]=C[L]+h[k];}return v(i,"i64",C)}if(a==="mean"){let C=new Float64Array(r),k=new Int32Array(r);for(let F=0;F<o;F++){if(!u(F))continue;let kt=n[F];C[kt]=C[kt]+Number(h[F]),k[kt]=k[kt]+1;}let L=new Array(r);for(let F=0;F<r;F++)L[F]=k[F]>0?C[F]/k[F]:null;return v(i,"f64",L)}let g=new Array(r).fill(null),x=a==="min";for(let C=0;C<o;C++){if(!u(C))continue;let k=n[C],L=h[C];g[k]===null?g[k]=L:g[k]=x?L<g[k]?L:g[k]:L>g[k]?L:g[k];}return v(i,"i64",g)}let p=i.viewOf({ptr:s.dataPtr,length:o,dtype:b[s.dtype].view}),f=new Array(r).fill(null);if(a==="sum"){let h=new Float64Array(r);for(let g=0;g<o;g++)if(u(g)){let x=n[g];h[x]=h[x]+p[g];}for(let g=0;g<r;g++)f[g]=h[g];return v(i,e.resultDtype,f)}if(a==="mean"){let h=new Float64Array(r),g=new Int32Array(r);for(let x=0;x<o;x++){if(!u(x))continue;let C=n[x];h[C]=h[C]+p[x],g[C]=g[C]+1;}for(let x=0;x<r;x++)f[x]=g[x]>0?h[x]/g[x]:null;return v(i,"f64",f)}let m=new Int32Array(r),d=new Int32Array(r),y=new Float64Array(r),w=a==="min";for(let h=0;h<o;h++){if(!u(h))continue;let g=n[h];m[g]=m[g]+1;let x=p[h];Number.isNaN(x)||(d[g]===0?y[g]=x:y[g]=w?Math.min(y[g],x):Math.max(y[g],x),d[g]=d[g]+1);}for(let h=0;h<r;h++)f[h]=m[h]===0?null:d[h]===0?NaN:y[h];return v(i,e.resultDtype,f)}function ar(t,e,n,r,o,i){let{ctx:a}=t,s=e.operand,l=s.dtype==="i64",c=l?a.viewOf({ptr:s.dataPtr,length:o,dtype:"i64"}):a.viewOf({ptr:s.dataPtr,length:o,dtype:b[s.dtype].view}),u=new Float64Array(r),p=new Int32Array(r);for(let w=0;w<o;w++){if(!i(w))continue;let h=n[w];u[h]=u[h]+(l?Number(c[w]):c[w]),p[h]=p[h]+1;}let f=new Float64Array(r);for(let w=0;w<r;w++)f[w]=p[w]>0?u[w]/p[w]:0;let m=new Float64Array(r);for(let w=0;w<o;w++){if(!i(w))continue;let h=n[w],x=(l?Number(c[w]):c[w])-f[h];m[h]=m[h]+x*x;}let d=new Array(r),y=e.op==="std";for(let w=0;w<r;w++)if(p[w]<2)d[w]=null;else {let h=m[w]/(p[w]-1);d[w]=y?Math.sqrt(h):h;}return v(a,"f64",d)}function sr(t,e,n,r,o,i){let{ctx:a}=t,s=e.operand,l=new Array(r),c=s.dtype==="utf8"||s.dtype==="bool"?a.viewOf({ptr:s.dataPtr,length:o,dtype:s.dtype==="utf8"?"i32":"bool"}):s.dtype==="i64"?a.viewOf({ptr:s.dataPtr,length:o,dtype:"i64"}):a.viewOf({ptr:s.dataPtr,length:o,dtype:b[s.dtype].view});for(let p=0;p<o;p++){if(!i(p))continue;let f=n[p];(l[f]??=new Set).add(c[p]);}let u=new Array(r);for(let p=0;p<r;p++)u[p]=l[p]?l[p].size:0;return v(a,"i32",u)}function lr(t,e,n,r,o,i){let{ctx:a}=t,s=e.operand,l=e.op==="first",c=new Int32Array(r).fill(-1);for(let m=0;m<o;m++){if(!i(m))continue;let d=n[m];l?c[d]===-1&&(c[d]=m):c[d]=m;}let u=new Array(r);if(s.dtype==="utf8"){let m=a.viewOf({ptr:s.dataPtr,length:o,dtype:"i32"}),d=s.dict;for(let y=0;y<r;y++)u[y]=c[y]===-1?null:j(a,d,m[c[y]]);return v(a,"utf8",u)}if(s.dtype==="i64"){let m=a.viewOf({ptr:s.dataPtr,length:o,dtype:"i64"});for(let d=0;d<r;d++){let y=c[d];u[d]=y===-1?null:m[y];}return v(a,"i64",u)}let p=s.dtype==="bool",f=a.viewOf({ptr:s.dataPtr,length:o,dtype:b[s.dtype].view});for(let m=0;m<r;m++){let d=c[m];u[m]=d===-1?null:p?f[d]!==0:f[d];}return v(a,s.dtype,u)}function Ue(t,e,n){let r=n.how??"inner",o=Array.isArray(n.on)?n.on:[n.on];if(o.length===0)throw new I("join requires at least one key in `on`.");let i=t.rt,{ctx:a}=i,s=t.length,l=e.length;for(let u of o){let p=t.dtypeOf(u);if(p===void 0)throw G(u,t.columnNames());let f=e.dtypeOf(u);if(f===void 0)throw G(u,e.columnNames());if(p!==f)throw Ce("join",p,f,`join key '${u}' must have one dtype.`)}let c=o.map(u=>cr(i,t.getColumn(u),e.getColumn(u),s,l));try{let u=$e(i,c.map(y=>({ptr:y.leftPtr,tok:y.tok})),s),p=$e(i,c.map(y=>({ptr:y.rightPtr,tok:y.tok})),l),f=Le(i,o.map(y=>t.getColumn(y)),s),m=Le(i,o.map(y=>e.getColumn(y)),l),d;try{let y=i.wasm;d=r==="left"?Be(y,u,f.ptr,s,p,m.ptr,l):_e(y,u,f.ptr,s,p,m.ptr,l);}finally{a.viewOf.forget({ptr:u,length:s,dtype:"u8"}),a.mod.free(u),a.viewOf.forget({ptr:p,length:l,dtype:"u8"}),a.mod.free(p),ut(i,f.ptr,f.owns),ut(i,m.ptr,m.owns);}return ur(t,e,o,d,r)}finally{for(let u of c)u.free();}}function ur(t,e,n,r,o){let i=t.rt,{ctx:a}=i,s=new Set(n),l=t.columnNames(),c=e.columnNames().filter(f=>!s.has(f)),u=new Set(l),p=[];try{let f=[];for(let d of l){let y=Ve(i,t.getColumn(d),r.lIdx);p.push(y),f.push({name:d,col:y});}for(let d of c){let y=Ve(i,e.getColumn(d),r.rIdx);p.push(y);let w=u.has(d)?`${d}_right`:d;f.push({name:w,col:y});}let m=t.buildResult(f);return p.length=0,m}finally{for(let f of p)Q(a,f);}}function Ve(t,e,n){let{ctx:r}=t,o=z(r,e),i=new Array(n.length);for(let a=0;a<n.length;a++){let s=n[a];i[a]=s<0?null:o[s];}return v(r,e.dtype,i)}function cr(t,e,n,r,o){let{ctx:i}=t;if(e.dtype==="utf8"){let a=re(i,e.dict,n.dict),s=Fe(t,e,a.remapA,r),l=Fe(t,n,a.remapB,o);return {leftPtr:s,rightPtr:l,tok:"i32",free(){ut(t,s,true),ut(t,l,true);}}}if(e.dtype==="bool"){let a=Ne(t,e,r),s=Ne(t,n,o);return {leftPtr:a,rightPtr:s,tok:"i32",free(){ut(t,a,true),ut(t,s,true);}}}return {leftPtr:e.dataPtr,rightPtr:n.dataPtr,tok:b[e.dtype].wasm,free(){}}}function Fe(t,e,n,r){let{ctx:o}=t,i=o.mod.alloc(Math.max(r*4,1)),a=o.viewOf({ptr:e.dataPtr,length:r,dtype:"i32"}),s=o.viewOf({ptr:i,length:r,dtype:"i32"});for(let l=0;l<r;l++){let c=a[l];s[l]=c>=0&&c<n.length?n[c]:0;}return i}function Ne(t,e,n){let{ctx:r}=t,o=r.mod.alloc(Math.max(n*4,1)),i=r.viewOf({ptr:e.dataPtr,length:n,dtype:"bool"}),a=r.viewOf({ptr:o,length:n,dtype:"i32"});for(let s=0;s<n;s++)a[s]=i[s];return o}function $e(t,e,n){let{ctx:r,wasm:o}=t,i=r.mod.alloc(Math.max(n*8,1));for(let a=0;a<e.length;a++){let s=e[a];if(a===0)B(o,`hash_${s.tok}`)(s.ptr,0,i,n);else {let l=r.mod.alloc(Math.max(n*8,1));try{B(o,`hash_${s.tok}`)(s.ptr,0,l,n),B(o,"hash_combine")(i,l,n);}finally{r.viewOf.forget({ptr:l,length:n,dtype:"u8"}),r.mod.free(l);}}}return i}function Le(t,e,n){let{ctx:r}=t,o=e.filter(c=>c.validityPtr!==0);if(o.length===0)return {ptr:0,owns:false};let i=A(n),a=r.mod.alloc(Math.max(i,1)),s=r.viewOf({ptr:a,length:Math.max(i,1),dtype:"u8"});s.fill(0);let l=o.map(c=>({view:r.viewOf({ptr:c.validityPtr,length:A(c.validityBitOffset+n),dtype:"u8"}),bitOff:c.validityBitOffset}));for(let c=0;c<n;c++){let u=true;for(let p of l)if(!D(p.view,p.bitOff+c)){u=false;break}u&&O(s,c);}return {ptr:a,owns:true}}function ut(t,e,n){n&&e!==0&&(t.ctx.viewOf.forget({ptr:e,length:1,dtype:"u8"}),t.ctx.mod.free(e));}function je(t,e){if(t===null)return "null";if(typeof t=="boolean")return t?"true":"false";if(typeof t=="string")return t.length>24?`${t.slice(0,23)}\u2026`:t;if(e==="date32"&&typeof t=="number")return new Date(t*864e5).toISOString().slice(0,10);if(typeof t=="bigint")return e==="timestamp"?new Date(Number(t)).toISOString():String(t);if(Number.isNaN(t))return "NaN";if(t===1/0)return "inf";if(t===-1/0)return "-inf";if(Number.isInteger(t))return String(t);if(e==="f32"||e==="f64"){let n=t.toPrecision(6);return n.includes(".")&&!n.includes("e")?n.replace(/0+$/,"").replace(/\.$/,""):n}return String(t)}function ze(t){return t==="utf8"||t==="bool"?"left":"right"}function pr(t,e,n){let r=e-t.length;return r<=0?t:n==="right"?" ".repeat(r)+t:t+" ".repeat(r)}function qe(t,e,n,r,o){let i=t.length,a=new Array(i);for(let u=0;u<i;u++){let p=Math.max(t[u].length,e[u].length);for(let f of n)p=Math.max(p,f[u].length);a[u]=p;}let s=u=>u.map((p,f)=>pr(p,a[f],r[f])).join(" "),l=a.map(u=>"\u2500".repeat(u)).join(" "),c=[];c.push(s(t)),c.push(s(e)),c.push(l);for(let u of n)c.push(s(u));return o&&c.push(o),c.join(`
|
|
2
|
+
`)}var fr=new Set(["f64","f32","i32","u32","i64"]),Bt=class t{length;_rt;entries;byName;disposed=false;constructor(e,n,r){this._rt=e,this.entries=n,this.length=r,this.byName=new Map(n.map(o=>[o.name,o]));}get ctx(){return this._rt.ctx}get wasm(){return this._rt.wasm}get rt(){return this._rt}getColumn(e){return this.byName.get(e)?.col}dtypeOf(e){return this.byName.get(e)?.col.dtype}columnNames(){return this.entries.map(e=>e.name)}buildResult(e){let n=e.length>0?e[0].col.length:this.length;return t.fromRoots(this._rt,e,n)}static fromColumns(e,n={}){let r=n.runtime??Gt(),o=[],i=-1;for(let[a,s]of Object.entries(e)){let l=n.dtypes?.[a]??Zt(s),c=l==="timestamp"?n.tzs?.[a]:void 0,u=v(r.ctx,l,s,c);if(i===-1)i=u.length;else if(u.length!==i)throw new I(`column '${a}' has length ${u.length}, expected ${i}.`);o.push({name:a,col:u});}return t.fromRoots(r,o,i===-1?0:i)}static fromRecords(e,n={}){n.runtime??Gt();let o=[],i=new Set;for(let s of e)for(let l of Object.keys(s))i.has(l)||(i.add(l),o.push(l));let a={};for(let s of o){let l=new Array(e.length);for(let c=0;c<e.length;c++){let u=e[c][s];l[c]=u===void 0?null:u;}a[s]=l;}return t.fromColumns(a,n)}static fromRoots(e,n,r){let o=n.map(i=>({name:i.name,col:i.col,owner:new At(e.ctx,i.col)}));return new t(e,o,r)}get shape(){return [this.length,this.entries.length]}get columns(){return this.columnNames()}get dtypes(){let e={};for(let n of this.entries)e[n.name]=n.col.dtype;return e}col(e){let n=this.entryOf(e);return new vt(this._rt.ctx,e,n.col)}select(e){return new t(this._rt,this.shareEntries(e),this.length)}drop(e){let n=new Set(e);for(let o of e)if(!this.byName.has(o))throw G(o,this.columnNames());let r=this.entries.filter(o=>!n.has(o.name)).map(o=>o.name);return new t(this._rt,this.shareEntries(r),this.length)}withColumn(e,n,r={}){let o=this.materializeColumn(n,r),i=new At(this._rt.ctx,o),a={name:e,col:o,owner:i},s=[],l=false;for(let c of this.entries)c.name===e?(s.push(a),l=true):s.push(this.retainEntry(c));return l||s.push(a),new t(this._rt,s,this.length)}assign(e,n,r){return this.withColumn(e,n,r)}filter(e){let n=Wt(e,this).execute();try{let r=this.entries.map(o=>({name:o.name,col:n.compact(o.col)}));return t.fromRoots(this._rt,r,n.count)}finally{n.free();}}filterFn(e){let n=ee(this._rt.ctx,this.entries),r=[];for(let o=0;o<this.length;o++)e(n.at(o))&&r.push(o);return this.gatherRows(r)}mapFn(e){let n=ee(this._rt.ctx,this.entries),r=new Array(this.length);for(let o=0;o<this.length;o++)r[o]=e(n.at(o));return r}sortValues(e,n={}){let r=typeof e=="string"?[e]:[...e];if(r.length===0)throw new I("sortValues requires at least one key.");let o=r.map(s=>this.entryOf(s).col),i=Array.isArray(n.descending)?r.map((s,l)=>n.descending[l]===true):r.map(()=>n.descending===true),a=Ie(this._rt,o,i);try{let s=this.entries.map(l=>({name:l.name,col:Qt(this._rt,l.col,a.ptr,a.len)}));return t.fromRoots(this._rt,s,a.len)}finally{this._rt.ctx.viewOf.forget({ptr:a.ptr,length:a.len,dtype:"i32"}),this._rt.ctx.mod.free(a.ptr);}}groupby(e){let n=typeof e=="string"?[e]:[...e];if(n.length===0)throw new I("groupby requires at least one key.");return new _t(this,n)}join(e,n){return Ue(this,e,n)}head(e=5){return this.sliceRange(0,e)}tail(e=5){return this.sliceRange(Math.max(0,this.length-e),this.length)}slice(e,n=this.length){return this.sliceRange(e,n)}sliceRange(e,n){let r=Math.max(0,Math.min(e,this.length)),o=Math.max(r,Math.min(n,this.length)),i=this.entries.map(a=>({name:a.name,col:Vt(a.col,r,o),owner:a.owner.retain()}));return new t(this._rt,i,o-r)}toColumns(){let e={};for(let n of this.entries)e[n.name]=z(this._rt.ctx,n.col);return e}toRecords(){let e=this.toColumns(),n=this.columnNames(),r=new Array(this.length);for(let o=0;o<this.length;o++){let i={};for(let a of n)i[a]=e[a][o];r[o]=i;}return r}describe(){let e=["count","mean","std","min","25%","50%","75%","max"],n=this.entries.filter(i=>fr.has(i.col.dtype)),r={statistic:e},o={statistic:"utf8"};for(let i of n)r[i.name]=dr(z(this._rt.ctx,i.col)),o[i.name]="f64";return t.fromColumns(r,{runtime:this._rt,dtypes:o})}dispose(){if(!this.disposed){this.disposed=true;for(let e of this.entries)e.owner.release();}}toString(){return this.render()}[Symbol.for("nodejs.util.inspect.custom")](){return this.render()}entryOf(e){let n=this.byName.get(e);if(!n)throw G(e,this.columnNames());return n}retainEntry(e){return e.owner.retain(),{name:e.name,col:e.col,owner:e.owner}}shareEntries(e){return e.map(n=>this.retainEntry(this.entryOf(n)))}materializeColumn(e,n){if(e instanceof V){let o=xt(e,this).execute();if(o.kind==="column"&&o.column)return o.column;let i=o.scalar,a=new Array(this.length).fill(i.value);return v(this._rt.ctx,i.dtype,a)}let r=n.dtype??Zt(e);if(e.length!==this.length)throw new I(`withColumn value has length ${e.length}, expected ${this.length}.`);return v(this._rt.ctx,r,e)}gatherRows(e){let{ctx:n}=this._rt,r=e.length,o=n.mod.alloc(Math.max(r*4,1));try{let i=n.viewOf({ptr:o,length:r,dtype:"i32"});for(let s=0;s<r;s++)i[s]=e[s];let a=this.entries.map(s=>({name:s.name,col:Qt(this._rt,s.col,o,r)}));return t.fromRoots(this._rt,a,r)}finally{n.viewOf.forget({ptr:o,length:r,dtype:"i32"}),n.mod.free(o);}}render(){let e=this.columnNames();if(e.length===0)return `Empty DataFrame [${this.length} rows \xD7 0 columns]`;let n=this.entries.map(u=>u.col.dtype),r=n.map(ze),o=5,i=5,a=[],s=this.length>o+i,l=(u,p)=>{let f=this.entries.map(m=>z(this._rt.ctx,Vt(m.col,u,p)));for(let m=0;m<p-u;m++)a.push(f.map((d,y)=>je(d[m],n[y])));};s?(l(0,o),a.push(e.map(()=>"\u2026")),l(this.length-i,this.length)):l(0,this.length);let c=`[${this.length} rows \xD7 ${e.length} columns]`;return qe(e,n,a,r,c)}};function dr(t){let e=[];for(let l of t){if(l===null)continue;let c=typeof l=="bigint"?Number(l):l;Number.isFinite(c)&&e.push(c);}let n=e.length;if(n===0)return [0,null,null,null,null,null,null,null];let r=e.slice().sort((l,c)=>l-c),i=e.reduce((l,c)=>l+c,0)/n,a=n>=2?Math.sqrt(e.reduce((l,c)=>l+(c-i)*(c-i),0)/(n-1)):null,s=l=>{if(r.length===1)return r[0];let c=l*(r.length-1),u=Math.floor(c),p=Math.ceil(c),f=c-u;return r[u]+(r[p]-r[u])*f};return [n,i,a,r[0],s(.25),s(.5),s(.75),r[r.length-1]]}var br=new Set(["UNCOMPRESSED","SNAPPY",void 0]),xr={timestampFromMilliseconds:t=>t,timestampFromMicroseconds:t=>t/1000n,timestampFromNanoseconds:t=>t/1000000n,dateFromDays:t=>t,stringFromBytes:t=>t!=null?new TextDecoder().decode(t):null,jsonFromBytes:t=>t!=null?JSON.parse(new TextDecoder().decode(t)):null,bsonFromBytes:t=>t,geometryFromBytes:t=>t,geographyFromBytes:t=>t,uuidFromBytes:t=>t};function Ar(t){let e=t instanceof ArrayBuffer?t:t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength);return {byteLength:e.byteLength,slice:(n,r)=>Promise.resolve(e.slice(n,r))}}function vr(t,e){let n=t.name,r=t.type,o=t.logical_type,i=t.converted_type,a=t.num_children,s=t.repetition_type;if(a!=null&&a>0){let l=o?.type;throw l==="LIST"?new Error(`unsupported Parquet feature: LIST column '${n}' \u2014 nested/repeated types are not supported by databonk/parquet (ADR-011)`):l==="MAP"?new Error(`unsupported Parquet feature: MAP column '${n}' \u2014 nested types are not supported (ADR-011)`):new Error(`unsupported Parquet feature: nested/group column '${n}' \u2014 databonk/parquet only supports flat columns (ADR-011)`)}if(s==="REPEATED")throw new Error(`unsupported Parquet feature: REPEATED field '${n}' \u2014 only OPTIONAL/REQUIRED are supported (ADR-011)`);switch(r){case "DOUBLE":return {name:n,dtype:"f64"};case "FLOAT":return {name:n,dtype:"f32"};case "BOOLEAN":return {name:n,dtype:"bool"};case "INT32":{let l=o?.type;if(l==="DATE"||i==="DATE")return {name:n,dtype:"date32"};if(l==="DECIMAL"||i==="DECIMAL")throw new Error(`unsupported Parquet feature: DECIMAL column '${n}' (ADR-011 \u2014 only the databonk numeric dtypes are supported)`);if(l==="INTEGER"){let c=o?.isSigned;return {name:n,dtype:c===false?"u32":"i32"}}return i==="UINT_32"?{name:n,dtype:"u32"}:{name:n,dtype:"i32"}}case "INT64":{let l=o?.type;if(l==="DECIMAL"||i==="DECIMAL")throw new Error(`unsupported Parquet feature: DECIMAL column '${n}' (ADR-011)`);if(l==="TIMESTAMP"||i==="TIMESTAMP_MILLIS"){let c=o?.unit;if(c!=null&&c!=="MILLIS")throw new Error(`unsupported Parquet feature: TIMESTAMP with unit '${c}' in column '${n}' \u2014 only MILLIS is supported (ADR-011)`);if(i==="TIMESTAMP_MICROS")throw new Error(`unsupported Parquet feature: TIMESTAMP_MICROS column '${n}' \u2014 only MILLIS is supported (ADR-011)`);let u=e.get(n);return u!==void 0?{name:n,dtype:"timestamp",tz:u}:{name:n,dtype:"timestamp"}}return {name:n,dtype:"i64"}}case "INT96":throw new Error(`unsupported Parquet feature: INT96 timestamp column '${n}' \u2014 only TIMESTAMP(INT64, MILLIS) is supported (ADR-011)`);case "FIXED_LEN_BYTE_ARRAY":throw new Error(`unsupported Parquet feature: FIXED_LEN_BYTE_ARRAY column '${n}' (ADR-011)`);case "BYTE_ARRAY":{let l=o?.type;if(l==="STRING"||i==="UTF8")return {name:n,dtype:"utf8"};throw l==="DECIMAL"||i==="DECIMAL"?new Error(`unsupported Parquet feature: DECIMAL column '${n}' (ADR-011)`):new Error(`unsupported Parquet feature: BYTE_ARRAY column '${n}' without STRING/UTF8 annotation is not supported (ADR-011)`)}default:throw new Error(`unsupported Parquet feature: unknown physical type '${String(r??"GROUP")}' in column '${n}' (ADR-011)`)}}function Dr(t){if(t.length===0)return [];if(t.length===1)return t[0];let e=t.reduce((o,i)=>o+i.length,0),n=new Array(e),r=0;for(let o of t){let i=o.length;for(let a=0;a<i;a++)n[r++]=o[a];}return n}async function xi(t,e){let n=Ar(t),r=await index_js.parquetMetadataAsync(n);for(let m of r.row_groups??[])for(let d of m.columns??[]){let y=d.meta_data?.codec;if(!br.has(y))throw new Error(`unsupported Parquet compression codec: '${y}'. databonk/parquet supports only SNAPPY and UNCOMPRESSED (ADR-011). For GZIP/ZSTD/BROTLI/LZ4, re-compress the file first.`)}let o=new Map,i=r.key_value_metadata??[],a="databonk:tz:";for(let{key:m,value:d}of i)m.startsWith(a)&&d&&o.set(m.slice(a.length),d);let l=index_js.parquetSchema(r).children.map(m=>vr(m.element,o)),c=new Map;for(let{name:m}of l)c.set(m,[]);await index_js.parquetRead({file:n,metadata:r,parsers:xr,onChunk(m){let d=c.get(m.columnName);d&&d.push(m.columnData);}});let u=[];for(let{name:m,dtype:d,tz:y}of l){let w=c.get(m)??[],h=Dr(w),g=v(e.ctx,d,h,y);u.push({name:m,col:g});}let p=Bt.fromColumns({},{runtime:e}),f=p.buildResult(u);return p.dispose(),f}function Cr(t,e,n,r){let o=z(t,n),i,a;switch(n.dtype){case "f64":i={name:e,type:"DOUBLE",repetition_type:"OPTIONAL"};break;case "f32":i={name:e,type:"FLOAT",repetition_type:"OPTIONAL"};break;case "i32":i={name:e,type:"INT32",repetition_type:"OPTIONAL"};break;case "u32":i={name:e,type:"INT32",repetition_type:"OPTIONAL",converted_type:"UINT_32"};break;case "i64":i={name:e,type:"INT64",repetition_type:"OPTIONAL"};break;case "bool":i={name:e,type:"BOOLEAN",repetition_type:"OPTIONAL"};break;case "utf8":i={name:e,type:"BYTE_ARRAY",repetition_type:"OPTIONAL",logical_type:{type:"STRING"},converted_type:"UTF8"};break;case "date32":i={name:e,type:"INT32",repetition_type:"OPTIONAL",logical_type:{type:"DATE"}};break;case "timestamp":{i={name:e,type:"INT64",repetition_type:"OPTIONAL",logical_type:{type:"TIMESTAMP",isAdjustedToUTC:true,unit:{MILLIS:{}}}},n.tz&&(a={key:`databonk:tz:${e}`,value:n.tz});break}default:{let s=n.dtype;throw new Error(`unsupported databonk dtype for Parquet write: '${String(s)}'`)}}return a!==void 0?{el:i,data:o,tzKey:a}:{el:i,data:o}}function Ai(t,e={}){let{compression:n="uncompressed"}=e;if(n!=="snappy"&&n!=="uncompressed")throw new Error(`unsupported Parquet compression codec: '${n}'. databonk/parquet writeParquet only accepts 'snappy' or 'uncompressed' (ADR-011).`);let r=n==="snappy"?"SNAPPY":"UNCOMPRESSED",o=t.columns;t.length;let a=t.ctx,s=[{name:"root",num_children:o.length}],l=[],c=[];for(let f of o){let m=t.getColumn(f),{el:d,data:y,tzKey:w}=Cr(a,f,m);s.push(d),l.push({name:f,data:y}),w&&c.push(w);}let u={schema:s,columnData:l,codec:r};c.length>0&&(u.kvMetadata=c);let p=index_js$1.parquetWriteBuffer(u);return new Uint8Array(p)}exports.readParquet=xi;exports.writeParquet=Ai;//# sourceMappingURL=parquet.cjs.map
|
|
3
|
+
//# sourceMappingURL=parquet.cjs.map
|