Skip to content

Commit

Permalink
ARROW-2640: [JS] Write schema metadata
Browse files Browse the repository at this point in the history
Forgot to serialize schema metadata. Resolves https://issues.apache.org/jira/browse/ARROW-2640

Author: ptaylor <[email protected]>

Closes apache#2086 from trxcllnt/js-write-schema-metadata and squashes the following commits:

953232c <ptaylor> write schema metadata
  • Loading branch information
trxcllnt authored and wesm committed Jun 4, 2018
1 parent 44bfd0d commit 9aa7c52
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions js/src/ipc/writer/binary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,14 +588,34 @@ function writeMessage(b: Builder, node: Message) {
}

function writeSchema(b: Builder, node: Schema) {

const fieldOffsets = node.fields.map((f) => writeField(b, f));
const fieldsOffset =
_Schema.startFieldsVector(b, fieldOffsets.length) ||
_Schema.createFieldsVector(b, fieldOffsets);

let metadata: number | undefined = undefined;
if (node.metadata && node.metadata.size > 0) {
metadata = _Schema.createCustomMetadataVector(
b,
[...node.metadata].map(([k, v]) => {
const key = b.createString(`${k}`);
const val = b.createString(`${v}`);
return (
_KeyValue.startKeyValue(b) ||
_KeyValue.addKey(b, key) ||
_KeyValue.addValue(b, val) ||
_KeyValue.endKeyValue(b)
);
})
);
}

return (
_Schema.startSchema(b) ||
_Schema.addFields(b, fieldsOffset) ||
_Schema.addEndianness(b, platformIsLittleEndian ? _Endianness.Little : _Endianness.Big) ||
(metadata !== undefined && _Schema.addCustomMetadata(b, metadata)) ||
_Schema.endSchema(b)
);
}
Expand Down Expand Up @@ -662,8 +682,8 @@ function writeField(b: Builder, node: Field) {
metadata = _Field.createCustomMetadataVector(
b,
[...node.metadata].map(([k, v]) => {
const key = b.createString(k);
const val = b.createString(v);
const key = b.createString(`${k}`);
const val = b.createString(`${v}`);
return (
_KeyValue.startKeyValue(b) ||
_KeyValue.addKey(b, key) ||
Expand Down

0 comments on commit 9aa7c52

Please sign in to comment.