You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2017/06/02 18:17:23 UTC
arrow git commit: ARROW-990: [JS] Add tslint support for linting
TypeScript
Repository: arrow
Updated Branches:
refs/heads/master 5c155c353 -> 092afb6dc
ARROW-990: [JS] Add tslint support for linting TypeScript
Added tslint config and `npm run tslint` script. Modified current code to pass lint tests.
Currently the config disables the bitwise operation and max classes per file checks. I also ignored the long line test for all of the nullable primitive vectors, since that should be replaced anyway in the near future.
Author: Brian Hulette <br...@ccri.com>
Closes #718 from TheNeuralBit/tslint and squashes the following commits:
727d80f2 [Brian Hulette] added npm lint script
68b7c8fc [Brian Hulette] misc tslint fixes
6f1583e5 [Brian Hulette] sort object literals
67d82cac [Brian Hulette] variable names, object shorthand
0a1b872f [Brian Hulette] fix public, private, protected ordering issues
08d60e67 [Brian Hulette] quotes, equality checks
c5d85f77 [Brian Hulette] whitespace, semicolons, Errors
2b4ff287 [Brian Hulette] added public, private, protected to all members
81c9868a [Brian Hulette] Replace vars with let/const, one def per line
d591b3c7 [Brian Hulette] add tslint config
Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/092afb6d
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/092afb6d
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/092afb6d
Branch: refs/heads/master
Commit: 092afb6dc561161019990f3e8f0c88b56e6e5120
Parents: 5c155c3
Author: Brian Hulette <br...@ccri.com>
Authored: Fri Jun 2 14:06:03 2017 -0400
Committer: Wes McKinney <we...@twosigma.com>
Committed: Fri Jun 2 14:06:03 2017 -0400
----------------------------------------------------------------------
js/README.md | 1 +
js/package.json | 4 +-
js/src/arrow.ts | 316 ++++++++++++++++++++-----------------
js/src/bitarray.ts | 18 +--
js/src/types.ts | 410 ++++++++++++++++++++++++------------------------
js/tslint.json | 12 ++
6 files changed, 403 insertions(+), 358 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/arrow/blob/092afb6d/js/README.md
----------------------------------------------------------------------
diff --git a/js/README.md b/js/README.md
index 167bafc..de9070c 100644
--- a/js/README.md
+++ b/js/README.md
@@ -18,6 +18,7 @@ From this directory, run:
``` bash
$ npm install # pull dependencies
+$ npm run lint -- <filename> # run tslint
$ npm run build # build typescript (run tsc and webpack)
$ npm run test # run the unit tests (node.js only)
```
http://git-wip-us.apache.org/repos/asf/arrow/blob/092afb6d/js/package.json
----------------------------------------------------------------------
diff --git a/js/package.json b/js/package.json
index 1739e38..e46b5bd 100644
--- a/js/package.json
+++ b/js/package.json
@@ -6,7 +6,8 @@
"scripts": {
"build": "./flatbuffers.sh && tsc && tsc -m es6 --outDir lib-esm && webpack",
"clean": "rm -rf lib lib-esm _bundles",
- "test": "./node_modules/mocha/bin/mocha ./spec/arrow.js"
+ "test": "./node_modules/mocha/bin/mocha ./spec/arrow.js",
+ "lint": "./node_modules/tslint/bin/tslint"
},
"author": "",
"repository": "https://github.com/apache/arrow/",
@@ -15,6 +16,7 @@
"awesome-typescript-loader": "^3.1.3",
"chai": "^3.5.0",
"mocha": "^3.3.0",
+ "tslint": "^5.3.2",
"typescript": "^2.3.2",
"uglifyjs-webpack-plugin": "^0.4.3",
"webpack": "^2.3.3"
http://git-wip-us.apache.org/repos/asf/arrow/blob/092afb6d/js/src/arrow.ts
----------------------------------------------------------------------
diff --git a/js/src/arrow.ts b/js/src/arrow.ts
index 74def4d..ac87a8c 100644
--- a/js/src/arrow.ts
+++ b/js/src/arrow.ts
@@ -15,19 +15,19 @@
// specific language governing permissions and limitations
// under the License.
-import { flatbuffers } from 'flatbuffers';
-import { org } from './Arrow_generated';
-import { vectorFromField, Vector } from './types';
+import { flatbuffers } from "flatbuffers";
+import { org } from "./Arrow_generated";
+import { Vector, vectorFromField } from "./types";
import ByteBuffer = flatbuffers.ByteBuffer;
-var Footer = org.apache.arrow.flatbuf.Footer;
-var Message = org.apache.arrow.flatbuf.Message;
-var MessageHeader = org.apache.arrow.flatbuf.MessageHeader;
-var RecordBatch = org.apache.arrow.flatbuf.RecordBatch;
-var DictionaryBatch = org.apache.arrow.flatbuf.DictionaryBatch;
-var Schema = org.apache.arrow.flatbuf.Schema;
-var Type = org.apache.arrow.flatbuf.Type;
-var VectorType = org.apache.arrow.flatbuf.VectorType;
+const Footer = org.apache.arrow.flatbuf.Footer;
+const Message = org.apache.arrow.flatbuf.Message;
+const MessageHeader = org.apache.arrow.flatbuf.MessageHeader;
+const RecordBatch = org.apache.arrow.flatbuf.RecordBatch;
+const DictionaryBatch = org.apache.arrow.flatbuf.DictionaryBatch;
+const Schema = org.apache.arrow.flatbuf.Schema;
+const Type = org.apache.arrow.flatbuf.Type;
+const VectorType = org.apache.arrow.flatbuf.VectorType;
export class ArrowReader {
@@ -43,16 +43,16 @@ export class ArrowReader {
this.bb = bb;
this.schema = schema;
this.vectors = vectors;
- for (var i = 0; i < vectors.length; i += 1|0) {
- this.vectorMap[vectors[i].name] = vectors[i]
+ for (let i = 0; i < vectors.length; i++) {
+ this.vectorMap[vectors[i].name] = vectors[i];
}
this.batches = batches;
this.dictionaries = dictionaries;
}
- loadNextBatch() {
+ public loadNextBatch() {
if (this.batchIndex < this.batches.length) {
- var batch = this.batches[this.batchIndex];
+ const batch = this.batches[this.batchIndex];
this.batchIndex += 1;
loadVectors(this.bb, this.vectors, batch);
return batch.length;
@@ -61,36 +61,36 @@ export class ArrowReader {
}
}
- getSchema() {
+ public getSchema() {
return this.schema;
}
- getVectors() {
+ public getVectors() {
return this.vectors;
}
- getVector(name) {
+ public getVector(name) {
return this.vectorMap[name];
}
- getBatchCount() {
+ public getBatchCount() {
return this.batches.length;
}
// the index of the next batch to be loaded
- getBatchIndex() {
+ public getBatchIndex() {
return this.batchIndex;
}
// set the index of the next batch to be loaded
- setBatchIndex(i: number) {
+ public setBatchIndex(i: number) {
this.batchIndex = i;
}
}
export function getSchema(buf) { return getReader(buf).getSchema(); }
-export function getReader(buf) : ArrowReader {
+export function getReader(buf): ArrowReader {
if (_checkMagic(buf, 0)) {
return getFileReader(buf);
} else {
@@ -98,20 +98,20 @@ export function getReader(buf) : ArrowReader {
}
}
-export function getStreamReader(buf) : ArrowReader {
- var bb = new ByteBuffer(buf);
+export function getStreamReader(buf): ArrowReader {
+ const bb = new ByteBuffer(buf);
- var schema = _loadSchema(bb),
- field,
- vectors: Vector[] = [],
- i,j,
- iLen,jLen,
- batch,
- recordBatches = [],
- dictionaryBatches = [],
- dictionaries = {};
+ const schema = _loadSchema(bb);
+ let field;
+ const vectors: Vector[] = [];
+ let i;
+ let iLen;
+ let batch;
+ const recordBatches = [];
+ const dictionaryBatches = [];
+ const dictionaries = {};
- for (i = 0, iLen = schema.fieldsLength(); i < iLen; i += 1|0) {
+ for (i = 0, iLen = schema.fieldsLength(); i < iLen; i++) {
field = schema.fields(i);
_createDictionaryVectors(field, dictionaries);
vectors.push(vectorFromField(field, dictionaries));
@@ -121,18 +121,18 @@ export function getStreamReader(buf) : ArrowReader {
batch = _loadBatch(bb);
if (batch == null) {
break;
- } else if (batch.type == MessageHeader.DictionaryBatch) {
+ } else if (batch.type === MessageHeader.DictionaryBatch) {
dictionaryBatches.push(batch);
- } else if (batch.type == MessageHeader.RecordBatch) {
- recordBatches.push(batch)
+ } else if (batch.type === MessageHeader.RecordBatch) {
+ recordBatches.push(batch);
} else {
- console.error("Expected batch type" + MessageHeader.RecordBatch + " or " +
+ throw new Error("Expected batch type" + MessageHeader.RecordBatch + " or " +
MessageHeader.DictionaryBatch + " but got " + batch.type);
}
}
// load dictionary vectors
- for (i = 0; i < dictionaryBatches.length; i += 1|0) {
+ for (i = 0; i < dictionaryBatches.length; i++) {
batch = dictionaryBatches[i];
loadVectors(bb, [dictionaries[batch.id]], batch);
}
@@ -140,58 +140,60 @@ export function getStreamReader(buf) : ArrowReader {
return new ArrowReader(bb, parseSchema(schema), vectors, recordBatches, dictionaries);
}
-export function getFileReader (buf) : ArrowReader {
- var bb = new ByteBuffer(buf);
+export function getFileReader(buf): ArrowReader {
+ const bb = new ByteBuffer(buf);
- var footer = _loadFooter(bb);
+ const footer = _loadFooter(bb);
- var schema = footer.schema();
- var i, len, field,
- vectors: Vector[] = [],
- block,
- batch,
- recordBatchBlocks = [],
- dictionaryBatchBlocks = [],
- dictionaries = {};
+ const schema = footer.schema();
+ let i;
+ let len;
+ let field;
+ const vectors: Vector[] = [];
+ let block;
+ let batch;
+ const recordBatchBlocks = [];
+ const dictionaryBatchBlocks = [];
+ const dictionaries = {};
- for (i = 0, len = schema.fieldsLength(); i < len; i += 1|0) {
+ for (i = 0, len = schema.fieldsLength(); i < len; i++) {
field = schema.fields(i);
_createDictionaryVectors(field, dictionaries);
vectors.push(vectorFromField(field, dictionaries));
}
- for (i = 0; i < footer.dictionariesLength(); i += 1|0) {
+ for (i = 0; i < footer.dictionariesLength(); i++) {
block = footer.dictionaries(i);
dictionaryBatchBlocks.push({
- offset: block.offset().low,
- metaDataLength: block.metaDataLength(),
bodyLength: block.bodyLength().low,
- })
+ metaDataLength: block.metaDataLength(),
+ offset: block.offset().low,
+ });
}
- for (i = 0; i < footer.recordBatchesLength(); i += 1|0) {
+ for (i = 0; i < footer.recordBatchesLength(); i++) {
block = footer.recordBatches(i);
recordBatchBlocks.push({
- offset: block.offset().low,
- metaDataLength: block.metaDataLength(),
bodyLength: block.bodyLength().low,
- })
+ metaDataLength: block.metaDataLength(),
+ offset: block.offset().low,
+ });
}
- var dictionaryBatches = dictionaryBatchBlocks.map(function (block) {
- bb.setPosition(block.offset);
+ const dictionaryBatches = dictionaryBatchBlocks.map((batchBlock) => {
+ bb.setPosition(batchBlock.offset);
// TODO: Make sure this is a dictionary batch
return _loadBatch(bb);
});
- var recordBatches = recordBatchBlocks.map(function (block) {
- bb.setPosition(block.offset);
+ const recordBatches = recordBatchBlocks.map((batchBlock) => {
+ bb.setPosition(batchBlock.offset);
// TODO: Make sure this is a record batch
return _loadBatch(bb);
});
// load dictionary vectors
- for (i = 0; i < dictionaryBatches.length; i += 1|0) {
+ for (i = 0; i < dictionaryBatches.length; i++) {
batch = dictionaryBatches[i];
loadVectors(bb, [dictionaries[batch.id]], batch);
}
@@ -200,107 +202,124 @@ export function getFileReader (buf) : ArrowReader {
}
function _loadFooter(bb) {
- var fileLength: number = bb.bytes_.length;
+ const fileLength: number = bb.bytes_.length;
- if (fileLength < MAGIC.length*2 + 4) {
- console.error("file too small " + fileLength);
- return;
+ if (fileLength < MAGIC.length * 2 + 4) {
+ throw new Error("file too small " + fileLength);
}
if (!_checkMagic(bb.bytes_, 0)) {
- console.error("missing magic bytes at beginning of file")
- return;
+ throw new Error("missing magic bytes at beginning of file");
}
if (!_checkMagic(bb.bytes_, fileLength - MAGIC.length)) {
- console.error("missing magic bytes at end of file")
- return;
+ throw new Error("missing magic bytes at end of file");
}
- var footerLengthOffset: number = fileLength - MAGIC.length - 4;
+ const footerLengthOffset: number = fileLength - MAGIC.length - 4;
bb.setPosition(footerLengthOffset);
- var footerLength: number = Int32FromByteBuffer(bb, footerLengthOffset)
+ const footerLength: number = Int32FromByteBuffer(bb, footerLengthOffset);
- if (footerLength <= 0 || footerLength + MAGIC.length*2 + 4 > fileLength) {
- console.log("Invalid footer length: " + footerLength)
+ if (footerLength <= 0 || footerLength + MAGIC.length * 2 + 4 > fileLength) {
+ throw new Error("Invalid footer length: " + footerLength);
}
- var footerOffset: number = footerLengthOffset - footerLength;
+ const footerOffset: number = footerLengthOffset - footerLength;
bb.setPosition(footerOffset);
- var footer = Footer.getRootAsFooter(bb);
+ const footer = Footer.getRootAsFooter(bb);
return footer;
}
function _loadSchema(bb) {
- var message =_loadMessage(bb);
- if (message.headerType() != MessageHeader.Schema) {
- console.error("Expected header type " + MessageHeader.Schema + " but got " + message.headerType());
- return;
+ const message = _loadMessage(bb);
+ if (message.headerType() !== MessageHeader.Schema) {
+ throw new Error("Expected header type " + MessageHeader.Schema + " but got " + message.headerType());
}
return message.header(new Schema());
}
function _loadBatch(bb) {
- var message = _loadMessage(bb);
+ const message = _loadMessage(bb);
if (message == null) {
return;
- } else if (message.headerType() == MessageHeader.RecordBatch) {
- var batch = { header: message.header(new RecordBatch()), length: message.bodyLength().low }
+ } else if (message.headerType() === MessageHeader.RecordBatch) {
+ const batch = { header: message.header(new RecordBatch()), length: message.bodyLength().low };
return _loadRecordBatch(bb, batch);
- } else if (message.headerType() == MessageHeader.DictionaryBatch) {
- var batch = { header: message.header(new DictionaryBatch()), length: message.bodyLength().low }
+ } else if (message.headerType() === MessageHeader.DictionaryBatch) {
+ const batch = { header: message.header(new DictionaryBatch()), length: message.bodyLength().low };
return _loadDictionaryBatch(bb, batch);
} else {
- console.error("Expected header type " + MessageHeader.RecordBatch + " or " + MessageHeader.DictionaryBatch +
+ throw new Error("Expected header type " + MessageHeader.RecordBatch + " or " + MessageHeader.DictionaryBatch +
" but got " + message.headerType());
- return;
}
}
function _loadRecordBatch(bb, batch) {
- var data = batch.header;
- var i, nodes_ = [], nodesLength = data.nodesLength();
- var buffer, buffers_ = [], buffersLength = data.buffersLength();
+ const data = batch.header;
+ let i;
+ const nodesLength = data.nodesLength();
+ const nodes = new Array(nodesLength);
+ let buffer;
+ const buffersLength = data.buffersLength();
+ const buffers = new Array(buffersLength);
for (i = 0; i < nodesLength; i += 1) {
- nodes_.push(data.nodes(i));
+ nodes[i] = data.nodes(i);
}
+
for (i = 0; i < buffersLength; i += 1) {
buffer = data.buffers(i);
- buffers_.push({ offset: bb.position() + buffer.offset().low, length: buffer.length().low });
+ buffers[i] = {
+ length: buffer.length().low,
+ offset: bb.position() + buffer.offset().low,
+ };
}
// position the buffer after the body to read the next message
bb.setPosition(bb.position() + batch.length);
- return { nodes: nodes_, buffers: buffers_, length: data.length().low, type: MessageHeader.RecordBatch };
+ return { nodes, buffers, length: data.length().low, type: MessageHeader.RecordBatch };
}
function _loadDictionaryBatch(bb, batch) {
- var id_ = batch.header.id().toFloat64().toString(), data = batch.header.data();
- var i, nodes_ = [], nodesLength = data.nodesLength();
- var buffer, buffers_ = [], buffersLength = data.buffersLength();
+ const id = batch.header.id().toFloat64().toString();
+ const data = batch.header.data();
+ let i;
+ const nodesLength = data.nodesLength();
+ const nodes = new Array(nodesLength);
+ let buffer;
+ const buffersLength = data.buffersLength();
+ const buffers = new Array(buffersLength);
for (i = 0; i < nodesLength; i += 1) {
- nodes_.push(data.nodes(i));
+ nodes[i] = data.nodes(i);
}
for (i = 0; i < buffersLength; i += 1) {
buffer = data.buffers(i);
- buffers_.push({ offset: bb.position() + buffer.offset().low, length: buffer.length().low });
+ buffers[i] = {
+ length: buffer.length().low,
+ offset: bb.position() + buffer.offset().low,
+ };
}
// position the buffer after the body to read the next message
bb.setPosition(bb.position() + batch.length);
- return { id: id_, nodes: nodes_, buffers: buffers_, length: data.length().low, type: MessageHeader.DictionaryBatch };
+ return {
+ buffers,
+ id,
+ length: data.length().low,
+ nodes,
+ type: MessageHeader.DictionaryBatch,
+ };
}
function _loadMessage(bb) {
- var messageLength: number = Int32FromByteBuffer(bb, bb.position());
- if (messageLength == 0) {
+ const messageLength: number = Int32FromByteBuffer(bb, bb.position());
+ if (messageLength === 0) {
return;
}
bb.setPosition(bb.position() + 4);
- var message = Message.getRootAsMessage(bb);
+ const message = Message.getRootAsMessage(bb);
// position the buffer at the end of the message so it's ready to read further
bb.setPosition(bb.position() + messageLength);
@@ -308,36 +327,36 @@ function _loadMessage(bb) {
}
function _createDictionaryVectors(field, dictionaries) {
- var encoding = field.dictionary();
+ const encoding = field.dictionary();
if (encoding != null) {
- var id = encoding.id().toFloat64().toString();
+ const id = encoding.id().toFloat64().toString();
if (dictionaries[id] == null) {
// create a field for the dictionary
- var dictionaryField = _createDictionaryField(id, field);
+ const dictionaryField = _createDictionaryField(id, field);
dictionaries[id] = vectorFromField(dictionaryField, null);
}
}
// recursively examine child fields
- for (var i = 0, len = field.childrenLength(); i < len; i += 1|0) {
+ for (let i = 0, len = field.childrenLength(); i < len; i++) {
_createDictionaryVectors(field.children(i), dictionaries);
}
}
function _createDictionaryField(id, field) {
- var builder = new flatbuffers.Builder();
- var nameOffset = builder.createString("dict-" + id);
+ const builder = new flatbuffers.Builder();
+ const nameOffset = builder.createString("dict-" + id);
- var typeType = field.typeType();
- var typeOffset;
+ const typeType = field.typeType();
+ let typeOffset;
if (typeType === Type.Int) {
- var type = field.type(new org.apache.arrow.flatbuf.Int());
+ const type = field.type(new org.apache.arrow.flatbuf.Int());
org.apache.arrow.flatbuf.Int.startInt(builder);
org.apache.arrow.flatbuf.Int.addBitWidth(builder, type.bitWidth());
org.apache.arrow.flatbuf.Int.addIsSigned(builder, type.isSigned());
typeOffset = org.apache.arrow.flatbuf.Int.endInt(builder);
} else if (typeType === Type.FloatingPoint) {
- var type = field.type(new org.apache.arrow.flatbuf.FloatingPoint());
+ const type = field.type(new org.apache.arrow.flatbuf.FloatingPoint());
org.apache.arrow.flatbuf.FloatingPoint.startFloatingPoint(builder);
org.apache.arrow.flatbuf.FloatingPoint.addPrecision(builder, type.precision());
typeOffset = org.apache.arrow.flatbuf.FloatingPoint.endFloatingPoint(builder);
@@ -345,27 +364,28 @@ function _createDictionaryField(id, field) {
org.apache.arrow.flatbuf.Utf8.startUtf8(builder);
typeOffset = org.apache.arrow.flatbuf.Utf8.endUtf8(builder);
} else if (typeType === Type.Date) {
- var type = field.type(new org.apache.arrow.flatbuf.Date());
+ const type = field.type(new org.apache.arrow.flatbuf.Date());
org.apache.arrow.flatbuf.Date.startDate(builder);
org.apache.arrow.flatbuf.Date.addUnit(builder, type.unit());
typeOffset = org.apache.arrow.flatbuf.Date.endDate(builder);
} else {
- throw "Unimplemented dictionary type " + typeType;
+ throw new Error("Unimplemented dictionary type " + typeType);
}
if (field.childrenLength() > 0) {
- throw "Dictionary encoded fields can't have children"
+ throw new Error("Dictionary encoded fields can't have children");
}
- var childrenOffset = org.apache.arrow.flatbuf.Field.createChildrenVector(builder, []);
+ const childrenOffset = org.apache.arrow.flatbuf.Field.createChildrenVector(builder, []);
- var layout, layoutOffsets = [];
- for (var i = 0, len = field.layoutLength(); i < len; i += 1|0) {
+ let layout;
+ const layoutOffsets = [];
+ for (let i = 0, len = field.layoutLength(); i < len; i++) {
layout = field.layout(i);
org.apache.arrow.flatbuf.VectorLayout.startVectorLayout(builder);
org.apache.arrow.flatbuf.VectorLayout.addBitWidth(builder, layout.bitWidth());
org.apache.arrow.flatbuf.VectorLayout.addType(builder, layout.type());
layoutOffsets.push(org.apache.arrow.flatbuf.VectorLayout.endVectorLayout(builder));
}
- var layoutOffset = org.apache.arrow.flatbuf.Field.createLayoutVector(builder, layoutOffsets);
+ const layoutOffset = org.apache.arrow.flatbuf.Field.createLayoutVector(builder, layoutOffsets);
org.apache.arrow.flatbuf.Field.startField(builder);
org.apache.arrow.flatbuf.Field.addName(builder, nameOffset);
@@ -374,7 +394,7 @@ function _createDictionaryField(id, field) {
org.apache.arrow.flatbuf.Field.addType(builder, typeOffset);
org.apache.arrow.flatbuf.Field.addChildren(builder, childrenOffset);
org.apache.arrow.flatbuf.Field.addLayout(builder, layoutOffset);
- var offset = org.apache.arrow.flatbuf.Field.endField(builder);
+ const offset = org.apache.arrow.flatbuf.Field.endField(builder);
builder.finish(offset);
return org.apache.arrow.flatbuf.Field.getRootAsField(builder.bb);
@@ -387,22 +407,22 @@ function Int32FromByteBuffer(bb, offset) {
((bb.bytes_[offset] & 255));
}
-var MAGIC_STR = "ARROW1";
-var MAGIC = new Uint8Array(MAGIC_STR.length);
-for (var i = 0; i < MAGIC_STR.length; i += 1|0) {
+const MAGIC_STR = "ARROW1";
+const MAGIC = new Uint8Array(MAGIC_STR.length);
+for (let i = 0; i < MAGIC_STR.length; i++) {
MAGIC[i] = MAGIC_STR.charCodeAt(i);
}
function _checkMagic(buf, index) {
- for (var i = 0; i < MAGIC.length; i += 1|0) {
- if (MAGIC[i] != buf[index + i]) {
+ for (let i = 0; i < MAGIC.length; i++) {
+ if (MAGIC[i] !== buf[index + i]) {
return false;
}
}
return true;
}
-var TYPEMAP = {}
+const TYPEMAP = {};
TYPEMAP[Type.NONE] = "NONE";
TYPEMAP[Type.Null] = "Null";
TYPEMAP[Type.Int] = "Int";
@@ -420,45 +440,44 @@ TYPEMAP[Type.FixedSizeList] = "FixedSizeList";
TYPEMAP[Type.Struct_] = "Struct";
TYPEMAP[Type.Union] = "Union";
-var VECTORTYPEMAP = {};
-VECTORTYPEMAP[VectorType.OFFSET] = 'OFFSET';
-VECTORTYPEMAP[VectorType.DATA] = 'DATA';
-VECTORTYPEMAP[VectorType.VALIDITY] = 'VALIDITY';
-VECTORTYPEMAP[VectorType.TYPE] = 'TYPE';
+const VECTORTYPEMAP = {};
+VECTORTYPEMAP[VectorType.OFFSET] = "OFFSET";
+VECTORTYPEMAP[VectorType.DATA] = "DATA";
+VECTORTYPEMAP[VectorType.VALIDITY] = "VALIDITY";
+VECTORTYPEMAP[VectorType.TYPE] = "TYPE";
function parseField(field) {
- var children = [];
- for (var i = 0; i < field.childrenLength(); i += 1|0) {
+ const children = [];
+ for (let i = 0; i < field.childrenLength(); i++) {
children.push(parseField(field.children(i)));
}
- var layouts = [];
- for (var i = 0; i < field.layoutLength(); i += 1|0) {
+ const layouts = [];
+ for (let i = 0; i < field.layoutLength(); i++) {
layouts.push(VECTORTYPEMAP[field.layout(i).type()]);
}
return {
+ children,
+ layout: layouts,
name: field.name(),
nullable: field.nullable(),
type: TYPEMAP[field.typeType()],
- children: children,
- layout: layouts
};
}
function parseSchema(schema) {
- var result = [];
- var this_result, type;
- for (var i = 0, len = schema.fieldsLength(); i < len; i += 1|0) {
+ const result = [];
+ for (let i = 0, len = schema.fieldsLength(); i < len; i++) {
result.push(parseField(schema.fields(i)));
}
return result;
}
function loadVectors(bb, vectors: Vector[], recordBatch) {
- var indices = { bufferIndex: 0, nodeIndex: 0 }, i;
- for (i = 0; i < vectors.length; i += 1) {
- loadVector(bb, vectors[i], recordBatch, indices);
+ const indices = { bufferIndex: 0, nodeIndex: 0 };
+ for (const vector of vectors) {
+ loadVector(bb, vector, recordBatch, indices);
}
}
@@ -467,7 +486,10 @@ function loadVectors(bb, vectors: Vector[], recordBatch) {
* recordBatch: { nodes: org.apache.arrow.flatbuf.FieldNode[], buffers: { offset: number, length: number }[] }
*/
function loadVector(bb, vector: Vector, recordBatch, indices) {
- var node = recordBatch.nodes[indices.nodeIndex], ownBuffersLength, ownBuffers = [], i;
+ const node = recordBatch.nodes[indices.nodeIndex];
+ let ownBuffersLength;
+ const ownBuffers = [];
+ let i;
indices.nodeIndex += 1;
// dictionary vectors are always ints, so will have a data vector plus optional null vector
@@ -486,7 +508,7 @@ function loadVector(bb, vector: Vector, recordBatch, indices) {
vector.loadData(bb, node, ownBuffers);
- var children = vector.getChildVectors();
+ const children = vector.getChildVectors();
for (i = 0; i < children.length; i++) {
loadVector(bb, children[i], recordBatch, indices);
}
http://git-wip-us.apache.org/repos/asf/arrow/blob/092afb6d/js/src/bitarray.ts
----------------------------------------------------------------------
diff --git a/js/src/bitarray.ts b/js/src/bitarray.ts
index fc3c091..6b0a91a 100644
--- a/js/src/bitarray.ts
+++ b/js/src/bitarray.ts
@@ -22,21 +22,21 @@ export class BitArray {
this.view = new Uint8Array(buffer, offset || 0, Math.ceil(length / 8));
}
- get(i) {
- var index = (i >> 3) | 0; // | 0 converts to an int. Math.floor works too.
- var bit = i % 8; // i % 8 is just as fast as i & 7
+ public get(i) {
+ const index = (i >> 3) | 0; // | 0 converts to an int. Math.floor works too.
+ const bit = i % 8; // i % 8 is just as fast as i & 7
return (this.view[index] & (1 << bit)) !== 0;
}
- set(i) {
- var index = (i >> 3) | 0;
- var bit = i % 8;
+ public set(i) {
+ const index = (i >> 3) | 0;
+ const bit = i % 8;
this.view[index] |= 1 << bit;
}
- unset(i) {
- var index = (i >> 3) | 0;
- var bit = i % 8;
+ public unset(i) {
+ const index = (i >> 3) | 0;
+ const bit = i % 8;
this.view[index] &= ~(1 << bit);
}
}
http://git-wip-us.apache.org/repos/asf/arrow/blob/092afb6d/js/src/types.ts
----------------------------------------------------------------------
diff --git a/js/src/types.ts b/js/src/types.ts
index d656c6a..c541098 100644
--- a/js/src/types.ts
+++ b/js/src/types.ts
@@ -15,22 +15,50 @@
// specific language governing permissions and limitations
// under the License.
-import { BitArray } from './bitarray';
-import { TextDecoder } from 'text-encoding';
-import { org } from './Arrow_generated';
+import { org } from "./Arrow_generated";
+import { BitArray } from "./bitarray";
-var Type = org.apache.arrow.flatbuf.Type;
+import { TextDecoder } from "text-encoding";
-interface ArrayView {
- slice(start: number, end: number) : ArrayView
- toString() : string
+const Type = org.apache.arrow.flatbuf.Type;
+
+interface IArrayView {
+ slice(start: number, end: number): IArrayView;
+ toString(): string;
+}
+
+interface IViewConstructor<T extends IArrayView> {
+ BYTES_PER_ELEMENT: number;
+ new(buffer: any, offset: number, length: number): T;
}
export abstract class Vector {
- field: any;
- name: string;
- length: number;
- null_count: number;
+ /**
+ * Helper function for loading a VALIDITY buffer (for Nullable types)
+ * bb: flatbuffers.ByteBuffer
+ * buffer: org.apache.arrow.flatbuf.Buffer
+ */
+ public static loadValidityBuffer(bb, buffer): BitArray {
+ const arrayBuffer = bb.bytes_.buffer;
+ const offset = bb.bytes_.byteOffset + buffer.offset;
+ return new BitArray(arrayBuffer, offset, buffer.length * 8);
+ }
+
+ /**
+ * Helper function for loading an OFFSET buffer
+ * buffer: org.apache.arrow.flatbuf.Buffer
+ */
+ public static loadOffsetBuffer(bb, buffer): Int32Array {
+ const arrayBuffer = bb.bytes_.buffer;
+ const offset = bb.bytes_.byteOffset + buffer.offset;
+ const length = buffer.length / Int32Array.BYTES_PER_ELEMENT;
+ return new Int32Array(arrayBuffer, offset, length);
+ }
+
+ public field: any;
+ public name: string;
+ public length: number;
+ public nullCount: number;
constructor(field) {
this.field = field;
@@ -38,11 +66,13 @@ export abstract class Vector {
}
/* Access datum at index i */
- abstract get(i);
+ public abstract get(i);
/* Return array representing data in the range [start, end) */
- abstract slice(start: number, end: number);
+ public abstract slice(start: number, end: number);
/* Return array of child vectors, for container types */
- abstract getChildVectors();
+ public getChildVectors() {
+ return [];
+ }
/**
* Use recordBatch fieldNodes and Buffers to construct this Vector
@@ -52,85 +82,58 @@ export abstract class Vector {
*/
public loadData(bb, node, buffers) {
this.length = node.length().low;
- this.null_count = node.nullCount().low;
+ this.nullCount = node.nullCount().low;
this.loadBuffers(bb, node, buffers);
}
protected abstract loadBuffers(bb, node, buffers);
-
- /**
- * Helper function for loading a VALIDITY buffer (for Nullable types)
- * bb: flatbuffers.ByteBuffer
- * buffer: org.apache.arrow.flatbuf.Buffer
- */
- static loadValidityBuffer(bb, buffer) : BitArray {
- var arrayBuffer = bb.bytes_.buffer;
- var offset = bb.bytes_.byteOffset + buffer.offset;
- return new BitArray(arrayBuffer, offset, buffer.length * 8);
- }
-
- /**
- * Helper function for loading an OFFSET buffer
- * buffer: org.apache.arrow.flatbuf.Buffer
- */
- static loadOffsetBuffer(bb, buffer) : Int32Array {
- var arrayBuffer = bb.bytes_.buffer;
- var offset = bb.bytes_.byteOffset + buffer.offset;
- var length = buffer.length / Int32Array.BYTES_PER_ELEMENT;
- return new Int32Array(arrayBuffer, offset, length);
- }
-
}
-class SimpleVector<T extends ArrayView> extends Vector {
+class SimpleVector<T extends IArrayView> extends Vector {
protected dataView: T;
- private TypedArray: { new(buffer: any, offset: number, length: number): T, BYTES_PER_ELEMENT: number };
+ private TypedArray: IViewConstructor<T>;
- constructor (field, TypedArray: { new(buffer: any, offset: number, length: number): T, BYTES_PER_ELEMENT: number }) {
+ constructor(field, TypedArray: IViewConstructor<T>) {
super(field);
this.TypedArray = TypedArray;
}
- getChildVectors() {
- return [];
- }
-
- get(i) {
+ public get(i) {
return this.dataView[i];
}
- loadBuffers(bb, node, buffers) {
- this.loadDataBuffer(bb, buffers[0]);
+ public getDataView() {
+ return this.dataView;
}
- /**
- * buffer: org.apache.arrow.flatbuf.Buffer
- */
- protected loadDataBuffer(bb, buffer) {
- var arrayBuffer = bb.bytes_.buffer;
- var offset = bb.bytes_.byteOffset + buffer.offset;
- var length = buffer.length / this.TypedArray.BYTES_PER_ELEMENT;
- this.dataView = new this.TypedArray(arrayBuffer, offset, length);
+ public toString() {
+ return this.dataView.toString();
}
- getDataView() {
- return this.dataView;
+ public slice(start, end) {
+ return this.dataView.slice(start, end);
}
- toString() {
- return this.dataView.toString();
+ protected loadBuffers(bb, node, buffers) {
+ this.loadDataBuffer(bb, buffers[0]);
}
- slice(start, end) {
- return this.dataView.slice(start, end);
+ /*
+ * buffer: org.apache.arrow.flatbuf.Buffer
+ */
+ protected loadDataBuffer(bb, buffer) {
+ const arrayBuffer = bb.bytes_.buffer;
+ const offset = bb.bytes_.byteOffset + buffer.offset;
+ const length = buffer.length / this.TypedArray.BYTES_PER_ELEMENT;
+ this.dataView = new this.TypedArray(arrayBuffer, offset, length);
}
-}
-class NullableSimpleVector<T extends ArrayView> extends SimpleVector<T> {
+}
+class NullableSimpleVector<T extends IArrayView> extends SimpleVector<T> {
protected validityView: BitArray;
- get(i: number) {
+ public get(i: number) {
if (this.validityView.get(i)) {
return this.dataView[i];
} else {
@@ -138,40 +141,42 @@ class NullableSimpleVector<T extends ArrayView> extends SimpleVector<T> {
}
}
- loadBuffers(bb, node, buffers) {
- this.validityView = Vector.loadValidityBuffer(bb, buffers[0]);
- this.loadDataBuffer(bb, buffers[1]);
+ public getValidityVector() {
+ return this.validityView;
}
- getValidityVector() {
- return this.validityView;
+ protected loadBuffers(bb, node, buffers) {
+ this.validityView = Vector.loadValidityBuffer(bb, buffers[0]);
+ this.loadDataBuffer(bb, buffers[1]);
}
}
-class Uint8Vector extends SimpleVector<Uint8Array> { constructor(field) { super(field, Uint8Array); }; }
-class Uint16Vector extends SimpleVector<Uint16Array> { constructor(field) { super(field, Uint16Array); }; }
-class Uint32Vector extends SimpleVector<Uint32Array> { constructor(field) { super(field, Uint32Array); }; }
-class Int8Vector extends SimpleVector<Uint8Array> { constructor(field) { super(field, Uint8Array); }; }
-class Int16Vector extends SimpleVector<Uint16Array> { constructor(field) { super(field, Uint16Array); }; }
-class Int32Vector extends SimpleVector<Uint32Array> { constructor(field) { super(field, Uint32Array); }; }
-class Float32Vector extends SimpleVector<Float32Array> { constructor(field) { super(field, Float32Array); }; }
-class Float64Vector extends SimpleVector<Float64Array> { constructor(field) { super(field, Float64Array); }; }
-
-class NullableUint8Vector extends NullableSimpleVector<Uint8Array> { constructor(field) { super(field, Uint8Array); }; }
-class NullableUint16Vector extends NullableSimpleVector<Uint16Array> { constructor(field) { super(field, Uint16Array); }; }
-class NullableUint32Vector extends NullableSimpleVector<Uint32Array> { constructor(field) { super(field, Uint32Array); }; }
-class NullableInt8Vector extends NullableSimpleVector<Uint8Array> { constructor(field) { super(field, Uint8Array); }; }
-class NullableInt16Vector extends NullableSimpleVector<Uint16Array> { constructor(field) { super(field, Uint16Array); }; }
-class NullableInt32Vector extends NullableSimpleVector<Uint32Array> { constructor(field) { super(field, Uint32Array); }; }
-class NullableFloat32Vector extends NullableSimpleVector<Float32Array> { constructor(field) { super(field, Float32Array); }; }
-class NullableFloat64Vector extends NullableSimpleVector<Float64Array> { constructor(field) { super(field, Float64Array); }; }
+/* tslint:disable max-line-length */
+class Uint8Vector extends SimpleVector<Uint8Array> { constructor(field) { super(field, Uint8Array); } }
+class Uint16Vector extends SimpleVector<Uint16Array> { constructor(field) { super(field, Uint16Array); } }
+class Uint32Vector extends SimpleVector<Uint32Array> { constructor(field) { super(field, Uint32Array); } }
+class Int8Vector extends SimpleVector<Uint8Array> { constructor(field) { super(field, Uint8Array); } }
+class Int16Vector extends SimpleVector<Uint16Array> { constructor(field) { super(field, Uint16Array); } }
+class Int32Vector extends SimpleVector<Uint32Array> { constructor(field) { super(field, Uint32Array); } }
+class Float32Vector extends SimpleVector<Float32Array> { constructor(field) { super(field, Float32Array); } }
+class Float64Vector extends SimpleVector<Float64Array> { constructor(field) { super(field, Float64Array); } }
+
+class NullableUint8Vector extends NullableSimpleVector<Uint8Array> { constructor(field) { super(field, Uint8Array); } }
+class NullableUint16Vector extends NullableSimpleVector<Uint16Array> { constructor(field) { super(field, Uint16Array); } }
+class NullableUint32Vector extends NullableSimpleVector<Uint32Array> { constructor(field) { super(field, Uint32Array); } }
+class NullableInt8Vector extends NullableSimpleVector<Uint8Array> { constructor(field) { super(field, Uint8Array); } }
+class NullableInt16Vector extends NullableSimpleVector<Uint16Array> { constructor(field) { super(field, Uint16Array); } }
+class NullableInt32Vector extends NullableSimpleVector<Uint32Array> { constructor(field) { super(field, Uint32Array); } }
+class NullableFloat32Vector extends NullableSimpleVector<Float32Array> { constructor(field) { super(field, Float32Array); } }
+class NullableFloat64Vector extends NullableSimpleVector<Float64Array> { constructor(field) { super(field, Float64Array); } }
+/* tslint:enable max-line-length */
class Uint64Vector extends SimpleVector<Uint32Array> {
constructor(field) {
super(field, Uint32Array);
}
- get(i: number) {
+ public get(i: number) {
return { low: this.dataView[i * 2], high: this.dataView[(i * 2) + 1] };
}
}
@@ -181,7 +186,7 @@ class NullableUint64Vector extends NullableSimpleVector<Uint32Array> {
super(field, Uint32Array);
}
- get(i: number) {
+ public get(i: number) {
if (this.validityView.get(i)) {
return { low: this.dataView[i * 2], high: this.dataView[(i * 2) + 1] };
} else {
@@ -195,7 +200,7 @@ class Int64Vector extends NullableSimpleVector<Uint32Array> {
super(field, Uint32Array);
}
- get(i: number) {
+ public get(i: number) {
return { low: this.dataView[i * 2], high: this.dataView[(i * 2) + 1] };
}
}
@@ -205,7 +210,7 @@ class NullableInt64Vector extends NullableSimpleVector<Uint32Array> {
super(field, Uint32Array);
}
- get(i: number) {
+ public get(i: number) {
if (this.validityView.get(i)) {
return { low: this.dataView[i * 2], high: this.dataView[(i * 2) + 1] };
} else {
@@ -219,20 +224,15 @@ class DateVector extends SimpleVector<Uint32Array> {
super(field, Uint32Array);
}
- get (i) {
- return new Date(super.get(2*i+1)*Math.pow(2,32) + super.get(2*i));
+ public get(i) {
+ return new Date(super.get(2 * i + 1) * Math.pow(2, 32) + super.get(2 * i));
}
}
class NullableDateVector extends DateVector {
private validityView: BitArray;
- loadBuffers(bb, node, buffers) {
- this.validityView = Vector.loadValidityBuffer(bb, buffers[0]);
- this.loadDataBuffer(bb, buffers[1]);
- }
-
- get (i) {
+ public get(i) {
if (this.validityView.get(i)) {
return super.get(i);
} else {
@@ -240,51 +240,51 @@ class NullableDateVector extends DateVector {
}
}
- getValidityVector() {
+ public getValidityVector() {
return this.validityView;
}
+
+ protected loadBuffers(bb, node, buffers) {
+ this.validityView = Vector.loadValidityBuffer(bb, buffers[0]);
+ this.loadDataBuffer(bb, buffers[1]);
+ }
}
class Utf8Vector extends SimpleVector<Uint8Array> {
+ private static decoder: TextDecoder = new TextDecoder("utf8");
+
protected offsetView: Int32Array;
- static decoder: TextDecoder = new TextDecoder('utf8');
constructor(field) {
super(field, Uint8Array);
}
- loadBuffers(bb, node, buffers) {
- this.offsetView = Vector.loadOffsetBuffer(bb, buffers[0]);
- this.loadDataBuffer(bb, buffers[1]);
- }
-
- get(i) {
+ public get(i) {
return Utf8Vector.decoder.decode(this.dataView.slice(this.offsetView[i], this.offsetView[i + 1]));
}
- slice(start: number, end: number) {
- var result: string[] = [];
- for (var i: number = start; i < end; i += 1|0) {
+ public slice(start: number, end: number) {
+ const result: string[] = [];
+ for (let i: number = start; i < end; i++) {
result.push(this.get(i));
}
return result;
}
- getOffsetView() {
+ public getOffsetView() {
return this.offsetView;
}
+
+ protected loadBuffers(bb, node, buffers) {
+ this.offsetView = Vector.loadOffsetBuffer(bb, buffers[0]);
+ this.loadDataBuffer(bb, buffers[1]);
+ }
}
class NullableUtf8Vector extends Utf8Vector {
private validityView: BitArray;
- loadBuffers(bb, node, buffers) {
- this.validityView = Vector.loadValidityBuffer(bb, buffers[0]);
- this.offsetView = Vector.loadOffsetBuffer(bb, buffers[1]);
- this.loadDataBuffer(bb, buffers[2]);
- }
-
- get(i) {
+ public get(i) {
if (this.validityView.get(i)) {
return super.get(i);
} else {
@@ -292,9 +292,15 @@ class NullableUtf8Vector extends Utf8Vector {
}
}
- getValidityVector() {
+ public getValidityVector() {
return this.validityView;
}
+
+ protected loadBuffers(bb, node, buffers) {
+ this.validityView = Vector.loadValidityBuffer(bb, buffers[0]);
+ this.offsetView = Vector.loadOffsetBuffer(bb, buffers[1]);
+ this.loadDataBuffer(bb, buffers[2]);
+ }
}
// Nested Types
@@ -306,47 +312,41 @@ class ListVector extends Uint32Vector {
this.dataVector = dataVector;
}
- getChildVectors() {
+ public getChildVectors() {
return [this.dataVector];
}
- loadBuffers(bb, node, buffers) {
- super.loadBuffers(bb, node, buffers);
- this.length -= 1;
- }
-
- get(i) {
- var offset = super.get(i)
+ public get(i) {
+ const offset = super.get(i);
if (offset === null) {
return null;
}
- var next_offset = super.get(i + 1)
- return this.dataVector.slice(offset, next_offset)
+ const nextOffset = super.get(i + 1);
+ return this.dataVector.slice(offset, nextOffset);
}
- toString() {
+ public toString() {
return "length: " + (this.length);
}
- slice(start: number, end: number) {
- var result = [];
- for (var i = start; i < end; i += 1|0) {
+ public slice(start: number, end: number) {
+ const result = [];
+ for (let i = start; i < end; i++) {
result.push(this.get(i));
}
return result;
}
+
+ protected loadBuffers(bb, node, buffers) {
+ super.loadBuffers(bb, node, buffers);
+ this.length -= 1;
+ }
}
class NullableListVector extends ListVector {
private validityView: BitArray;
- loadBuffers(bb, node, buffers) {
- this.validityView = Vector.loadValidityBuffer(bb, buffers[0]);
- this.loadDataBuffer(bb, buffers[1]);
- this.length -= 1;
- }
-
- get(i) {
+ public get(i) {
if (this.validityView.get(i)) {
return super.get(i);
} else {
@@ -354,13 +354,19 @@ class NullableListVector extends ListVector {
}
}
- getValidityVector() {
+ public getValidityVector() {
return this.validityView;
}
+
+ protected loadBuffers(bb, node, buffers) {
+ this.validityView = Vector.loadValidityBuffer(bb, buffers[0]);
+ this.loadDataBuffer(bb, buffers[1]);
+ this.length -= 1;
+ }
}
class FixedSizeListVector extends Vector {
- private size: number
+ public size: number;
private dataVector: Vector;
constructor(field, size: number, dataVector: Vector) {
@@ -369,39 +375,35 @@ class FixedSizeListVector extends Vector {
this.dataVector = dataVector;
}
- getChildVectors() {
+ public getChildVectors() {
return [this.dataVector];
}
- loadBuffers(bb, node, buffers) {
- // no buffers to load
- }
-
- get(i: number) {
+ public get(i: number) {
return this.dataVector.slice(i * this.size, (i + 1) * this.size);
}
- slice(start : number, end : number) {
- var result = [];
- for (var i = start; i < end; i += 1|0) {
+ public slice(start: number, end: number) {
+ const result = [];
+ for (let i = start; i < end; i++) {
result.push(this.get(i));
}
return result;
}
- getListSize() {
+ public getListSize() {
return this.size;
}
+
+ protected loadBuffers(bb, node, buffers) {
+ // no buffers to load
+ }
}
class NullableFixedSizeListVector extends FixedSizeListVector {
private validityView: BitArray;
- loadBuffers(bb, node, buffers) {
- this.validityView = Vector.loadValidityBuffer(bb, buffers[0]);
- }
-
- get(i: number) {
+ public get(i: number) {
if (this.validityView.get(i)) {
return super.get(i);
} else {
@@ -409,9 +411,13 @@ class NullableFixedSizeListVector extends FixedSizeListVector {
}
}
- getValidityVector() {
+ public getValidityVector() {
return this.validityView;
}
+
+ protected loadBuffers(bb, node, buffers) {
+ this.validityView = Vector.loadValidityBuffer(bb, buffers[0]);
+ }
}
class StructVector extends Vector {
@@ -423,15 +429,11 @@ class StructVector extends Vector {
this.vectors = vectors;
}
- getChildVectors() {
+ public getChildVectors() {
return this.vectors;
}
- loadBuffers(bb, node, buffers) {
- this.validityView = Vector.loadValidityBuffer(bb, buffers[0]);
- }
-
- get(i : number) {
+ public get(i: number) {
if (this.validityView.get(i)) {
return this.vectors.map((v: Vector) => v.get(i));
} else {
@@ -439,32 +441,35 @@ class StructVector extends Vector {
}
}
- slice(start : number, end : number) {
- var result = [];
- for (var i = start; i < end; i += 1|0) {
+ public slice(start: number, end: number) {
+ const result = [];
+ for (let i = start; i < end; i++) {
result.push(this.get(i));
}
return result;
}
- getValidityVector() {
+ public getValidityVector() {
return this.validityView;
}
+
+ protected loadBuffers(bb, node, buffers) {
+ this.validityView = Vector.loadValidityBuffer(bb, buffers[0]);
+ }
}
class DictionaryVector extends Vector {
-
private indices: Vector;
private dictionary: Vector;
- constructor (field, indices: Vector, dictionary: Vector) {
+ constructor(field, indices: Vector, dictionary: Vector) {
super(field);
this.indices = indices;
this.dictionary = dictionary;
}
- get(i) {
- var encoded = this.indices.get(i);
+ public get(i) {
+ const encoded = this.indices.get(i);
if (encoded == null) {
return null;
} else {
@@ -477,18 +482,14 @@ class DictionaryVector extends Vector {
return this.indices.get(i);
}
- slice(start, end) {
+ public slice(start, end) {
return this.indices.slice(start, end); // TODO decode
}
- getChildVectors() {
+ public getChildVectors() {
return this.indices.getChildVectors();
}
- loadBuffers(bb, node, buffers) {
- this.indices.loadData(bb, node, buffers);
- }
-
/** Get the index (encoded) vector */
public getIndexVector() {
return this.indices;
@@ -499,91 +500,98 @@ class DictionaryVector extends Vector {
return this.dictionary;
}
- toString() {
+ public toString() {
return this.indices.toString();
}
+
+ protected loadBuffers(bb, node, buffers) {
+ this.indices.loadData(bb, node, buffers);
+ }
}
-export function vectorFromField(field, dictionaries) : Vector {
- var dictionary = field.dictionary(), nullable = field.nullable();
+export function vectorFromField(field, dictionaries): Vector {
+ const dictionary = field.dictionary();
+ const nullable = field.nullable();
if (dictionary == null) {
- var typeType = field.typeType();
+ const typeType = field.typeType();
if (typeType === Type.List) {
- var dataVector = vectorFromField(field.children(0), dictionaries);
+ const dataVector = vectorFromField(field.children(0), dictionaries);
return nullable ? new NullableListVector(field, dataVector) : new ListVector(field, dataVector);
} else if (typeType === Type.FixedSizeList) {
- var dataVector = vectorFromField(field.children(0), dictionaries);
- var size = field.type(new org.apache.arrow.flatbuf.FixedSizeList()).listSize();
+ const dataVector = vectorFromField(field.children(0), dictionaries);
+ const size = field.type(new org.apache.arrow.flatbuf.FixedSizeList()).listSize();
if (nullable) {
return new NullableFixedSizeListVector(field, size, dataVector);
} else {
return new FixedSizeListVector(field, size, dataVector);
}
} else if (typeType === Type.Struct_) {
- var vectors : Vector[] = [];
- for (var i : number = 0; i < field.childrenLength(); i += 1|0) {
+ const vectors: Vector[] = [];
+ for (let i: number = 0; i < field.childrenLength(); i++) {
vectors.push(vectorFromField(field.children(i), dictionaries));
}
return new StructVector(field, vectors);
} else {
if (typeType === Type.Int) {
- var type = field.type(new org.apache.arrow.flatbuf.Int());
- return _createIntVector(field, type.bitWidth(), type.isSigned(), nullable)
+ const type = field.type(new org.apache.arrow.flatbuf.Int());
+ return _createIntVector(field, type.bitWidth(), type.isSigned(), nullable);
} else if (typeType === Type.FloatingPoint) {
- var precision = field.type(new org.apache.arrow.flatbuf.FloatingPoint()).precision();
- if (precision == org.apache.arrow.flatbuf.Precision.SINGLE) {
+ const precision = field.type(new org.apache.arrow.flatbuf.FloatingPoint()).precision();
+ if (precision === org.apache.arrow.flatbuf.Precision.SINGLE) {
return nullable ? new NullableFloat32Vector(field) : new Float32Vector(field);
- } else if (precision == org.apache.arrow.flatbuf.Precision.DOUBLE) {
+ } else if (precision === org.apache.arrow.flatbuf.Precision.DOUBLE) {
return nullable ? new NullableFloat64Vector(field) : new Float64Vector(field);
} else {
- throw "Unimplemented FloatingPoint precision " + precision;
+ throw new Error("Unimplemented FloatingPoint precision " + precision);
}
} else if (typeType === Type.Utf8) {
return nullable ? new NullableUtf8Vector(field) : new Utf8Vector(field);
} else if (typeType === Type.Date) {
return nullable ? new NullableDateVector(field) : new DateVector(field);
} else {
- throw "Unimplemented type " + typeType;
+ throw new Error("Unimplemented type " + typeType);
}
}
} else {
// determine arrow type - default is signed 32 bit int
- var type = dictionary.indexType(), bitWidth = 32, signed = true;
+ const type = dictionary.indexType();
+ let bitWidth = 32;
+ let signed = true;
if (type != null) {
bitWidth = type.bitWidth();
signed = type.isSigned();
}
- var indices = _createIntVector(field, bitWidth, signed, nullable);
+ const indices = _createIntVector(field, bitWidth, signed, nullable);
return new DictionaryVector(field, indices, dictionaries[dictionary.id().toFloat64().toString()]);
}
}
function _createIntVector(field, bitWidth, signed, nullable) {
- if (bitWidth == 64) {
+ if (bitWidth === 64) {
if (signed) {
return nullable ? new NullableInt64Vector(field) : new Int64Vector(field);
} else {
return nullable ? new NullableUint64Vector(field) : new Uint64Vector(field);
}
- } else if (bitWidth == 32) {
+ } else if (bitWidth === 32) {
if (signed) {
return nullable ? new NullableInt32Vector(field) : new Int32Vector(field);
} else {
return nullable ? new NullableUint32Vector(field) : new Uint32Vector(field);
}
- } else if (bitWidth == 16) {
+ } else if (bitWidth === 16) {
if (signed) {
return nullable ? new NullableInt16Vector(field) : new Int16Vector(field);
} else {
return nullable ? new NullableUint16Vector(field) : new Uint16Vector(field);
}
- } else if (bitWidth == 8) {
+ } else if (bitWidth === 8) {
if (signed) {
return nullable ? new NullableInt8Vector(field) : new Int8Vector(field);
} else {
return nullable ? new NullableUint8Vector(field) : new Uint8Vector(field);
}
} else {
- throw "Unimplemented Int bit width " + bitWidth;
+ throw new Error("Unimplemented Int bit width " + bitWidth);
}
}
http://git-wip-us.apache.org/repos/asf/arrow/blob/092afb6d/js/tslint.json
----------------------------------------------------------------------
diff --git a/js/tslint.json b/js/tslint.json
new file mode 100644
index 0000000..5f2f6cd
--- /dev/null
+++ b/js/tslint.json
@@ -0,0 +1,12 @@
+{
+ "defaultSeverity": "error",
+ "extends": [
+ "tslint:recommended"
+ ],
+ "jsRules": {},
+ "rules": {
+ "no-bitwise": false,
+ "max-classes-per-file": false
+ },
+ "rulesDirectory": []
+}