Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/ipc/writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,11 @@ export class RecordBatchFileWriter<T extends TypeMap = any> extends RecordBatchW
this._writeLegacyIpcFormat = false;
}

// @ts-ignore
protected _writeSchema(schema: Schema<T>) {
return this._writeMagic()._writePadding(2);
// The file format embeds a complete IPC stream after the leading
// magic and padding, so the Schema message has to be written here too.
this._writeMagic()._writePadding(2);
return super._writeSchema(schema);
}

protected _writeDictionaryBatch(dictionary: Data, id: number, isDelta = false) {
Expand Down
18 changes: 18 additions & 0 deletions test/unit/ipc/writer/file-writer-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
RecordBatch,
RecordBatchFileWriter,
RecordBatchReader,
RecordBatchStreamReader,
Table,
tableFromArrays,
Uint32,
Expand Down Expand Up @@ -134,6 +135,23 @@ describe('RecordBatchFileWriter', () => {
expect(dictionary).toBeInstanceOf(Vector);
expect(dictionary.data).toHaveLength(20);
});

describe('embedded IPC stream', () => {
const cases: [string, Table][] = [
['all types', generate.table([10, 20, 30]).table],
['dictionaries', generateDictionaryTables([10, 20, 30]).next().value!],
];
for (const [name, source] of cases) {
it(`can be read by a stream reader after the leading magic (${name})`, async () => {
const bytes = await RecordBatchFileWriter.writeAll(source).toUint8Array();
// Skip the leading "ARROW1" magic and its two bytes of padding.
const reader = RecordBatchStreamReader.from(bytes.subarray(FILE_FORMAT_HEADER_LENGTH));
const result = new Table(reader);
expect(result.schema.fields).toHaveLength(source.schema.fields.length);
expect(result).toEqualTable(source);
});
}
});
});

function testFileWriter(table: Table, name: string, options?: RecordBatchStreamWriterOptions) {
Expand Down