UNPKG

apache-arrow

Version:

Apache Arrow columnar in-memory format

133 lines (131 loc) 4.99 kB
"use strict"; // automatically generated by the FlatBuffers compiler, do not modify Object.defineProperty(exports, "__esModule", { value: true }); exports.Schema = void 0; const flatbuffers = require("flatbuffers"); const endianness_js_1 = require("./endianness.js"); const field_js_1 = require("./field.js"); const key_value_js_1 = require("./key-value.js"); /** * ---------------------------------------------------------------------- * A Schema describes the columns in a row batch */ class Schema { constructor() { this.bb = null; this.bb_pos = 0; } __init(i, bb) { this.bb_pos = i; this.bb = bb; return this; } static getRootAsSchema(bb, obj) { return (obj || new Schema()).__init(bb.readInt32(bb.position()) + bb.position(), bb); } static getSizePrefixedRootAsSchema(bb, obj) { bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); return (obj || new Schema()).__init(bb.readInt32(bb.position()) + bb.position(), bb); } /** * endianness of the buffer * it is Little Endian by default * if endianness doesn't match the underlying system then the vectors need to be converted */ endianness() { const offset = this.bb.__offset(this.bb_pos, 4); return offset ? this.bb.readInt16(this.bb_pos + offset) : endianness_js_1.Endianness.Little; } fields(index, obj) { const offset = this.bb.__offset(this.bb_pos, 6); return offset ? (obj || new field_js_1.Field()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; } fieldsLength() { const offset = this.bb.__offset(this.bb_pos, 6); return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; } customMetadata(index, obj) { const offset = this.bb.__offset(this.bb_pos, 8); return offset ? (obj || new key_value_js_1.KeyValue()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; } customMetadataLength() { const offset = this.bb.__offset(this.bb_pos, 8); return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; } /** * Features used in the stream/file. */ features(index) { const offset = this.bb.__offset(this.bb_pos, 10); return offset ? this.bb.readInt64(this.bb.__vector(this.bb_pos + offset) + index * 8) : BigInt(0); } featuresLength() { const offset = this.bb.__offset(this.bb_pos, 10); return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; } static startSchema(builder) { builder.startObject(4); } static addEndianness(builder, endianness) { builder.addFieldInt16(0, endianness, endianness_js_1.Endianness.Little); } static addFields(builder, fieldsOffset) { builder.addFieldOffset(1, fieldsOffset, 0); } static createFieldsVector(builder, data) { builder.startVector(4, data.length, 4); for (let i = data.length - 1; i >= 0; i--) { builder.addOffset(data[i]); } return builder.endVector(); } static startFieldsVector(builder, numElems) { builder.startVector(4, numElems, 4); } static addCustomMetadata(builder, customMetadataOffset) { builder.addFieldOffset(2, customMetadataOffset, 0); } static createCustomMetadataVector(builder, data) { builder.startVector(4, data.length, 4); for (let i = data.length - 1; i >= 0; i--) { builder.addOffset(data[i]); } return builder.endVector(); } static startCustomMetadataVector(builder, numElems) { builder.startVector(4, numElems, 4); } static addFeatures(builder, featuresOffset) { builder.addFieldOffset(3, featuresOffset, 0); } static createFeaturesVector(builder, data) { builder.startVector(8, data.length, 8); for (let i = data.length - 1; i >= 0; i--) { builder.addInt64(data[i]); } return builder.endVector(); } static startFeaturesVector(builder, numElems) { builder.startVector(8, numElems, 8); } static endSchema(builder) { const offset = builder.endObject(); return offset; } static finishSchemaBuffer(builder, offset) { builder.finish(offset); } static finishSizePrefixedSchemaBuffer(builder, offset) { builder.finish(offset, undefined, true); } static createSchema(builder, endianness, fieldsOffset, customMetadataOffset, featuresOffset) { Schema.startSchema(builder); Schema.addEndianness(builder, endianness); Schema.addFields(builder, fieldsOffset); Schema.addCustomMetadata(builder, customMetadataOffset); Schema.addFeatures(builder, featuresOffset); return Schema.endSchema(builder); } } exports.Schema = Schema; //# sourceMappingURL=schema.js.map