UNPKG

parquet-wasm

Version:

WebAssembly Parquet reader and writer.

1,588 lines (1,493 loc) 112 kB
let wasm; const heap = new Array(128).fill(undefined); heap.push(undefined, null, true, false); let heap_next = heap.length; function addHeapObject(obj) { if (heap_next === heap.length) heap.push(heap.length + 1); const idx = heap_next; heap_next = heap[idx]; heap[idx] = obj; return idx; } function getObject(idx) { return heap[idx]; } function dropObject(idx) { if (idx < 132) return; heap[idx] = heap_next; heap_next = idx; } function takeObject(idx) { const ret = getObject(idx); dropObject(idx); return ret; } const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } ); if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); }; let cachedUint8Memory0 = null; function getUint8Memory0() { if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) { cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer); } return cachedUint8Memory0; } function getStringFromWasm0(ptr, len) { ptr = ptr >>> 0; return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); } function isLikeNone(x) { return x === undefined || x === null; } let cachedFloat64Memory0 = null; function getFloat64Memory0() { if (cachedFloat64Memory0 === null || cachedFloat64Memory0.byteLength === 0) { cachedFloat64Memory0 = new Float64Array(wasm.memory.buffer); } return cachedFloat64Memory0; } let cachedInt32Memory0 = null; function getInt32Memory0() { if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) { cachedInt32Memory0 = new Int32Array(wasm.memory.buffer); } return cachedInt32Memory0; } let WASM_VECTOR_LEN = 0; const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } ); const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' ? function (arg, view) { return cachedTextEncoder.encodeInto(arg, view); } : function (arg, view) { const buf = cachedTextEncoder.encode(arg); view.set(buf); return { read: arg.length, written: buf.length }; }); function passStringToWasm0(arg, malloc, realloc) { if (realloc === undefined) { const buf = cachedTextEncoder.encode(arg); const ptr = malloc(buf.length, 1) >>> 0; getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf); WASM_VECTOR_LEN = buf.length; return ptr; } let len = arg.length; let ptr = malloc(len, 1) >>> 0; const mem = getUint8Memory0(); let offset = 0; for (; offset < len; offset++) { const code = arg.charCodeAt(offset); if (code > 0x7F) break; mem[ptr + offset] = code; } if (offset !== len) { if (offset !== 0) { arg = arg.slice(offset); } ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0; const view = getUint8Memory0().subarray(ptr + offset, ptr + len); const ret = encodeString(arg, view); offset += ret.written; ptr = realloc(ptr, len, offset, 1) >>> 0; } WASM_VECTOR_LEN = offset; return ptr; } let cachedBigInt64Memory0 = null; function getBigInt64Memory0() { if (cachedBigInt64Memory0 === null || cachedBigInt64Memory0.byteLength === 0) { cachedBigInt64Memory0 = new BigInt64Array(wasm.memory.buffer); } return cachedBigInt64Memory0; } function debugString(val) { // primitive types const type = typeof val; if (type == 'number' || type == 'boolean' || val == null) { return `${val}`; } if (type == 'string') { return `"${val}"`; } if (type == 'symbol') { const description = val.description; if (description == null) { return 'Symbol'; } else { return `Symbol(${description})`; } } if (type == 'function') { const name = val.name; if (typeof name == 'string' && name.length > 0) { return `Function(${name})`; } else { return 'Function'; } } // objects if (Array.isArray(val)) { const length = val.length; let debug = '['; if (length > 0) { debug += debugString(val[0]); } for(let i = 1; i < length; i++) { debug += ', ' + debugString(val[i]); } debug += ']'; return debug; } // Test for built-in const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val)); let className; if (builtInMatches.length > 1) { className = builtInMatches[1]; } else { // Failed to match the standard '[object ClassName]' return toString.call(val); } if (className == 'Object') { // we're a user defined class or Object // JSON.stringify avoids problems with cycles, and is generally much // easier than looping through ownProperties of `val`. try { return 'Object(' + JSON.stringify(val) + ')'; } catch (_) { return 'Object'; } } // errors if (val instanceof Error) { return `${val.name}: ${val.message}\n${val.stack}`; } // TODO we could test for more things here, like `Set`s and `Map`s. return className; } const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(state => { wasm.__wbindgen_export_2.get(state.dtor)(state.a, state.b) }); function makeMutClosure(arg0, arg1, dtor, f) { const state = { a: arg0, b: arg1, cnt: 1, dtor }; const real = (...args) => { // First up with a closure we increment the internal reference // count. This ensures that the Rust closure environment won't // be deallocated while we're invoking it. state.cnt++; const a = state.a; state.a = 0; try { return f(a, state.b, ...args); } finally { if (--state.cnt === 0) { wasm.__wbindgen_export_2.get(state.dtor)(a, state.b); CLOSURE_DTORS.unregister(state); } else { state.a = a; } } }; real.original = state; CLOSURE_DTORS.register(real, state, state); return real; } function __wbg_adapter_50(arg0, arg1, arg2) { wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h1de40baa0df51db0(arg0, arg1, addHeapObject(arg2)); } function passArray8ToWasm0(arg, malloc) { const ptr = malloc(arg.length * 1, 1) >>> 0; getUint8Memory0().set(arg, ptr / 1); WASM_VECTOR_LEN = arg.length; return ptr; } /** * Read a Parquet file into Arrow data. * * This returns an Arrow table in WebAssembly memory. To transfer the Arrow table to JavaScript * memory you have two options: * * - (Easier): Call {@linkcode Table.intoIPCStream} to construct a buffer that can be parsed with * Arrow JS's `tableFromIPC` function. * - (More performant but bleeding edge): Call {@linkcode Table.intoFFI} to construct a data * representation that can be parsed zero-copy from WebAssembly with * [arrow-js-ffi](https://github.com/kylebarron/arrow-js-ffi) using `parseTable`. * * Example with IPC stream: * * ```js * import { tableFromIPC } from "apache-arrow"; * import initWasm, {readParquet} from "parquet-wasm"; * * // Instantiate the WebAssembly context * await initWasm(); * * const resp = await fetch("https://example.com/file.parquet"); * const parquetUint8Array = new Uint8Array(await resp.arrayBuffer()); * const arrowWasmTable = readParquet(parquetUint8Array); * const arrowTable = tableFromIPC(arrowWasmTable.intoIPCStream()); * ``` * * Example with `arrow-js-ffi`: * * ```js * import { parseTable } from "arrow-js-ffi"; * import initWasm, {readParquet, wasmMemory} from "parquet-wasm"; * * // Instantiate the WebAssembly context * await initWasm(); * const WASM_MEMORY = wasmMemory(); * * const resp = await fetch("https://example.com/file.parquet"); * const parquetUint8Array = new Uint8Array(await resp.arrayBuffer()); * const arrowWasmTable = readParquet(parquetUint8Array); * const ffiTable = arrowWasmTable.intoFFI(); * const arrowTable = parseTable( * WASM_MEMORY.buffer, * ffiTable.arrayAddrs(), * ffiTable.schemaAddr() * ); * ``` * * @param parquet_file Uint8Array containing Parquet data * @param options * * Options for reading Parquet data. Optional keys include: * * - `batchSize`: The number of rows in each batch. If not provided, the upstream parquet * default is 1024. * - `rowGroups`: Only read data from the provided row group indexes. * - `limit`: Provide a limit to the number of rows to be read. * - `offset`: Provide an offset to skip over the given number of rows. * - `columns`: The column names from the file to read. * @param {Uint8Array} parquet_file * @param {ReaderOptions | undefined} [options] * @returns {Table} */ export function readParquet(parquet_file, options) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); const ptr0 = passArray8ToWasm0(parquet_file, wasm.__wbindgen_malloc); const len0 = WASM_VECTOR_LEN; wasm.readParquet(retptr, ptr0, len0, isLikeNone(options) ? 0 : addHeapObject(options)); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var r2 = getInt32Memory0()[retptr / 4 + 2]; if (r2) { throw takeObject(r1); } return Table.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Read an Arrow schema from a Parquet file in memory. * * This returns an Arrow schema in WebAssembly memory. To transfer the Arrow schema to JavaScript * memory you have two options: * * - (Easier): Call {@linkcode Schema.intoIPCStream} to construct a buffer that can be parsed with * Arrow JS's `tableFromIPC` function. This results in an Arrow JS Table with zero rows but a * valid schema. * - (More performant but bleeding edge): Call {@linkcode Schema.intoFFI} to construct a data * representation that can be parsed zero-copy from WebAssembly with * [arrow-js-ffi](https://github.com/kylebarron/arrow-js-ffi) using `parseSchema`. * * Example with IPC Stream: * * ```js * import { tableFromIPC } from "apache-arrow"; * import initWasm, {readSchema} from "parquet-wasm"; * * // Instantiate the WebAssembly context * await initWasm(); * * const resp = await fetch("https://example.com/file.parquet"); * const parquetUint8Array = new Uint8Array(await resp.arrayBuffer()); * const arrowWasmSchema = readSchema(parquetUint8Array); * const arrowTable = tableFromIPC(arrowWasmSchema.intoIPCStream()); * const arrowSchema = arrowTable.schema; * ``` * * Example with `arrow-js-ffi`: * * ```js * import { parseSchema } from "arrow-js-ffi"; * import initWasm, {readSchema, wasmMemory} from "parquet-wasm"; * * // Instantiate the WebAssembly context * await initWasm(); * const WASM_MEMORY = wasmMemory(); * * const resp = await fetch("https://example.com/file.parquet"); * const parquetUint8Array = new Uint8Array(await resp.arrayBuffer()); * const arrowWasmSchema = readSchema(parquetUint8Array); * const ffiSchema = arrowWasmSchema.intoFFI(); * const arrowTable = parseSchema(WASM_MEMORY.buffer, ffiSchema.addr()); * const arrowSchema = arrowTable.schema; * ``` * * @param parquet_file Uint8Array containing Parquet data * @param {Uint8Array} parquet_file * @returns {Schema} */ export function readSchema(parquet_file) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); const ptr0 = passArray8ToWasm0(parquet_file, wasm.__wbindgen_malloc); const len0 = WASM_VECTOR_LEN; wasm.readSchema(retptr, ptr0, len0); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var r2 = getInt32Memory0()[retptr / 4 + 2]; if (r2) { throw takeObject(r1); } return Schema.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } function _assertClass(instance, klass) { if (!(instance instanceof klass)) { throw new Error(`expected instance of ${klass.name}`); } return instance.ptr; } function getArrayU8FromWasm0(ptr, len) { ptr = ptr >>> 0; return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len); } /** * Write Arrow data to a Parquet file. * * For example, to create a Parquet file with Snappy compression: * * ```js * import { tableToIPC } from "apache-arrow"; * // Edit the `parquet-wasm` import as necessary * import initWasm, { * Table, * WriterPropertiesBuilder, * Compression, * writeParquet, * } from "parquet-wasm"; * * // Instantiate the WebAssembly context * await initWasm(); * * // Given an existing arrow JS table under `table` * const wasmTable = Table.fromIPCStream(tableToIPC(table, "stream")); * const writerProperties = new WriterPropertiesBuilder() * .setCompression(Compression.SNAPPY) * .build(); * const parquetUint8Array = writeParquet(wasmTable, writerProperties); * ``` * * If `writerProperties` is not provided or is `null`, the default writer properties will be used. * This is equivalent to `new WriterPropertiesBuilder().build()`. * * @param table A {@linkcode Table} representation in WebAssembly memory. * @param writer_properties (optional) Configuration for writing to Parquet. Use the {@linkcode * WriterPropertiesBuilder} to build a writing configuration, then call `.build()` to create an * immutable writer properties to pass in here. * @returns Uint8Array containing written Parquet data. * @param {Table} table * @param {WriterProperties | undefined} [writer_properties] * @returns {Uint8Array} */ export function writeParquet(table, writer_properties) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); _assertClass(table, Table); var ptr0 = table.__destroy_into_raw(); let ptr1 = 0; if (!isLikeNone(writer_properties)) { _assertClass(writer_properties, WriterProperties); ptr1 = writer_properties.__destroy_into_raw(); } wasm.writeParquet(retptr, ptr0, ptr1); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var r2 = getInt32Memory0()[retptr / 4 + 2]; var r3 = getInt32Memory0()[retptr / 4 + 3]; if (r3) { throw takeObject(r2); } var v3 = getArrayU8FromWasm0(r0, r1).slice(); wasm.__wbindgen_free(r0, r1 * 1, 1); return v3; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Read a Parquet file into a stream of Arrow `RecordBatch`es. * * This returns a ReadableStream containing RecordBatches in WebAssembly memory. To transfer the * Arrow table to JavaScript memory you have two options: * * - (Easier): Call {@linkcode RecordBatch.intoIPCStream} to construct a buffer that can be parsed * with Arrow JS's `tableFromIPC` function. (The table will have a single internal record * batch). * - (More performant but bleeding edge): Call {@linkcode RecordBatch.intoFFI} to construct a data * representation that can be parsed zero-copy from WebAssembly with * [arrow-js-ffi](https://github.com/kylebarron/arrow-js-ffi) using `parseRecordBatch`. * * Example with IPC stream: * * ```js * import { tableFromIPC } from "apache-arrow"; * import initWasm, {readParquetStream} from "parquet-wasm"; * * // Instantiate the WebAssembly context * await initWasm(); * * const stream = await wasm.readParquetStream(url); * * const batches = []; * for await (const wasmRecordBatch of stream) { * const arrowTable = tableFromIPC(wasmRecordBatch.intoIPCStream()); * batches.push(...arrowTable.batches); * } * const table = new arrow.Table(batches); * ``` * * Example with `arrow-js-ffi`: * * ```js * import { parseRecordBatch } from "arrow-js-ffi"; * import initWasm, {readParquetStream, wasmMemory} from "parquet-wasm"; * * // Instantiate the WebAssembly context * await initWasm(); * const WASM_MEMORY = wasmMemory(); * * const stream = await wasm.readParquetStream(url); * * const batches = []; * for await (const wasmRecordBatch of stream) { * const ffiRecordBatch = wasmRecordBatch.intoFFI(); * const recordBatch = parseRecordBatch( * WASM_MEMORY.buffer, * ffiRecordBatch.arrayAddr(), * ffiRecordBatch.schemaAddr(), * true * ); * batches.push(recordBatch); * } * const table = new arrow.Table(batches); * ``` * * @param url URL to Parquet file * @param {string} url * @param {number | undefined} [content_length] * @returns {Promise<ReadableStream>} */ export function readParquetStream(url, content_length) { const ptr0 = passStringToWasm0(url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; const ret = wasm.readParquetStream(ptr0, len0, !isLikeNone(content_length), isLikeNone(content_length) ? 0 : content_length); return takeObject(ret); } let cachedUint32Memory0 = null; function getUint32Memory0() { if (cachedUint32Memory0 === null || cachedUint32Memory0.byteLength === 0) { cachedUint32Memory0 = new Uint32Array(wasm.memory.buffer); } return cachedUint32Memory0; } function getArrayJsValueFromWasm0(ptr, len) { ptr = ptr >>> 0; const mem = getUint32Memory0(); const slice = mem.subarray(ptr / 4, ptr / 4 + len); const result = []; for (let i = 0; i < slice.length; i++) { result.push(takeObject(slice[i])); } return result; } function handleError(f, args) { try { return f.apply(this, args); } catch (e) { wasm.__wbindgen_exn_store(addHeapObject(e)); } } function getArrayU32FromWasm0(ptr, len) { ptr = ptr >>> 0; return getUint32Memory0().subarray(ptr / 4, ptr / 4 + len); } /** * Returns a handle to this wasm instance's `WebAssembly.Memory` * @returns {Memory} */ export function wasmMemory() { const ret = wasm.wasmMemory(); return takeObject(ret); } /** * Returns a handle to this wasm instance's `WebAssembly.Table` which is the indirect function * table used by Rust * @returns {FunctionTable} */ export function _functionTable() { const ret = wasm._functionTable(); return takeObject(ret); } function __wbg_adapter_285(arg0, arg1, arg2, arg3) { wasm.wasm_bindgen__convert__closures__invoke2_mut__h26b6dc7d05b06fdf(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3)); } /** * The Parquet version to use when writing */ export const WriterVersion = Object.freeze({ V1:0,"0":"V1",V2:1,"1":"V2", }); /** * Controls the level of statistics to be computed by the writer */ export const EnabledStatistics = Object.freeze({ /** * Compute no statistics */ None:0,"0":"None", /** * Compute chunk-level statistics but not page-level */ Chunk:1,"1":"Chunk", /** * Compute page-level and chunk-level statistics */ Page:2,"2":"Page", }); /** * Encodings supported by Parquet. * Not all encodings are valid for all types. These enums are also used to specify the * encoding of definition and repetition levels. */ export const Encoding = Object.freeze({ /** * Default byte encoding. * - BOOLEAN - 1 bit per value, 0 is false; 1 is true. * - INT32 - 4 bytes per value, stored as little-endian. * - INT64 - 8 bytes per value, stored as little-endian. * - FLOAT - 4 bytes per value, stored as little-endian. * - DOUBLE - 8 bytes per value, stored as little-endian. * - BYTE_ARRAY - 4 byte length stored as little endian, followed by bytes. * - FIXED_LEN_BYTE_ARRAY - just the bytes are stored. */ PLAIN:0,"0":"PLAIN", /** * **Deprecated** dictionary encoding. * * The values in the dictionary are encoded using PLAIN encoding. * Since it is deprecated, RLE_DICTIONARY encoding is used for a data page, and * PLAIN encoding is used for dictionary page. */ PLAIN_DICTIONARY:1,"1":"PLAIN_DICTIONARY", /** * Group packed run length encoding. * * Usable for definition/repetition levels encoding and boolean values. */ RLE:2,"2":"RLE", /** * Bit packed encoding. * * This can only be used if the data has a known max width. * Usable for definition/repetition levels encoding. */ BIT_PACKED:3,"3":"BIT_PACKED", /** * Delta encoding for integers, either INT32 or INT64. * * Works best on sorted data. */ DELTA_BINARY_PACKED:4,"4":"DELTA_BINARY_PACKED", /** * Encoding for byte arrays to separate the length values and the data. * * The lengths are encoded using DELTA_BINARY_PACKED encoding. */ DELTA_LENGTH_BYTE_ARRAY:5,"5":"DELTA_LENGTH_BYTE_ARRAY", /** * Incremental encoding for byte arrays. * * Prefix lengths are encoded using DELTA_BINARY_PACKED encoding. * Suffixes are stored using DELTA_LENGTH_BYTE_ARRAY encoding. */ DELTA_BYTE_ARRAY:6,"6":"DELTA_BYTE_ARRAY", /** * Dictionary encoding. * * The ids are encoded using the RLE encoding. */ RLE_DICTIONARY:7,"7":"RLE_DICTIONARY", /** * Encoding for floating-point data. * * K byte-streams are created where K is the size in bytes of the data type. * The individual bytes of an FP value are scattered to the corresponding stream and * the streams are concatenated. * This itself does not reduce the size of the data but can lead to better compression * afterwards. */ BYTE_STREAM_SPLIT:8,"8":"BYTE_STREAM_SPLIT", }); /** * Supported compression algorithms. * * Codecs added in format version X.Y can be read by readers based on X.Y and later. * Codec support may vary between readers based on the format version and * libraries available at runtime. */ export const Compression = Object.freeze({ UNCOMPRESSED:0,"0":"UNCOMPRESSED",SNAPPY:1,"1":"SNAPPY",GZIP:2,"2":"GZIP",BROTLI:3,"3":"BROTLI", /** * @deprecated as of Parquet 2.9.0. * Switch to LZ4_RAW */ LZ4:4,"4":"LZ4",ZSTD:5,"5":"ZSTD",LZ4_RAW:6,"6":"LZ4_RAW",LZO:7,"7":"LZO", }); const ColumnChunkMetaDataFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_columnchunkmetadata_free(ptr >>> 0)); /** * Metadata for a Parquet column chunk. */ export class ColumnChunkMetaData { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(ColumnChunkMetaData.prototype); obj.__wbg_ptr = ptr; ColumnChunkMetaDataFinalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; ColumnChunkMetaDataFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_columnchunkmetadata_free(ptr); } /** * File where the column chunk is stored. * * If not set, assumed to belong to the same file as the metadata. * This path is relative to the current file. * @returns {string | undefined} */ filePath() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.columnchunkmetadata_filePath(retptr, this.__wbg_ptr); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; let v1; if (r0 !== 0) { v1 = getStringFromWasm0(r0, r1).slice(); wasm.__wbindgen_free(r0, r1 * 1, 1); } return v1; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Byte offset in `file_path()`. * @returns {bigint} */ fileOffset() { const ret = wasm.columnchunkmetadata_fileOffset(this.__wbg_ptr); return ret; } /** * Path (or identifier) of this column. * @returns {(string)[]} */ columnPath() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.columnchunkmetadata_columnPath(retptr, this.__wbg_ptr); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var v1 = getArrayJsValueFromWasm0(r0, r1).slice(); wasm.__wbindgen_free(r0, r1 * 4, 4); return v1; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * All encodings used for this column. * @returns {any[]} */ encodings() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.columnchunkmetadata_encodings(retptr, this.__wbg_ptr); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var v1 = getArrayJsValueFromWasm0(r0, r1).slice(); wasm.__wbindgen_free(r0, r1 * 4, 4); return v1; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Total number of values in this column chunk. * @returns {number} */ numValues() { const ret = wasm.columnchunkmetadata_numValues(this.__wbg_ptr); return ret; } /** * Compression for this column. * @returns {Compression} */ compression() { const ret = wasm.columnchunkmetadata_compression(this.__wbg_ptr); return ret; } /** * Returns the total compressed data size of this column chunk. * @returns {number} */ compressedSize() { const ret = wasm.columnchunkmetadata_compressedSize(this.__wbg_ptr); return ret; } /** * Returns the total uncompressed data size of this column chunk. * @returns {number} */ uncompressedSize() { const ret = wasm.columnchunkmetadata_uncompressedSize(this.__wbg_ptr); return ret; } } const FFIArrowArrayFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_ffiarrowarray_free(ptr >>> 0)); /** */ export class FFIArrowArray { __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; FFIArrowArrayFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_ffiarrowarray_free(ptr); } /** * @returns {number} */ addr() { const ret = wasm.ffiarrowarray_addr(this.__wbg_ptr); return ret >>> 0; } } const FFIArrowSchemaFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_ffiarrowschema_free(ptr >>> 0)); /** */ export class FFIArrowSchema { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(FFIArrowSchema.prototype); obj.__wbg_ptr = ptr; FFIArrowSchemaFinalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; FFIArrowSchemaFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_ffiarrowschema_free(ptr); } /** * Access the pointer to the * [`ArrowSchema`](https://arrow.apache.org/docs/format/CDataInterface.html#structure-definitions) * struct. This can be viewed or copied (without serialization) to an Arrow JS `Field` by * using [`arrow-js-ffi`](https://github.com/kylebarron/arrow-js-ffi). You can access the * [`WebAssembly.Memory`](https://developer.mozilla.org/en-US/docs/WebAssembly/JavaScript_interface/Memory) * instance by using {@linkcode wasmMemory}. * * **Example**: * * ```ts * import { parseRecordBatch } from "arrow-js-ffi"; * * const wasmRecordBatch: FFIRecordBatch = ... * const wasmMemory: WebAssembly.Memory = wasmMemory(); * * // Pass `true` to copy arrays across the boundary instead of creating views. * const jsRecordBatch = parseRecordBatch( * wasmMemory.buffer, * wasmRecordBatch.arrayAddr(), * wasmRecordBatch.schemaAddr(), * true * ); * ``` * @returns {number} */ addr() { const ret = wasm.ffiarrowschema_addr(this.__wbg_ptr); return ret >>> 0; } } const FFIDataFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_ffidata_free(ptr >>> 0)); /** * An Arrow array including associated field metadata. * * Using [`arrow-js-ffi`](https://github.com/kylebarron/arrow-js-ffi), you can view or copy Arrow * these objects to JavaScript. */ export class FFIData { __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; FFIDataFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_ffidata_free(ptr); } /** * @returns {number} */ arrayAddr() { const ret = wasm.ffiarrowschema_addr(this.__wbg_ptr); return ret >>> 0; } /** * @returns {number} */ schema_addr() { const ret = wasm.ffidata_schema_addr(this.__wbg_ptr); return ret >>> 0; } } const FFIRecordBatchFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_ffirecordbatch_free(ptr >>> 0)); /** * A representation of an Arrow RecordBatch in WebAssembly memory exposed as FFI-compatible * structs through the Arrow C Data Interface. */ export class FFIRecordBatch { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(FFIRecordBatch.prototype); obj.__wbg_ptr = ptr; FFIRecordBatchFinalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; FFIRecordBatchFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_ffirecordbatch_free(ptr); } /** * Access the pointer to the * [`ArrowArray`](https://arrow.apache.org/docs/format/CDataInterface.html#structure-definitions) * struct. This can be viewed or copied (without serialization) to an Arrow JS `RecordBatch` by * using [`arrow-js-ffi`](https://github.com/kylebarron/arrow-js-ffi). You can access the * [`WebAssembly.Memory`](https://developer.mozilla.org/en-US/docs/WebAssembly/JavaScript_interface/Memory) * instance by using {@linkcode wasmMemory}. * * **Example**: * * ```ts * import { parseRecordBatch } from "arrow-js-ffi"; * * const wasmRecordBatch: FFIRecordBatch = ... * const wasmMemory: WebAssembly.Memory = wasmMemory(); * * // Pass `true` to copy arrays across the boundary instead of creating views. * const jsRecordBatch = parseRecordBatch( * wasmMemory.buffer, * wasmRecordBatch.arrayAddr(), * wasmRecordBatch.schemaAddr(), * true * ); * ``` * @returns {number} */ arrayAddr() { const ret = wasm.ffirecordbatch_arrayAddr(this.__wbg_ptr); return ret >>> 0; } /** * Access the pointer to the * [`ArrowSchema`](https://arrow.apache.org/docs/format/CDataInterface.html#structure-definitions) * struct. This can be viewed or copied (without serialization) to an Arrow JS `Field` by * using [`arrow-js-ffi`](https://github.com/kylebarron/arrow-js-ffi). You can access the * [`WebAssembly.Memory`](https://developer.mozilla.org/en-US/docs/WebAssembly/JavaScript_interface/Memory) * instance by using {@linkcode wasmMemory}. * * **Example**: * * ```ts * import { parseRecordBatch } from "arrow-js-ffi"; * * const wasmRecordBatch: FFIRecordBatch = ... * const wasmMemory: WebAssembly.Memory = wasmMemory(); * * // Pass `true` to copy arrays across the boundary instead of creating views. * const jsRecordBatch = parseRecordBatch( * wasmMemory.buffer, * wasmRecordBatch.arrayAddr(), * wasmRecordBatch.schemaAddr(), * true * ); * ``` * @returns {number} */ schemaAddr() { const ret = wasm.ffirecordbatch_schemaAddr(this.__wbg_ptr); return ret >>> 0; } } const FFITableFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_ffitable_free(ptr >>> 0)); /** * A representation of an Arrow Table in WebAssembly memory exposed as FFI-compatible * structs through the Arrow C Data Interface. */ export class FFITable { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(FFITable.prototype); obj.__wbg_ptr = ptr; FFITableFinalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; FFITableFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_ffitable_free(ptr); } /** * Get the total number of record batches in the table * @returns {number} */ numBatches() { const ret = wasm.ffitable_numBatches(this.__wbg_ptr); return ret >>> 0; } /** * Get the pointer to one ArrowSchema FFI struct * @returns {number} */ schemaAddr() { const ret = wasm.ffitable_schemaAddr(this.__wbg_ptr); return ret >>> 0; } /** * Get the pointer to one ArrowArray FFI struct for a given chunk index and column index * * Access the pointer to one * [`ArrowArray`](https://arrow.apache.org/docs/format/CDataInterface.html#structure-definitions) * struct representing one of the internal `RecordBatch`es. This can be viewed or copied (without serialization) to an Arrow JS `RecordBatch` by * using [`arrow-js-ffi`](https://github.com/kylebarron/arrow-js-ffi). You can access the * [`WebAssembly.Memory`](https://developer.mozilla.org/en-US/docs/WebAssembly/JavaScript_interface/Memory) * instance by using {@linkcode wasmMemory}. * * **Example**: * * ```ts * import * as arrow from "apache-arrow"; * import { parseRecordBatch } from "arrow-js-ffi"; * * const wasmTable: FFITable = ... * const wasmMemory: WebAssembly.Memory = wasmMemory(); * * const jsBatches: arrow.RecordBatch[] = [] * for (let i = 0; i < wasmTable.numBatches(); i++) { * // Pass `true` to copy arrays across the boundary instead of creating views. * const jsRecordBatch = parseRecordBatch( * wasmMemory.buffer, * wasmTable.arrayAddr(i), * wasmTable.schemaAddr(), * true * ); * jsBatches.push(jsRecordBatch); * } * const jsTable = new arrow.Table(jsBatches); * ``` * * @param chunk number The chunk index to use * @returns number pointer to an ArrowArray FFI struct in Wasm memory * @param {number} chunk * @returns {number} */ arrayAddr(chunk) { const ret = wasm.ffitable_arrayAddr(this.__wbg_ptr, chunk); return ret >>> 0; } /** * @returns {Uint32Array} */ arrayAddrs() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.ffitable_arrayAddrs(retptr, this.__wbg_ptr); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var v1 = getArrayU32FromWasm0(r0, r1).slice(); wasm.__wbindgen_free(r0, r1 * 4, 4); return v1; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** */ drop() { const ptr = this.__destroy_into_raw(); wasm.ffitable_drop(ptr); } } const FFIVectorFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_ffivector_free(ptr >>> 0)); /** * A chunked Arrow array including associated field metadata */ export class FFIVector { __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; FFIVectorFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_ffivector_free(ptr); } /** * @returns {number} */ schemaAddr() { const ret = wasm.ffivector_schemaAddr(this.__wbg_ptr); return ret >>> 0; } /** * @param {number} i * @returns {number} */ arrayAddr(i) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.ffivector_arrayAddr(retptr, this.__wbg_ptr, i); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var r2 = getInt32Memory0()[retptr / 4 + 2]; if (r2) { throw takeObject(r1); } return r0 >>> 0; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } } const FileMetaDataFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_filemetadata_free(ptr >>> 0)); /** * Metadata for a Parquet file. */ export class FileMetaData { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(FileMetaData.prototype); obj.__wbg_ptr = ptr; FileMetaDataFinalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; FileMetaDataFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_filemetadata_free(ptr); } /** * Returns version of this file. * @returns {number} */ version() { const ret = wasm.filemetadata_version(this.__wbg_ptr); return ret; } /** * Returns number of rows in the file. * @returns {number} */ numRows() { const ret = wasm.filemetadata_numRows(this.__wbg_ptr); return ret; } /** * String message for application that wrote this file. * * This should have the following format: * `<application> version <application version> (build <application build hash>)`. * * ```shell * parquet-mr version 1.8.0 (build 0fda28af84b9746396014ad6a415b90592a98b3b) * ``` * @returns {string | undefined} */ createdBy() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.filemetadata_createdBy(retptr, this.__wbg_ptr); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; let v1; if (r0 !== 0) { v1 = getStringFromWasm0(r0, r1).slice(); wasm.__wbindgen_free(r0, r1 * 1, 1); } return v1; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Returns key_value_metadata of this file. * @returns {Map<any, any>} */ keyValueMetadata() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.filemetadata_keyValueMetadata(retptr, this.__wbg_ptr); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var r2 = getInt32Memory0()[retptr / 4 + 2]; if (r2) { throw takeObject(r1); } return takeObject(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } } const IntoUnderlyingByteSourceFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_intounderlyingbytesource_free(ptr >>> 0)); /** */ export class IntoUnderlyingByteSource { __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; IntoUnderlyingByteSourceFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_intounderlyingbytesource_free(ptr); } /** * @returns {string} */ get type() { let deferred1_0; let deferred1_1; try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.intounderlyingbytesource_type(retptr, this.__wbg_ptr); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; deferred1_0 = r0; deferred1_1 = r1; return getStringFromWasm0(r0, r1); } finally { wasm.__wbindgen_add_to_stack_pointer(16); wasm.__wbindgen_free(deferred1_0, deferred1_1, 1); } } /** * @returns {number} */ get autoAllocateChunkSize() { const ret = wasm.intounderlyingbytesource_autoAllocateChunkSize(this.__wbg_ptr); return ret >>> 0; } /** * @param {ReadableByteStreamController} controller */ start(controller) { wasm.intounderlyingbytesource_start(this.__wbg_ptr, addHeapObject(controller)); } /** * @param {ReadableByteStreamController} controller * @returns {Promise<any>} */ pull(controller) { const ret = wasm.intounderlyingbytesource_pull(this.__wbg_ptr, addHeapObject(controller)); return takeObject(ret); } /** */ cancel() { const ptr = this.__destroy_into_raw(); wasm.intounderlyingbytesource_cancel(ptr); } } const IntoUnderlyingSinkFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_intounderlyingsink_free(ptr >>> 0)); /** */ export class IntoUnderlyingSink { __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; IntoUnderlyingSinkFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_intounderlyingsink_free(ptr); } /** * @param {any} chunk * @returns {Promise<any>} */ write(chunk) { const ret = wasm.intounderlyingsink_write(this.__wbg_ptr, addHeapObject(chunk)); return takeObject(ret); } /** * @returns {Promise<any>} */ close() { const ptr = this.__destroy_into_raw(); const ret = wasm.intounderlyingsink_close(ptr); return takeObject(ret); } /** * @param {any} reason * @returns {Promise<any>} */ abort(reason) { const ptr = this.__destroy_into_raw(); const ret = wasm.intounderlyingsink_abort(ptr, addHeapObject(reason)); return takeObject(ret); } } const IntoUnderlyingSourceFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_intounderlyingsource_free(ptr >>> 0)); /** */ export class IntoUnderlyingSource { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(IntoUnderlyingSource.prototype); obj.__wbg_ptr = ptr; IntoUnderlyingSourceFinalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; IntoUnderlyingSourceFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_intounderlyingsource_free(ptr); } /** * @param {ReadableStreamDefaultController} controller * @returns {Promise<any>} */ pull(controller) { const ret = wasm.intounderlyingsource_pull(this.__wbg_ptr, addHeapObject(controller)); return takeObject(ret); } /** */ cancel() { const ptr = this.__destroy_into_raw(); wasm.intounderlyingsource_cancel(ptr); } } const ParquetFileFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_parquetfile_free(ptr >>> 0)); /** */ export class ParquetFile { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(ParquetFile.prototype); obj.__wbg_ptr = ptr; ParquetFileFinalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; ParquetFileFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_parquetfile_free(ptr); } /** * Construct a ParquetFile from a new URL. * * @param options The options to pass into `object-store`'s [`parse_url_opts`][parse_url_opts] * * [parse_url_opts]: https://docs.rs/object_store/latest/object_store/fn.parse_url_opts.html * @param {string} url * @param {Map<any, any> | undefined} [options] * @returns {Promise<ParquetFile>} */ static fromUrl(url, options) { const ptr0 = passStringToWasm0(url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; const ret = wasm.parquetfile_fromUrl(ptr0, len0, isLikeNone(options) ? 0 : addHeapObject(options)); return takeObject(ret); } /** * Construct a ParquetFile from a new [Blob] or [File] handle. * * [Blob]: https://developer.mozilla.org/en-US/docs/Web/API/Blob * [File]: https://developer.mozilla.org/en-US/docs/Web/API/File * * Safety: Do not use this in a multi-threaded environment, * (transitively depends on `!Send` `web_sys::Blob`) * @param {Blob} handle * @returns {Promise<ParquetFile>} */ static fromFile(handle) { const ret = wasm.parquetfile_fromFile(addHeapObject(handle)); return takeObject(ret); } /** * @returns {ParquetMetaData} */ metadata() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.parquetfile_metadata(retptr, this.__wbg_ptr); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var r2 = getInt32Memory0()[retptr / 4 + 2]; if (r2) { throw takeObject(r1); } return ParquetMetaData.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Read from the Parquet file in an async fashion. * * @param options * * Options for reading Parquet data. Optional keys include: * * - `batchSize`: The number of rows in each batch. If not provided, the upstream parquet * default is 1024. * - `rowGroups`: Only read data from the provided row group indexes. * - `limit`: Provide a limit to the number of rows to be read. * - `offset`: Provide an offset to skip over the given number of rows. * - `columns`: The column names from the file to read. * @param {ReaderOptions | undefined} [options] * @returns {Promise<Table>} */ read(options) { const ret = wasm.parquetfile_read(this.__wbg_ptr, isLikeNone(options) ? 0 : addHeapObject(options)); return takeObject(ret); } /** * Create a readable stream of record batches. * * Each item in the stream will be a {@linkcode RecordBatch}. * * @param options * * Options for reading Parquet data. Optional keys include: * * - `batchSize`: The number of rows in each batch. If not provided, the upstream parquet * default is 1024. * - `rowGroups`: Only read data from the provided row group indexes. * - `limit`: Provide a limit to the number of rows to be read. * - `offset`: Provide an offset to skip over the given number of rows. * - `columns`: The column names from the file to read. * - `concurrency`: The number of concurrent requests to make * @param {ReaderOptions | undefined} [options] * @returns {Promise<ReadableStream>} */ stream(options) { const ret = wasm.parquetfile_stream(this.__wbg_ptr, isLikeNone(options) ? 0 : addHeapObject(options)); return takeObject(ret); } } const ParquetMetaDataFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_parquetmetadata_free(ptr >>> 0)); /** * Global Parquet metadata. */ export class ParquetMetaData { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(ParquetMetaData.prototype); obj.__wbg_ptr = ptr; ParquetMetaDataFinalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; ParquetMetaDataFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_parquetmetadata_free(ptr); } /** * Returns file metadata as reference. * @returns {FileM