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AC,EAAE;YACb,WAAW,EAAE,IAAI,CAAC,SAAS;YAC3B,WAAW,EAAE,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC;SAC7C;KACJ,CAAC;AACN,CAAC;AAED,cAAc;AACd,SAAS,qBAAqB,CAAC,UAAkB,EAAE,EAAU,EAAE,OAAO,GAAG,KAAK;IAC1E,MAAM,KAAK,GAAG,IAAI,cAAK,CAAC,GAAG,EAAE,EAAE,EAAE,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC;IAC5E,MAAM,OAAO,GAAG,yCAAmB,CAAC,QAAQ,CAAC,IAAI,eAAM,CAAC,KAAK,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAC9E,OAAO,IAAI,CAAC,SAAS,CAAC;QAClB,IAAI,EAAE,EAAE;QACR,SAAS,EAAE,OAAO;QAClB,MAAM,EAAE;YACJ,OAAO,EAAE,UAAU,CAAC,MAAM;YAC1B,SAAS,EAAE,OAAO;SACrB;KACJ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AAChB,CAAC;AAED,cAAc;AACd,SAAS,iBAAiB,CAAC,OAAoB;IAC3C,OAAO,IAAI,CAAC,SAAS,CAAC;QAClB,OAAO,EAAE,OAAO,CAAC,MAAM;QACvB,SAAS,EAAE,yCAAmB,CAAC,QAAQ,CAAC,OAAO,CAAC;KACnD,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AAChB,CAAC","file":"writer.js","sourcesContent":["// Licensed to the Apache Software Foundation (ASF) under one\n// or more contributor license agreements. See the NOTICE file\n// distributed with this work for additional information\n// regarding copyright ownership. The ASF licenses this file\n// to you under the Apache License, Version 2.0 (the\n// \"License\"); you may not use this file except in compliance\n// with the License. You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing,\n// software distributed under the License is distributed on an\n// \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n// KIND, either express or implied. See the License for the\n// specific language governing permissions and limitations\n// under the License.\n\nimport { Table } from '../table';\nimport { MAGIC } from './message';\nimport { Vector } from '../vector';\nimport { Column } from '../column';\nimport { DataType } from '../type';\nimport { Schema, Field } from '../schema';\nimport { Message } from './metadata/message';\nimport * as metadata from './metadata/message';\nimport { FileBlock, Footer } from './metadata/file';\nimport { MessageHeader, MetadataVersion } from '../enum';\nimport { WritableSink, AsyncByteQueue } from '../io/stream';\nimport { VectorAssembler } from '../visitor/vectorassembler';\nimport { JSONTypeAssembler } from '../visitor/jsontypeassembler';\nimport { JSONVectorAssembler } from '../visitor/jsonvectorassembler';\nimport { ArrayBufferViewInput, toUint8Array } from '../util/buffer';\nimport { RecordBatch, _InternalEmptyPlaceholderRecordBatch } from '../recordbatch';\nimport { Writable, ReadableInterop, ReadableDOMStreamOptions } from '../io/interfaces';\nimport { isPromise, isAsyncIterable, isWritableDOMStream, isWritableNodeStream, isIterable, isObject } from '../util/compat';\n\nexport interface RecordBatchStreamWriterOptions {\n /**\n *\n */\n autoDestroy?: boolean;\n /**\n * A flag indicating whether the RecordBatchWriter should construct pre-0.15.0\n * encapsulated IPC Messages, which reserves 4 bytes for the Message metadata\n * length instead of 8.\n * @see https://issues.apache.org/jira/browse/ARROW-6313\n */\n writeLegacyIpcFormat?: boolean;\n}\n\nexport class RecordBatchWriter<T extends { [key: string]: DataType } = any> extends ReadableInterop<Uint8Array> implements Writable<RecordBatch<T>> {\n\n /** @nocollapse */\n // @ts-ignore\n public static throughNode(options?: import('stream').DuplexOptions & { autoDestroy: boolean }): import('stream').Duplex {\n throw new Error(`\"throughNode\" not available in this environment`);\n }\n /** @nocollapse */\n public static throughDOM<T extends { [key: string]: DataType }>(\n // @ts-ignore\n writableStrategy?: QueuingStrategy<RecordBatch<T>> & { autoDestroy: boolean },\n // @ts-ignore\n readableStrategy?: { highWaterMark?: number, size?: any }\n ): { writable: WritableStream<Table<T> | RecordBatch<T>>, readable: ReadableStream<Uint8Array> } {\n throw new Error(`\"throughDOM\" not available in this environment`);\n }\n\n constructor(options?: RecordBatchStreamWriterOptions) {\n super();\n isObject(options) || (options = { autoDestroy: true, writeLegacyIpcFormat: false });\n this._autoDestroy = (typeof options.autoDestroy === 'boolean') ? options.autoDestroy : true;\n this._writeLegacyIpcFormat = (typeof options.writeLegacyIpcFormat === 'boolean') ? options.writeLegacyIpcFormat : false;\n }\n\n protected _position = 0;\n protected _started = false;\n protected _autoDestroy: boolean;\n protected _writeLegacyIpcFormat: boolean;\n // @ts-ignore\n protected _sink = new AsyncByteQueue();\n protected _schema: Schema | null = null;\n protected _dictionaryBlocks: FileBlock[] = [];\n protected _recordBatchBlocks: FileBlock[] = [];\n protected _dictionaryDeltaOffsets = new Map<number, number>();\n\n public toString(sync: true): string;\n public toString(sync?: false): Promise<string>;\n public toString(sync: any = false) {\n return this._sink.toString(sync) as Promise<string> | string;\n }\n public toUint8Array(sync: true): Uint8Array;\n public toUint8Array(sync?: false): Promise<Uint8Array>;\n public toUint8Array(sync: any = false) {\n return this._sink.toUint8Array(sync) as Promise<Uint8Array> | Uint8Array;\n }\n\n public writeAll(input: Table<T> | Iterable<RecordBatch<T>>): this;\n public writeAll(input: AsyncIterable<RecordBatch<T>>): Promise<this>;\n public writeAll(input: PromiseLike<AsyncIterable<RecordBatch<T>>>): Promise<this>;\n public writeAll(input: PromiseLike<Table<T> | Iterable<RecordBatch<T>>>): Promise<this>;\n public writeAll(input: PromiseLike<any> | Table<T> | Iterable<RecordBatch<T>> | AsyncIterable<RecordBatch<T>>) {\n if (isPromise<any>(input)) {\n return input.then((x) => this.writeAll(x));\n } else if (isAsyncIterable<RecordBatch<T>>(input)) {\n return writeAllAsync(this, input);\n }\n return writeAll(this, <any> input);\n }\n\n public get closed() { return this._sink.closed; }\n public [Symbol.asyncIterator]() { return this._sink[Symbol.asyncIterator](); }\n public toDOMStream(options?: ReadableDOMStreamOptions) { return this._sink.toDOMStream(options); }\n public toNodeStream(options?: import('stream').ReadableOptions) { return this._sink.toNodeStream(options); }\n\n public close() {\n return this.reset()._sink.close();\n }\n public abort(reason?: any) {\n return this.reset()._sink.abort(reason);\n }\n public finish() {\n this._autoDestroy ? this.close() : this.reset(this._sink, this._schema);\n return this;\n }\n public reset(sink: WritableSink<ArrayBufferViewInput> = this._sink, schema: Schema<T> | null = null) {\n\n if ((sink === this._sink) || (sink instanceof AsyncByteQueue)) {\n this._sink = sink as AsyncByteQueue;\n } else {\n this._sink = new AsyncByteQueue();\n if (sink && isWritableDOMStream(sink)) {\n this.toDOMStream({ type: 'bytes' }).pipeTo(sink);\n } else if (sink && isWritableNodeStream(sink)) {\n this.toNodeStream({ objectMode: false }).pipe(sink);\n }\n }\n\n if (this._started && this._schema) {\n this._writeFooter(this._schema);\n }\n\n this._started = false;\n this._dictionaryBlocks = [];\n this._recordBatchBlocks = [];\n this._dictionaryDeltaOffsets = new Map();\n\n if (!schema || !(schema.compareTo(this._schema))) {\n if (schema === null) {\n this._position = 0;\n this._schema = null;\n } else {\n this._started = true;\n this._schema = schema;\n this._writeSchema(schema);\n }\n }\n\n return this;\n }\n\n public write(payload?: Table<T> | RecordBatch<T> | Iterable<RecordBatch<T>> | null) {\n\n let schema: Schema<T> | null = null;\n\n if (!this._sink) {\n throw new Error(`RecordBatchWriter is closed`);\n } else if (payload === null || payload === undefined) {\n return this.finish() && undefined;\n } else if (payload instanceof Table && !(schema = payload.schema)) {\n return this.finish() && undefined;\n } else if (payload instanceof RecordBatch && !(schema = payload.schema)) {\n return this.finish() && undefined;\n }\n\n if (schema && !schema.compareTo(this._schema)) {\n if (this._started && this._autoDestroy) {\n return this.close();\n }\n this.reset(this._sink, schema);\n }\n\n if (payload instanceof RecordBatch) {\n if (!(payload instanceof _InternalEmptyPlaceholderRecordBatch)) {\n this._writeRecordBatch(payload);\n }\n } else if (payload instanceof Table) {\n this.writeAll(payload.chunks);\n } else if (isIterable(payload)) {\n this.writeAll(payload);\n }\n }\n\n protected _writeMessage<T extends MessageHeader>(message: Message<T>, alignment = 8) {\n\n const a = alignment - 1;\n const buffer = Message.encode(message);\n const flatbufferSize = buffer.byteLength;\n const prefixSize = !this._writeLegacyIpcFormat ? 8 : 4;\n const alignedSize = (flatbufferSize + prefixSize + a) & ~a;\n const nPaddingBytes = alignedSize - flatbufferSize - prefixSize;\n\n if (message.headerType === MessageHeader.RecordBatch) {\n this._recordBatchBlocks.push(new FileBlock(alignedSize, message.bodyLength, this._position));\n } else if (message.headerType === MessageHeader.DictionaryBatch) {\n this._dictionaryBlocks.push(new FileBlock(alignedSize, message.bodyLength, this._position));\n }\n\n // If not in legacy pre-0.15.0 mode, write the stream continuation indicator\n if (!this._writeLegacyIpcFormat) {\n this._write(Int32Array.of(-1));\n }\n // Write the flatbuffer size prefix including padding\n this._write(Int32Array.of(alignedSize - prefixSize));\n // Write the flatbuffer\n if (flatbufferSize > 0) { this._write(buffer); }\n // Write any padding\n return this._writePadding(nPaddingBytes);\n }\n\n protected _write(chunk: ArrayBufferViewInput) {\n if (this._started) {\n const buffer = toUint8Array(chunk);\n if (buffer && buffer.byteLength > 0) {\n this._sink.write(buffer);\n this._position += buffer.byteLength;\n }\n }\n return this;\n }\n\n protected _writeSchema(schema: Schema<T>) {\n return this._writeMessage(Message.from(schema));\n }\n\n // @ts-ignore\n protected _writeFooter(schema: Schema<T>) {\n // eos bytes\n return this._writeLegacyIpcFormat\n ? this._write(Int32Array.of(0))\n : this._write(Int32Array.of(-1, 0));\n }\n\n protected _writeMagic() {\n return this._write(MAGIC);\n }\n\n protected _writePadding(nBytes: number) {\n return nBytes > 0 ? this._write(new Uint8Array(nBytes)) : this;\n }\n\n protected _writeRecordBatch(batch: RecordBatch<T>) {\n const { byteLength, nodes, bufferRegions, buffers } = VectorAssembler.assemble(batch);\n const recordBatch = new metadata.RecordBatch(batch.length, nodes, bufferRegions);\n const message = Message.from(recordBatch, byteLength);\n return this\n ._writeDictionaries(batch)\n ._writeMessage(message)\n ._writeBodyBuffers(buffers);\n }\n\n protected _writeDictionaryBatch(dictionary: Vector, id: number, isDelta = false) {\n this._dictionaryDeltaOffsets.set(id, dictionary.length + (this._dictionaryDeltaOffsets.get(id) || 0));\n const { byteLength, nodes, bufferRegions, buffers } = VectorAssembler.assemble(dictionary);\n const recordBatch = new metadata.RecordBatch(dictionary.length, nodes, bufferRegions);\n const dictionaryBatch = new metadata.DictionaryBatch(recordBatch, id, isDelta);\n const message = Message.from(dictionaryBatch, byteLength);\n return this\n ._writeMessage(message)\n ._writeBodyBuffers(buffers);\n }\n\n protected _writeBodyBuffers(buffers: ArrayBufferView[]) {\n let buffer: ArrayBufferView;\n let size: number, padding: number;\n for (let i = -1, n = buffers.length; ++i < n;) {\n if ((buffer = buffers[i]) && (size = buffer.byteLength) > 0) {\n this._write(buffer);\n if ((padding = ((size + 7) & ~7) - size) > 0) {\n this._writePadding(padding);\n }\n }\n }\n return this;\n }\n\n protected _writeDictionaries(batch: RecordBatch<T>) {\n for (let [id, dictionary] of batch.dictionaries) {\n let offset = this._dictionaryDeltaOffsets.get(id) || 0;\n if (offset === 0 || (dictionary = dictionary.slice(offset)).length > 0) {\n const chunks = 'chunks' in dictionary ? (dictionary as any).chunks : [dictionary];\n for (const chunk of chunks) {\n this._writeDictionaryBatch(chunk, id, offset > 0);\n offset += chunk.length;\n }\n }\n }\n return this;\n }\n}\n\n/** @ignore */\nexport class RecordBatchStreamWriter<T extends { [key: string]: DataType } = any> extends RecordBatchWriter<T> {\n public static writeAll<T extends { [key: string]: DataType } = any>(input: Table<T> | Iterable<RecordBatch<T>>, options?: RecordBatchStreamWriterOptions): RecordBatchStreamWriter<T>;\n public static writeAll<T extends { [key: string]: DataType } = any>(input: AsyncIterable<RecordBatch<T>>, options?: RecordBatchStreamWriterOptions): Promise<RecordBatchStreamWriter<T>>;\n public static writeAll<T extends { [key: string]: DataType } = any>(input: PromiseLike<AsyncIterable<RecordBatch<T>>>, options?: RecordBatchStreamWriterOptions): Promise<RecordBatchStreamWriter<T>>;\n public static writeAll<T extends { [key: string]: DataType } = any>(input: PromiseLike<Table<T> | Iterable<RecordBatch<T>>>, options?: RecordBatchStreamWriterOptions): Promise<RecordBatchStreamWriter<T>>;\n /** @nocollapse */\n public static writeAll<T extends { [key: string]: DataType } = any>(input: any, options?: RecordBatchStreamWriterOptions) {\n const writer = new RecordBatchStreamWriter<T>(options);\n if (isPromise<any>(input)) {\n return input.then((x) => writer.writeAll(x));\n } else if (isAsyncIterable<RecordBatch<T>>(input)) {\n return writeAllAsync(writer, input);\n }\n return writeAll(writer, input);\n }\n}\n\n/** @ignore */\nexport class RecordBatchFileWriter<T extends { [key: string]: DataType } = any> extends RecordBatchWriter<T> {\n public static writeAll<T extends { [key: string]: DataType } = any>(input: Table<T> | Iterable<RecordBatch<T>>): RecordBatchFileWriter<T>;\n public static writeAll<T extends { [key: string]: DataType } = any>(input: AsyncIterable<RecordBatch<T>>): Promise<RecordBatchFileWriter<T>>;\n public static writeAll<T extends { [key: string]: DataType } = any>(input: PromiseLike<AsyncIterable<RecordBatch<T>>>): Promise<RecordBatchFileWriter<T>>;\n public static writeAll<T extends { [key: string]: DataType } = any>(input: PromiseLike<Table<T> | Iterable<RecordBatch<T>>>): Promise<RecordBatchFileWriter<T>>;\n /** @nocollapse */\n public static writeAll<T extends { [key: string]: DataType } = any>(input: any) {\n const writer = new RecordBatchFileWriter<T>();\n if (isPromise<any>(input)) {\n return input.then((x) => writer.writeAll(x));\n } else if (isAsyncIterable<RecordBatch<T>>(input)) {\n return writeAllAsync(writer, input);\n }\n return writeAll(writer, input);\n }\n\n constructor() {\n super();\n this._autoDestroy = true;\n }\n\n // @ts-ignore\n protected _writeSchema(schema: Schema<T>) {\n return this._writeMagic()._writePadding(2);\n }\n\n protected _writeFooter(schema: Schema<T>) {\n const buffer = Footer.encode(new Footer(\n schema, MetadataVersion.V4,\n this._recordBatchBlocks, this._dictionaryBlocks\n ));\n return super\n ._writeFooter(schema) // EOS bytes for sequential readers\n ._write(buffer) // Write the flatbuffer\n ._write(Int32Array.of(buffer.byteLength)) // then the footer size suffix\n ._writeMagic(); // then the magic suffix\n }\n}\n\n/** @ignore */\nexport class RecordBatchJSONWriter<T extends { [key: string]: DataType } = any> extends RecordBatchWriter<T> {\n\n public static writeAll<T extends { [key: string]: DataType } = any>(this: typeof RecordBatchWriter, input: Table<T> | Iterable<RecordBatch<T>>): RecordBatchJSONWriter<T>;\n // @ts-ignore\n public static writeAll<T extends { [key: string]: DataType } = any>(this: typeof RecordBatchWriter, input: AsyncIterable<RecordBatch<T>>): Promise<RecordBatchJSONWriter<T>>;\n public static writeAll<T extends { [key: string]: DataType } = any>(this: typeof RecordBatchWriter, input: PromiseLike<AsyncIterable<RecordBatch<T>>>): Promise<RecordBatchJSONWriter<T>>;\n public static writeAll<T extends { [key: string]: DataType } = any>(this: typeof RecordBatchWriter, input: PromiseLike<Table<T> | Iterable<RecordBatch<T>>>): Promise<RecordBatchJSONWriter<T>>;\n /** @nocollapse */\n public static writeAll<T extends { [key: string]: DataType } = any>(this: typeof RecordBatchWriter, input: any) {\n return new RecordBatchJSONWriter<T>().writeAll(input as any);\n }\n\n private _recordBatches: RecordBatch[];\n private _dictionaries: RecordBatch[];\n\n constructor() {\n super();\n this._autoDestroy = true;\n this._recordBatches = [];\n this._dictionaries = [];\n }\n\n protected _writeMessage() { return this; }\n // @ts-ignore\n protected _writeFooter(schema: Schema<T>) { return this; }\n protected _writeSchema(schema: Schema<T>) {\n return this._write(`{\\n \"schema\": ${\n JSON.stringify({ fields: schema.fields.map(fieldToJSON) }, null, 2)\n }`);\n }\n protected _writeDictionaries(batch: RecordBatch<T>) {\n if (batch.dictionaries.size > 0) {\n this._dictionaries.push(batch);\n }\n return this;\n }\n protected _writeDictionaryBatch(dictionary: Vector, id: number, isDelta = false) {\n this._dictionaryDeltaOffsets.set(id, dictionary.length + (this._dictionaryDeltaOffsets.get(id) || 0));\n this._write(this._dictionaryBlocks.length === 0 ? ` ` : `,\\n `);\n this._write(`${dictionaryBatchToJSON(dictionary, id, isDelta)}`);\n this._dictionaryBlocks.push(new FileBlock(0, 0, 0));\n return this;\n }\n protected _writeRecordBatch(batch: RecordBatch<T>) {\n this._writeDictionaries(batch);\n this._recordBatches.push(batch);\n return this;\n }\n public close() {\n\n if (this._dictionaries.length > 0) {\n this._write(`,\\n \"dictionaries\": [\\n`);\n for (const batch of this._dictionaries) {\n super._writeDictionaries(batch);\n }\n this._write(`\\n ]`);\n }\n\n if (this._recordBatches.length > 0) {\n for (let i = -1, n = this._recordBatches.length; ++i < n;) {\n this._write(i === 0 ? `,\\n \"batches\": [\\n ` : `,\\n `);\n this._write(`${recordBatchToJSON(this._recordBatches[i])}`);\n this._recordBatchBlocks.push(new FileBlock(0, 0, 0));\n }\n this._write(`\\n ]`);\n }\n\n if (this._schema) {\n this._write(`\\n}`);\n }\n\n this._dictionaries = [];\n this._recordBatches = [];\n\n return super.close();\n }\n}\n\n/** @ignore */\nfunction writeAll<T extends { [key: string]: DataType } = any>(writer: RecordBatchWriter<T>, input: Table<T> | Iterable<RecordBatch<T>>) {\n let chunks = input as Iterable<RecordBatch<T>>;\n if (input instanceof Table) {\n chunks = input.chunks;\n writer.reset(undefined, input.schema);\n }\n for (const batch of chunks) {\n writer.write(batch);\n }\n return writer.finish();\n}\n\n/** @ignore */\nasync function writeAllAsync<T extends { [key: string]: DataType } = any>(writer: RecordBatchWriter<T>, batches: AsyncIterable<RecordBatch<T>>) {\n for await (const batch of batches) {\n writer.write(batch);\n }\n return writer.finish();\n}\n\n/** @ignore */\nfunction fieldToJSON({ name, type, nullable }: Field): object {\n const assembler = new JSONTypeAssembler();\n return {\n 'name': name, 'nullable': nullable,\n 'type': assembler.visit(type),\n 'children': (type.children || []).map(fieldToJSON),\n 'dictionary': !DataType.isDictionary(type) ? undefined : {\n 'id': type.id,\n 'isOrdered': type.isOrdered,\n 'indexType': assembler.visit(type.indices)\n }\n };\n}\n\n/** @ignore */\nfunction dictionaryBatchToJSON(dictionary: Vector, id: number, isDelta = false) {\n const field = new Field(`${id}`, dictionary.type, dictionary.nullCount > 0);\n const columns = JSONVectorAssembler.assemble(new Column(field, [dictionary]));\n return JSON.stringify({\n 'id': id,\n 'isDelta': isDelta,\n 'data': {\n 'count': dictionary.length,\n 'columns': columns\n }\n }, null, 2);\n}\n\n/** @ignore */\nfunction recordBatchToJSON(records: RecordBatch) {\n return JSON.stringify({\n 'count': records.length,\n 'columns': JSONVectorAssembler.assemble(records)\n }, null, 2);\n}\n"]} |