From e3f629d0cf603eef5da44c510b69ad4e0a894a37 Mon Sep 17 00:00:00 2001 From: Paul Taylor Date: Thu, 18 Jan 2018 15:08:11 -0800 Subject: [PATCH] fix rest of the mangling issues --- js/gulp/closure-task.js | 5 +- js/gulp/uglify-task.js | 19 +- js/src/{Arrow.externs.ts => Arrow.externs.js} | 246 ++++++++++++++---- js/src/Arrow.ts | 230 +++++++++------- js/src/data.ts | 2 - js/src/ipc/reader/json.ts | 10 +- js/src/type.ts | 25 +- js/test/Arrow.ts | 77 ------ js/test/unit/int-tests.ts | 2 +- 9 files changed, 354 insertions(+), 262 deletions(-) rename js/src/{Arrow.externs.ts => Arrow.externs.js} (59%) diff --git a/js/gulp/closure-task.js b/js/gulp/closure-task.js index 1bd872fd3044a..9633d7199cf88 100644 --- a/js/gulp/closure-task.js +++ b/js/gulp/closure-task.js @@ -36,7 +36,7 @@ const closureTask = ((cache) => memoizeTask(cache, function closure(target, form const src = targetDir(target, `cls`); const out = targetDir(target, format); const entry = path.join(src, mainExport); - const externs = path.join(src, `${mainExport}.externs`); + const externs = path.join(`src/Arrow.externs.js`); return observableFromStreams( gulp.src([ /* external libs first --> */ `node_modules/tslib/package.json`, @@ -46,7 +46,6 @@ const closureTask = ((cache) => memoizeTask(cache, function closure(target, form `node_modules/text-encoding-utf-8/package.json`, `node_modules/text-encoding-utf-8/src/encoding.js`, /* then sources globs --> */ `${src}/**/*.js`, -/* and exclusions last --> */ `!${src}/Arrow.externs.js`, ], { base: `./` }), sourcemaps.init(), closureCompiler(createClosureArgs(entry, externs)), @@ -60,11 +59,11 @@ const closureTask = ((cache) => memoizeTask(cache, function closure(target, form }))({}); const createClosureArgs = (entry, externs) => ({ + externs, third_party: true, warning_level: `QUIET`, dependency_mode: `STRICT`, rewrite_polyfills: false, - externs: `${externs}.js`, entry_point: `${entry}.js`, module_resolution: `NODE`, // formatting: `PRETTY_PRINT`, debug: true, diff --git a/js/gulp/uglify-task.js b/js/gulp/uglify-task.js index 8e6a68a1aae52..bcda8cae60df5 100644 --- a/js/gulp/uglify-task.js +++ b/js/gulp/uglify-task.js @@ -84,11 +84,18 @@ module.exports = uglifyTask; module.exports.uglifyTask = uglifyTask; const reservePublicNames = ((ESKeywords) => function reservePublicNames(target, format) { - const publicModulePath = `../${targetDir(target, format)}/${mainExport}.js`; - return [ - ...ESKeywords, - ...reserveExportedNames(esmRequire(publicModulePath)) + const src = targetDir(target, format); + const publicModulePaths = [ + `../${src}/data.js`, + `../${src}/type.js`, + `../${src}/table.js`, + `../${src}/vector.js`, + `../${src}/util/int.js`, + `../${src}/${mainExport}.js`, ]; + return publicModulePaths.reduce((keywords, publicModulePath) => [ + ...keywords, ...reserveExportedNames(esmRequire(publicModulePath, { warnings: false })) + ], [...ESKeywords]); })(ESKeywords); // Reflect on the Arrow modules to come up with a list of keys to save from Uglify's @@ -104,8 +111,8 @@ const reserveExportedNames = (entryModule) => ( .map((name) => [name, entryModule[name]]) .reduce((reserved, [name, value]) => { const fn = function() {}; - const ownKeys = value && Object.getOwnPropertyNames(value) || []; - const protoKeys = typeof value === `function` && Object.getOwnPropertyNames(value.prototype) || []; + const ownKeys = value && typeof value === 'object' && Object.getOwnPropertyNames(value) || []; + const protoKeys = typeof value === `function` && Object.getOwnPropertyNames(value.prototype || {}) || []; const publicNames = [...ownKeys, ...protoKeys].filter((x) => x !== `default` && x !== `undefined` && !(x in fn)); return [...reserved, name, ...publicNames]; }, [] diff --git a/js/src/Arrow.externs.ts b/js/src/Arrow.externs.js similarity index 59% rename from js/src/Arrow.externs.ts rename to js/src/Arrow.externs.js index 8001f524a42fb..174ddad40e3db 100644 --- a/js/src/Arrow.externs.ts +++ b/js/src/Arrow.externs.js @@ -1,3 +1,4 @@ +// @ts-nocheck // Licensed to the Apache Software Foundation (ASF) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -15,6 +16,8 @@ // specific language governing permissions and limitations // under the License. +/* tslint:disable */ + /** * @fileoverview Closure Compiler externs for Arrow * @externs @@ -25,25 +28,51 @@ Symbol.iterator; /** @type {symbol} */ Symbol.asyncIterator; -let Table = function() {}; +var Table = function() {}; +/** @type {?} */ +Table.from = function() {}; /** @type {?} */ -( Table).from; +Table.fromAsync = function() {}; /** @type {?} */ -( Table).fromAsync; +Table.empty = function() {}; /** @type {?} */ -( Table).empty; +Table.prototype.schema; /** @type {?} */ Table.prototype.columns; /** @type {?} */ -Table.prototype.length; +Table.prototype.numCols; +/** @type {?} */ +Table.prototype.numRows; +/** @type {?} */ +Table.prototype.get; +/** @type {?} */ +Table.prototype.toArray; /** @type {?} */ Table.prototype.select; /** @type {?} */ -Table.prototype.toString; +Table.prototype.rowsToString; + +var TableToStringIterator = function() {}; +/** @type {?} */ +TableToStringIterator.prototype.pipe; + +var RecordBatch = function() {}; +/** @type {?} */ +RecordBatch.prototype.numRows; +/** @type {?} */ +RecordBatch.prototype.schema; +/** @type {?} */ +RecordBatch.prototype.data; +/** @type {?} */ +RecordBatch.prototype.columns; +/** @type {?} */ +RecordBatch.prototype.numCols; +/** @type {?} */ +RecordBatch.prototype.concat; -let Vector = function() {}; +var Vector = function() {}; /** @type {?} */ -( Vector).create; +Vector.create = function() {}; /** @type {?} */ Vector.prototype.data; /** @type {?} */ @@ -71,49 +100,135 @@ Vector.prototype.slice; /** @type {?} */ Vector.prototype.acceptTypeVisitor; -let DataType = function() {}; +var BaseInt64 = function() {}; +/** @type {?} */ +BaseInt64.prototype.lessThan; +/** @type {?} */ +BaseInt64.prototype.equals; +/** @type {?} */ +BaseInt64.prototype.greaterThan; +/** @type {?} */ +BaseInt64.prototype.hex; + +var Uint64 = function() {}; +/** @type {?} */ +Uint64.add = function() {}; +/** @type {?} */ +Uint64.multiply = function() {}; +/** @type {?} */ +Uint64.prototype.times; +/** @type {?} */ +Uint64.prototype.plus + +var Int64 = function() {}; +/** @type {?} */ +Int64.add = function() {}; +/** @type {?} */ +Int64.multiply = function() {}; +/** @type {?} */ +Int64.fromString = function() {}; +/** @type {?} */ +Int64.prototype.negate +/** @type {?} */ +Int64.prototype.times +/** @type {?} */ +Int64.prototype.plus +/** @type {?} */ +Int64.prototype.lessThan + +var Int128 = function() {}; +/** @type {?} */ +Int128.add = function() {}; +/** @type {?} */ +Int128.multiply = function() {}; +/** @type {?} */ +Int128.fromString = function() {}; +/** @type {?} */ +Int128.prototype.negate +/** @type {?} */ +Int128.prototype.times +/** @type {?} */ +Int128.prototype.plus +/** @type {?} */ +Int128.prototype.hex + +var DataType = function() {}; +/** @type {?} */ +DataType.isNull = function() {}; /** @type {?} */ -( DataType).isNull; +DataType.isInt = function() {}; /** @type {?} */ -( DataType).isInt; +DataType.isFloat = function() {}; /** @type {?} */ -( DataType).isFloat; +DataType.isBinary = function() {}; /** @type {?} */ -( DataType).isBinary; +DataType.isUtf8 = function() {}; /** @type {?} */ -( DataType).isUtf8; +DataType.isBool = function() {}; /** @type {?} */ -( DataType).isBool; +DataType.isDecimal = function() {}; /** @type {?} */ -( DataType).isDecimal; +DataType.isDate = function() {}; /** @type {?} */ -( DataType).isDate; +DataType.isTime = function() {}; /** @type {?} */ -( DataType).isTime; +DataType.isTimestamp = function() {}; /** @type {?} */ -( DataType).isTimestamp; +DataType.isInterval = function() {}; /** @type {?} */ -( DataType).isInterval; +DataType.isList = function() {}; /** @type {?} */ -( DataType).isList; +DataType.isStruct = function() {}; /** @type {?} */ -( DataType).isStruct; +DataType.isUnion = function() {}; /** @type {?} */ -( DataType).isUnion; +DataType.isDenseUnion = function() {}; /** @type {?} */ -( DataType).isDenseUnion; +DataType.isSparseUnion = function() {}; /** @type {?} */ -( DataType).isSparseUnion; +DataType.isFixedSizeBinary = function() {}; /** @type {?} */ -( DataType).isFixedSizeBinary; +DataType.isFixedSizeList = function() {}; /** @type {?} */ -( DataType).isFixedSizeList; +DataType.isMap = function() {}; /** @type {?} */ -( DataType).isMap; +DataType.isDictionary = function() {}; /** @type {?} */ -( DataType).isDictionary; +DataType.prototype.ArrayType; + +var Schema = function() {}; +var Field = function() {}; +var Null = function() {}; +var Int8 = function() {}; +var Int16 = function() {}; +var Int32 = function() {}; +var Int64 = function() {}; +var Uint8 = function() {}; +var Uint16 = function() {}; +var Uint32 = function() {}; +var Uint64 = function() {}; +var Float16 = function() {}; +var Float32 = function() {}; +var Float64 = function() {}; +var Binary = function() {}; +var Utf8 = function() {}; +var Bool = function() {}; +var Decimal = function() {}; +var Date_ = function() {}; +var Time = function() {}; +var Timestamp = function() {}; +var Interval = function() {}; +var List = function() {}; +var Struct = function() {}; +var Union = function() {}; +var DenseUnion = function() {}; +var SparseUnion = function() {}; +var FixedSizeBinary = function() {}; +var FixedSizeList = function() {}; +var Map_ = function() {}; +var Dictionary = function() {}; -let BaseData = function() {}; +var BaseData = function() {}; /** @type {?} */ BaseData.prototype.type; /** @type {?} */ @@ -133,45 +248,50 @@ BaseData.prototype.nullBitmap; /** @type {?} */ BaseData.prototype.nullCount; -let FlatData = function() {}; +var BoolData = function() {}; +var NestedData = function() {}; +var SparseUnionData = function() {}; +var ChunkedData = function() {}; + +var FlatData = function() {}; /** @type {?} */ FlatData.prototype.values; -let FlatListData = function() {}; +var FlatListData = function() {}; /** @type {?} */ FlatListData.prototype.values; /** @type {?} */ FlatListData.prototype.valueOffsets; -let DictionaryData = function() {}; +var DictionaryData = function() {}; /** @type {?} */ DictionaryData.prototype.indicies; /** @type {?} */ DictionaryData.prototype.dictionary; -let ListData = function() {}; +var ListData = function() {}; /** @type {?} */ ListData.prototype.values; /** @type {?} */ ListData.prototype.valueOffsets; -let UnionData = function() {}; +var UnionData = function() {}; /** @type {?} */ UnionData.prototype.typeIds; -let DenseUnionData = function() {}; +var DenseUnionData = function() {}; /** @type {?} */ DenseUnionData.prototype.valueOffsets; -let ChunkedData = function() {}; +var ChunkedData = function() {}; /** @type {?} */ -( ChunkedData).computeOffsets; +ChunkedData.computeOffsets = function() {}; -let FlatVector = function() {}; +var FlatVector = function() {}; /** @type {?} */ FlatVector.prototype.values; -let ListVectorBase = function() {}; +var ListVectorBase = function() {}; /** @type {?} */ ListVectorBase.prototype.values; /** @type {?} */ @@ -181,19 +301,37 @@ ListVectorBase.prototype.getValueOffset; /** @type {?} */ ListVectorBase.prototype.getValueLength; -let NestedVector = function() {}; +var NestedVector = function() {}; /** @type {?} */ NestedVector.prototype.childData; /** @type {?} */ NestedVector.prototype.getChildAt; -let DictionaryVector = function() {}; +var NullVector = function() {}; +var BoolVector = function() {}; +var IntVector = function() {}; +var FloatVector = function() {}; +var DateVector = function() {}; +var DecimalVector = function() {}; +var TimeVector = function() {}; +var TimestampVector = function() {}; +var IntervalVector = function() {}; +var BinaryVector = function() {}; +var FixedSizeBinaryVector = function() {}; +var Utf8Vector = function() {}; +var ListVector = function() {}; +var FixedSizeListVector = function() {}; +var MapVector = function() {}; +var StructVector = function() {}; +var UnionVector = function() {}; + +var DictionaryVector = function() {}; /** @type {?} */ DictionaryVector.prototype.getKey; /** @type {?} */ DictionaryVector.prototype.getValue; -let FlatView = function() {}; +var FlatView = function() {}; /** @type {?} */ FlatView.prototype.get; /** @type {?} */ @@ -205,7 +343,7 @@ FlatView.prototype.set; /** @type {?} */ FlatView.prototype.setData; -let NullView = function() {}; +var NullView = function() {}; /** @type {?} */ NullView.prototype.get; /** @type {?} */ @@ -217,7 +355,7 @@ NullView.prototype.set; /** @type {?} */ NullView.prototype.setData; -let BoolView = function() {}; +var BoolView = function() {}; /** @type {?} */ BoolView.prototype.get; /** @type {?} */ @@ -229,7 +367,7 @@ BoolView.prototype.set; /** @type {?} */ BoolView.prototype.setData; -let ValidityView = function() {}; +var ValidityView = function() {}; /** @type {?} */ ValidityView.prototype.get; /** @type {?} */ @@ -241,7 +379,7 @@ ValidityView.prototype.set; /** @type {?} */ ValidityView.prototype.setData; -let DictionaryView = function() {}; +var DictionaryView = function() {}; /** @type {?} */ DictionaryView.prototype.get; /** @type {?} */ @@ -253,7 +391,7 @@ DictionaryView.prototype.set; /** @type {?} */ DictionaryView.prototype.setData; -let ListViewBase = function() {}; +var ListViewBase = function() {}; /** @type {?} */ ListViewBase.prototype.get; /** @type {?} */ @@ -265,7 +403,7 @@ ListViewBase.prototype.set; /** @type {?} */ ListViewBase.prototype.setData; -let NestedView = function() {}; +var NestedView = function() {}; /** @type {?} */ NestedView.prototype.get; /** @type {?} */ @@ -277,7 +415,7 @@ NestedView.prototype.set; /** @type {?} */ NestedView.prototype.setData; -let ChunkedView = function() {}; +var ChunkedView = function() {}; /** @type {?} */ ChunkedView.prototype.get; /** @type {?} */ @@ -289,9 +427,9 @@ ChunkedView.prototype.set; /** @type {?} */ ChunkedView.prototype.setData; -let TypeVisitor = function() {}; +var TypeVisitor = function() {}; /** @type {?} */ -( TypeVisitor).visitTypeInline; +TypeVisitor.visitTypeInline = function() {}; /** @type {?} */ TypeVisitor.prototype.visit; /** @type {?} */ @@ -333,9 +471,9 @@ TypeVisitor.prototype.visitFixedSizeList; /** @type {?} */ TypeVisitor.prototype.visitMap; -let VectorVisitor = function() {}; +var VectorVisitor = function() {}; /** @type {?} */ -( VectorVisitor).visitTypeInline; +VectorVisitor.visitTypeInline = function() {}; /** @type {?} */ VectorVisitor.prototype.visit; /** @type {?} */ diff --git a/js/src/Arrow.ts b/js/src/Arrow.ts index c988e0cf8893f..bcaf3690097b8 100644 --- a/js/src/Arrow.ts +++ b/js/src/Arrow.ts @@ -16,34 +16,101 @@ // under the License. import * as type_ from './type'; -import * as data from './data'; -import * as vector from './vector'; - +import * as data_ from './data'; +import { Vector } from './vector'; +import * as vector_ from './vector'; +import * as util_ from './util/int'; +import { Schema, Field, Type } from './type'; import { Table, RecordBatch } from './table'; -import { Uint64, Int64, Int128 } from './util/int'; -import { View, Vector, VectorLike, } from './vector'; import { read, readAsync } from './ipc/reader/arrow'; -import { Schema, Field, DataType, Type } from './type'; - -// closure compiler always erases static method names: -// https://github.com/google/closure-compiler/issues/1776 -// set them via string indexers to save them from the mangler -Table['from'] = Table.from; -Table['fromAsync'] = Table.fromAsync; -Table['empty'] = Table.empty; -Vector['create'] = Vector.create; +export import View = vector_.View; +export import VectorLike = vector_.VectorLike; +export import TypedArray = type_.TypedArray; export import IntBitWidth = type_.IntBitWidth; export import TimeBitWidth = type_.TimeBitWidth; - -export import TypedArray = type_.TypedArray; export import TypedArrayConstructor = type_.TypedArrayConstructor; export { read, readAsync }; -export { View, VectorLike }; -export { Uint64, Int64, Int128 }; -export { type_ as type, data, vector }; -export { Table, Field, Schema, Vector, DataType, RecordBatch, Type }; +export { Field, Schema, Table, RecordBatch, Vector, Type }; + +export namespace util { + export import Uint64 = util_.Uint64; + export import Int64 = util_.Int64; + export import Int128 = util_.Int128; +} + +export namespace data { + export import BaseData = data_.BaseData; + export import FlatData = data_.FlatData; + export import BoolData = data_.BoolData; + export import FlatListData = data_.FlatListData; + export import DictionaryData = data_.DictionaryData; + export import NestedData = data_.NestedData; + export import ListData = data_.ListData; + export import UnionData = data_.UnionData; + export import SparseUnionData = data_.SparseUnionData; + export import DenseUnionData = data_.DenseUnionData; + export import ChunkedData = data_.ChunkedData; +} + +export namespace type { + export import Schema = type_.Schema; + export import Field = type_.Field; + export import Null = type_.Null; + export import Int = type_.Int; + export import Int8 = type_.Int8; + export import Int16 = type_.Int16; + export import Int32 = type_.Int32; + export import Int64 = type_.Int64; + export import Uint8 = type_.Uint8; + export import Uint16 = type_.Uint16; + export import Uint32 = type_.Uint32; + export import Uint64 = type_.Uint64; + export import Float = type_.Float; + export import Float16 = type_.Float16; + export import Float32 = type_.Float32; + export import Float64 = type_.Float64; + export import Binary = type_.Binary; + export import Utf8 = type_.Utf8; + export import Bool = type_.Bool; + export import Decimal = type_.Decimal; + export import Date_ = type_.Date_; + export import Time = type_.Time; + export import Timestamp = type_.Timestamp; + export import Interval = type_.Interval; + export import List = type_.List; + export import Struct = type_.Struct; + export import Union = type_.Union; + export import DenseUnion = type_.DenseUnion; + export import SparseUnion = type_.SparseUnion; + export import FixedSizeBinary = type_.FixedSizeBinary; + export import FixedSizeList = type_.FixedSizeList; + export import Map_ = type_.Map_; + export import Dictionary = type_.Dictionary; +} + +export namespace vector { + export import Vector = vector_.Vector; + export import NullVector = vector_.NullVector; + export import BoolVector = vector_.BoolVector; + export import IntVector = vector_.IntVector; + export import FloatVector = vector_.FloatVector; + export import DateVector = vector_.DateVector; + export import DecimalVector = vector_.DecimalVector; + export import TimeVector = vector_.TimeVector; + export import TimestampVector = vector_.TimestampVector; + export import IntervalVector = vector_.IntervalVector; + export import BinaryVector = vector_.BinaryVector; + export import FixedSizeBinaryVector = vector_.FixedSizeBinaryVector; + export import Utf8Vector = vector_.Utf8Vector; + export import ListVector = vector_.ListVector; + export import FixedSizeListVector = vector_.FixedSizeListVector; + export import MapVector = vector_.MapVector; + export import StructVector = vector_.StructVector; + export import UnionVector = vector_.UnionVector; + export import DictionaryVector = vector_.DictionaryVector; +} /* These exports are needed for the closure and uglify umd targets */ try { @@ -51,84 +118,65 @@ try { if (Arrow && typeof Arrow === 'object') { // string indexers tell closure and uglify not to rename these properties Arrow['data'] = data; - Arrow['type'] = type_; + Arrow['type'] = type; + Arrow['util'] = util; + Arrow['vector'] = vector; + Arrow['read'] = read; Arrow['readAsync'] = readAsync; - Arrow['Int64'] = Int64; - Arrow['Uint64'] = Uint64; - Arrow['Int128'] = Int128; - Arrow['Table'] = Table; Arrow['Field'] = Field; Arrow['Schema'] = Schema; - Arrow['Vector'] = Vector; - Arrow['DataType'] = DataType; + Arrow['Table'] = Table; Arrow['RecordBatch'] = RecordBatch; + Arrow['Vector'] = Vector; + // Arrow['DataType'] = type_.DataType; - Arrow['data']['BaseData'] = data.BaseData; - Arrow['data']['FlatData'] = data.FlatData; - Arrow['data']['BoolData'] = data.BoolData; - Arrow['data']['FlatListData'] = data.FlatListData; - Arrow['data']['DictionaryData'] = data.DictionaryData; - Arrow['data']['NestedData'] = data.NestedData; - Arrow['data']['ListData'] = data.ListData; - Arrow['data']['UnionData'] = data.UnionData; - Arrow['data']['SparseUnionData'] = data.SparseUnionData; - Arrow['data']['DenseUnionData'] = data.DenseUnionData; - - Arrow['type']['DataType'] = type_.DataType; - Arrow['type']['Null'] = type_.Null; - Arrow['type']['Bool'] = type_.Bool; - Arrow['type']['Decimal'] = type_.Decimal; - Arrow['type']['Int'] = type_.Int; - Arrow['type']['Int8'] = type_.Int8; - Arrow['type']['Int16'] = type_.Int16; - Arrow['type']['Int32'] = type_.Int32; - Arrow['type']['Int64'] = type_.Int64; - Arrow['type']['Uint8'] = type_.Uint8; - Arrow['type']['Uint16'] = type_.Uint16; - Arrow['type']['Uint32'] = type_.Uint32; - Arrow['type']['Uint64'] = type_.Uint64; - Arrow['type']['Float'] = type_.Float; - Arrow['type']['Float16'] = type_.Float16; - Arrow['type']['Float32'] = type_.Float32; - Arrow['type']['Float64'] = type_.Float64; - Arrow['type']['Date_'] = type_.Date_; - Arrow['type']['Time'] = type_.Time; - Arrow['type']['Timestamp'] = type_.Timestamp; - Arrow['type']['Interval'] = type_.Interval; - Arrow['type']['Binary'] = type_.Binary; - Arrow['type']['FixedSizeBinary'] = type_.FixedSizeBinary; - Arrow['type']['Utf8'] = type_.Utf8; - Arrow['type']['List'] = type_.List; - Arrow['type']['FixedSizeList'] = type_.FixedSizeList; - Arrow['type']['Struct'] = type_.Struct; - Arrow['type']['Union'] = type_.Union; - Arrow['type']['Map_'] = type_.Map_; - Arrow['type']['Dictionary'] = type_.Dictionary; - - Arrow['vector']['Vector'] = vector.Vector; - Arrow['vector']['FlatVector'] = vector.FlatVector; - Arrow['vector']['ListVectorBase'] = vector.ListVectorBase; - Arrow['vector']['NestedVector'] = vector.NestedVector; - Arrow['vector']['NullVector'] = vector.NullVector; - Arrow['vector']['BoolVector'] = vector.BoolVector; - Arrow['vector']['IntVector'] = vector.IntVector; - Arrow['vector']['FloatVector'] = vector.FloatVector; - Arrow['vector']['DateVector'] = vector.DateVector; - Arrow['vector']['DecimalVector'] = vector.DecimalVector; - Arrow['vector']['TimeVector'] = vector.TimeVector; - Arrow['vector']['TimestampVector'] = vector.TimestampVector; - Arrow['vector']['IntervalVector'] = vector.IntervalVector; - Arrow['vector']['BinaryVector'] = vector.BinaryVector; - Arrow['vector']['FixedSizeBinaryVector'] = vector.FixedSizeBinaryVector; - Arrow['vector']['Utf8Vector'] = vector.Utf8Vector; - Arrow['vector']['ListVector'] = vector.ListVector; - Arrow['vector']['FixedSizeListVector'] = vector.FixedSizeListVector; - Arrow['vector']['MapVector'] = vector.MapVector; - Arrow['vector']['StructVector'] = vector.StructVector; - Arrow['vector']['UnionVector'] = vector.UnionVector; - Arrow['vector']['DictionaryVector'] = vector.DictionaryVector; + // Arrow['Uint64'] = util_.Uint64; + // Arrow['Int64'] = util_.Int64; + // Arrow['Int128'] = util_.Int128; } } catch (e) { /* not the UMD bundle */ } /* end umd exports */ + +// closure compiler always erases static method names: +// https://github.com/google/closure-compiler/issues/1776 +// set them via string indexers to save them from the mangler +Table['from'] = Table.from; +Table['fromAsync'] = Table.fromAsync; +Table['empty'] = Table.empty; +Vector['create'] = Vector.create; + +util_.Uint64['add'] = util_.Uint64.add; +util_.Uint64['multiply'] = util_.Uint64.multiply; + +util_.Int64['add'] = util_.Int64.add; +util_.Int64['multiply'] = util_.Int64.multiply; +util_.Int64['fromString'] = util_.Int64.fromString; + +util_.Int128['add'] = util_.Int128.add; +util_.Int128['multiply'] = util_.Int128.multiply; +util_.Int128['fromString'] = util_.Int128.fromString; + +data_.ChunkedData['computeOffsets'] = data_.ChunkedData.computeOffsets; + +type_.DataType['isNull'] = type_.DataType.isNull; +type_.DataType['isInt'] = type_.DataType.isInt; +type_.DataType['isFloat'] = type_.DataType.isFloat; +type_.DataType['isBinary'] = type_.DataType.isBinary; +type_.DataType['isUtf8'] = type_.DataType.isUtf8; +type_.DataType['isBool'] = type_.DataType.isBool; +type_.DataType['isDecimal'] = type_.DataType.isDecimal; +type_.DataType['isDate'] = type_.DataType.isDate; +type_.DataType['isTime'] = type_.DataType.isTime; +type_.DataType['isTimestamp'] = type_.DataType.isTimestamp; +type_.DataType['isInterval'] = type_.DataType.isInterval; +type_.DataType['isList'] = type_.DataType.isList; +type_.DataType['isStruct'] = type_.DataType.isStruct; +type_.DataType['isUnion'] = type_.DataType.isUnion; +type_.DataType['isDenseUnion'] = type_.DataType.isDenseUnion; +type_.DataType['isSparseUnion'] = type_.DataType.isSparseUnion; +type_.DataType['isFixedSizeBinary'] = type_.DataType.isFixedSizeBinary; +type_.DataType['isFixedSizeList'] = type_.DataType.isFixedSizeList; +type_.DataType['isMap'] = type_.DataType.isMap; +type_.DataType['isDictionary'] = type_.DataType.isDictionary; diff --git a/js/src/data.ts b/js/src/data.ts index 5a6e26da9c2fc..f68d1e3faf378 100644 --- a/js/src/data.ts +++ b/js/src/data.ts @@ -299,5 +299,3 @@ export class ChunkedData extends BaseData { return childOffsets; } } - -ChunkedData['computeOffsets'] = ChunkedData.computeOffsets; \ No newline at end of file diff --git a/js/src/ipc/reader/json.ts b/js/src/ipc/reader/json.ts index c3f88f7d1e7ce..10819986f6d33 100644 --- a/js/src/ipc/reader/json.ts +++ b/js/src/ipc/reader/json.ts @@ -19,7 +19,7 @@ import { Vector } from '../../vector'; import { flatbuffers } from 'flatbuffers'; import { TypeDataLoader } from './vector'; import { packBools } from '../../util/bit'; -import { Int64, Int128 } from '../../util/int'; +import * as IntUtil from '../../util/int'; import { TextEncoder } from 'text-encoding-utf-8'; import { RecordBatchMetadata, DictionaryBatch, BufferMetadata, FieldMetadata } from '../metadata'; import { @@ -35,7 +35,7 @@ import { Int8, Uint8, Int16, Uint16, Int32, Uint32, - Int64 as Int64_, Uint64, + Int64, Uint64, Float16, Float64, Float32, } from '../../type'; @@ -127,7 +127,7 @@ function int64DataFromJSON(values: string[]) { // > -4613034156400212000 >>> 0 // 721782784 // The correct lower 32-bits are 721782752 - Int64.fromString(values[i].toString(), new Uint32Array(data.buffer, data.byteOffset + 2 * i * 4, 2)); + IntUtil.Int64.fromString(values[i].toString(), new Uint32Array(data.buffer, data.byteOffset + 2 * i * 4, 2)); } return data.buffer; } @@ -135,7 +135,7 @@ function int64DataFromJSON(values: string[]) { function decimalDataFromJSON(values: string[]) { const data = new Uint32Array(values.length * 4); for (let i = -1, n = values.length; ++i < n;) { - Int128.fromString(values[i], new Uint32Array(data.buffer, data.byteOffset + 4 * 4 * i, 4)); + IntUtil.Int128.fromString(values[i], new Uint32Array(data.buffer, data.byteOffset + 4 * 4 * i, 4)); } return data.buffer; } @@ -298,7 +298,7 @@ function intFromJSON (_type: any) { switch (_type[ case 8: return _type['isSigned'] ? new Int8() : new Uint8(); case 16: return _type['isSigned'] ? new Int16() : new Uint16(); case 32: return _type['isSigned'] ? new Int32() : new Uint32(); - case 64: return _type['isSigned'] ? new Int64_() : new Uint64(); + case 64: return _type['isSigned'] ? new Int64() : new Uint64(); } return null; } function floatingPointFromJSON (_type: any) { switch (Precision[_type['precision']] as any) { diff --git a/js/src/type.ts b/js/src/type.ts index 2a9ea12a7164a..06293bcc50238 100644 --- a/js/src/type.ts +++ b/js/src/type.ts @@ -195,27 +195,6 @@ export abstract class DataType implements Partial { TArray: void; TValue: null; } export class Null extends DataType { constructor() { super(Type.Null); } @@ -229,7 +208,7 @@ export class Null extends DataType { } export interface Int extends DataType { TArray: TArrayType; TValue: TValueType; } -export class Int extends DataType { +export abstract class Int extends DataType { constructor(public readonly isSigned: boolean, public readonly bitWidth: IntBitWidth) { super(Type.Int); @@ -309,7 +288,7 @@ export class Uint64 extends Int { } export interface Float extends DataType { TArray: TArrayType; TValue: number; } -export class Float extends DataType { +export abstract class Float extends DataType { constructor(public readonly precision: Precision) { super(Type.Float); } diff --git a/js/test/Arrow.ts b/js/test/Arrow.ts index b75cef066222f..5921c4cecb9ee 100644 --- a/js/test/Arrow.ts +++ b/js/test/Arrow.ts @@ -46,86 +46,9 @@ export { View, VectorLike }; import { Table, Field, Schema, RecordBatch, Type } from '../src/Arrow'; export { Table, Field, Schema, RecordBatch, Type }; -import { Int64, Uint64, Int128 } from '../src/Arrow'; -export { Int64, Uint64, Int128 }; import { TypedArray, TypedArrayConstructor, IntBitWidth, TimeBitWidth } from '../src/Arrow'; export { TypedArray, TypedArrayConstructor, IntBitWidth, TimeBitWidth }; import * as Arrow_ from '../src/Arrow'; -// import { data as data_, type as type_, vector as vector_ } from '../src/Arrow'; - export let Arrow = require(path.resolve(`./targets`, modulePath, `Arrow`)) as typeof Arrow_; export default Arrow; - -// export namespace data { -// export import Data = data_.Data; -// export import BaseData = data_.BaseData; -// export import FlatData = data_.FlatData; -// export import BoolData = data_.BoolData; -// export import FlatListData = data_.FlatListData; -// export import DictionaryData = data_.DictionaryData; -// export import NestedData = data_.NestedData; -// export import ListData = data_.ListData; -// export import UnionData = data_.UnionData; -// export import SparseUnionData = data_.SparseUnionData; -// export import DenseUnionData = data_.DenseUnionData; -// } - -// export namespace type { -// export import DataType = type_.DataType; -// export import Null = type_.Null; -// export import Bool = type_.Bool; -// export import Decimal = type_.Decimal; -// export import Int = type_.Int; -// export import Int8 = type_.Int8; -// export import Int16 = type_.Int16; -// export import Int32 = type_.Int32; -// export import Int64 = type_.Int64; -// export import Uint8 = type_.Uint8; -// export import Uint16 = type_.Uint16; -// export import Uint32 = type_.Uint32; -// export import Uint64 = type_.Uint64; -// export import Float = type_.Float; -// export import Float16 = type_.Float16; -// export import Float32 = type_.Float32; -// export import Float64 = type_.Float64; -// export import Date_ = type_.Date_; -// export import Time = type_.Time; -// export import Timestamp = type_.Timestamp; -// export import Interval = type_.Interval; -// export import Binary = type_.Binary; -// export import FixedSizeBinary = type_.FixedSizeBinary; -// export import Utf8 = type_.Utf8; -// export import List = type_.List; -// export import FixedSizeList = type_.FixedSizeList; -// export import Struct = type_.Struct; -// export import Union = type_.Union; -// export import Map_ = type_.Map_; -// export import Dictionary = type_.Dictionary; -// } - -// export namespace vector { -// export import Vector = vector_.Vector; -// export import FlatVector = vector_.FlatVector; -// export import ListVectorBase = vector_.ListVectorBase; -// export import NestedVector = vector_.NestedVector; -// export import NullVector = vector_.NullVector; -// export import BoolVector = vector_.BoolVector; -// export import IntVector = vector_.IntVector; -// export import FloatVector = vector_.FloatVector; -// export import DateVector = vector_.DateVector; -// export import DecimalVector = vector_.DecimalVector; -// export import TimeVector = vector_.TimeVector; -// export import TimestampVector = vector_.TimestampVector; -// export import IntervalVector = vector_.IntervalVector; -// export import BinaryVector = vector_.BinaryVector; -// export import FixedSizeBinaryVector = vector_.FixedSizeBinaryVector; -// export import Utf8Vector = vector_.Utf8Vector; -// export import ListVector = vector_.ListVector; -// export import FixedSizeListVector = vector_.FixedSizeListVector; -// export import MapVector = vector_.MapVector; -// export import StructVector = vector_.StructVector; -// export import UnionVector = vector_.UnionVector; -// export import DictionaryVector = vector_.DictionaryVector; -// } - diff --git a/js/test/unit/int-tests.ts b/js/test/unit/int-tests.ts index d06fca574dbb3..fbd92e7c7323d 100644 --- a/js/test/unit/int-tests.ts +++ b/js/test/unit/int-tests.ts @@ -16,7 +16,7 @@ // under the License. import Arrow from '../Arrow'; -const { Int64, Uint64, Int128 } = Arrow; +const { Int64, Uint64, Int128 } = Arrow.util; describe(`Uint64`, () => { test(`gets expected high/low bytes`, () => {