UNPKG

apache-arrow

Version:

Apache Arrow columnar in-memory format

135 lines (133 loc) 4.95 kB
"use strict"; // automatically generated by the FlatBuffers compiler, do not modify Object.defineProperty(exports, "__esModule", { value: true }); exports.Field = void 0; const flatbuffers = require("flatbuffers"); const dictionary_encoding_js_1 = require("./dictionary-encoding.js"); const key_value_js_1 = require("./key-value.js"); const type_js_1 = require("./type.js"); /** * ---------------------------------------------------------------------- * A field represents a named column in a record / row batch or child of a * nested type. */ class Field { constructor() { this.bb = null; this.bb_pos = 0; } __init(i, bb) { this.bb_pos = i; this.bb = bb; return this; } static getRootAsField(bb, obj) { return (obj || new Field()).__init(bb.readInt32(bb.position()) + bb.position(), bb); } static getSizePrefixedRootAsField(bb, obj) { bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); return (obj || new Field()).__init(bb.readInt32(bb.position()) + bb.position(), bb); } name(optionalEncoding) { const offset = this.bb.__offset(this.bb_pos, 4); return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; } /** * Whether or not this field can contain nulls. Should be true in general. */ nullable() { const offset = this.bb.__offset(this.bb_pos, 6); return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false; } typeType() { const offset = this.bb.__offset(this.bb_pos, 8); return offset ? this.bb.readUint8(this.bb_pos + offset) : type_js_1.Type.NONE; } /** * This is the type of the decoded value if the field is dictionary encoded. */ type(obj) { const offset = this.bb.__offset(this.bb_pos, 10); return offset ? this.bb.__union(obj, this.bb_pos + offset) : null; } /** * Present only if the field is dictionary encoded. */ dictionary(obj) { const offset = this.bb.__offset(this.bb_pos, 12); return offset ? (obj || new dictionary_encoding_js_1.DictionaryEncoding()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; } /** * children apply only to nested data types like Struct, List and Union. For * primitive types children will have length 0. */ children(index, obj) { const offset = this.bb.__offset(this.bb_pos, 14); return offset ? (obj || new Field()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; } childrenLength() { const offset = this.bb.__offset(this.bb_pos, 14); return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; } /** * User-defined metadata */ customMetadata(index, obj) { const offset = this.bb.__offset(this.bb_pos, 16); 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, 16); return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; } static startField(builder) { builder.startObject(7); } static addName(builder, nameOffset) { builder.addFieldOffset(0, nameOffset, 0); } static addNullable(builder, nullable) { builder.addFieldInt8(1, +nullable, +false); } static addTypeType(builder, typeType) { builder.addFieldInt8(2, typeType, type_js_1.Type.NONE); } static addType(builder, typeOffset) { builder.addFieldOffset(3, typeOffset, 0); } static addDictionary(builder, dictionaryOffset) { builder.addFieldOffset(4, dictionaryOffset, 0); } static addChildren(builder, childrenOffset) { builder.addFieldOffset(5, childrenOffset, 0); } static createChildrenVector(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 startChildrenVector(builder, numElems) { builder.startVector(4, numElems, 4); } static addCustomMetadata(builder, customMetadataOffset) { builder.addFieldOffset(6, 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 endField(builder) { const offset = builder.endObject(); return offset; } } exports.Field = Field; //# sourceMappingURL=field.js.map