From 25e6af7248c90d349c1786b5a50b7abe12144184 Mon Sep 17 00:00:00 2001 From: Brian Hulette Date: Thu, 25 Jan 2018 18:46:47 -0500 Subject: [PATCH 1/3] Create predicate namespace --- js/src/Arrow.externs.js | 32 ++++++++++++++++++++++++++++---- js/src/Arrow.ts | 28 ++++++++++++++++++++-------- js/src/predicate.ts | 6 +++--- js/test/unit/table-tests.ts | 10 ++++------ 4 files changed, 55 insertions(+), 21 deletions(-) diff --git a/js/src/Arrow.externs.js b/js/src/Arrow.externs.js index a0aff002fdb38..a3d5fad46880e 100644 --- a/js/src/Arrow.externs.js +++ b/js/src/Arrow.externs.js @@ -72,13 +72,37 @@ var CountByResult = function() {}; /** @type {?} */ CountByResult.prototype.asJSON; -let Col = function() {}; +var col = function () {}; + +var Value = function() {}; +/** @type {?} */ +Value.prototype.gteq; +/** @type {?} */ +Value.prototype.lteq; +/** @type {?} */ +Value.prototype.eq; + +var Col = function() {}; + +var Literal = function() {}; + +var GTeq = function () {}; +/** @type {?} */ +GTeq.prototype.and; +/** @type {?} */ +GTeq.prototype.or; + +var LTeq = function () {}; +/** @type {?} */ +LTeq.prototype.and; /** @type {?} */ -Col.prototype.gteq; +LTeq.prototype.or; + +var Equals = function () {}; /** @type {?} */ -Col.prototype.lteq; +Equals.prototype.and; /** @type {?} */ -Col.prototype.eq; +Equals.prototype.or; var TableToStringIterator = function() {}; /** @type {?} */ diff --git a/js/src/Arrow.ts b/js/src/Arrow.ts index 1cbc6c36aa39c..7ebb4d5dc130b 100644 --- a/js/src/Arrow.ts +++ b/js/src/Arrow.ts @@ -21,11 +21,11 @@ import * as vector_ from './vector'; import * as util_ from './util/int'; import * as visitor_ from './visitor'; import * as view_ from './vector/view'; +import * as predicate_ from './predicate'; import { Vector } from './vector'; import { RecordBatch } from './recordbatch'; import { Schema, Field, Type } from './type'; -import { Table, CountByResult } from './table'; -import { lit, col, Col, Value } from './predicate'; +import { Table, DataFrame, NextFunc, CountByResult } from './table'; import { read, readAsync } from './ipc/reader/arrow'; export import View = vector_.View; @@ -36,8 +36,7 @@ export import TimeBitWidth = type_.TimeBitWidth; export import TypedArrayConstructor = type_.TypedArrayConstructor; export { read, readAsync }; -export { Table, CountByResult }; -export { lit, col, Col, Value }; +export { Table, DataFrame, NextFunc, CountByResult }; export { Field, Schema, RecordBatch, Vector, Type }; export namespace util { @@ -154,6 +153,22 @@ export namespace view { export import IntervalMonthView = view_.IntervalMonthView; } +export namespace predicate { + export import col = predicate_.col; + export import Col = predicate_.Col; + //export import Value = predicate_.Value; + export import Literal = predicate_.Literal; + + export import Or = predicate_.Or; + export import And = predicate_.And; + export import GTeq = predicate_.GTeq; + export import LTeq = predicate_.LTeq; + export import Equals = predicate_.Equals; + export import Predicate = predicate_.Predicate; + + export import PredicateFunc = predicate_.PredicateFunc; +} + /* These exports are needed for the closure and uglify umd targets */ try { let Arrow: any = eval('exports'); @@ -165,6 +180,7 @@ try { Arrow['view'] = view; Arrow['vector'] = vector; Arrow['visitor'] = visitor; + Arrow['predicate'] = predicate; Arrow['read'] = read; Arrow['readAsync'] = readAsync; @@ -177,10 +193,6 @@ try { Arrow['Table'] = Table; Arrow['CountByResult'] = CountByResult; - Arrow['Value'] = Value; - Arrow['lit'] = lit; - Arrow['col'] = col; - Arrow['Col'] = Col; } } catch (e) { /* not the UMD bundle */ } /* end umd exports */ diff --git a/js/src/predicate.ts b/js/src/predicate.ts index ab327ea9d72b8..4a97cf00cefbc 100644 --- a/js/src/predicate.ts +++ b/js/src/predicate.ts @@ -102,13 +102,13 @@ export abstract class ComparisonPredicate extends Predicate { protected abstract _bindColLit(batch: RecordBatch, col: Col, lit: Literal): PredicateFunc; } -abstract class CombinationPredicate extends Predicate { +export abstract class CombinationPredicate extends Predicate { constructor(public readonly left: Predicate, public readonly right: Predicate) { super(); } } -class And extends CombinationPredicate { +export class And extends CombinationPredicate { bind(batch: RecordBatch) { const left = this.left.bind(batch); const right = this.right.bind(batch); @@ -117,7 +117,7 @@ class And extends CombinationPredicate { ands(): Predicate[] { return this.left.ands().concat(this.right.ands()); } } -class Or extends CombinationPredicate { +export class Or extends CombinationPredicate { bind(batch: RecordBatch) { const left = this.left.bind(batch); const right = this.right.bind(batch); diff --git a/js/test/unit/table-tests.ts b/js/test/unit/table-tests.ts index 9b71c79f265d5..a6f6777c0175a 100644 --- a/js/test/unit/table-tests.ts +++ b/js/test/unit/table-tests.ts @@ -15,13 +15,11 @@ // specific language governing permissions and limitations // under the License. -import Arrow, { -} from '../Arrow'; +import Arrow from '../Arrow'; -const { - col, - Table, -} = Arrow; +const { predicate, Table } = Arrow; + +const { col } = predicate; describe(`Table`, () => { test(`can create an empty table`, () => { From dc7c728557421dabafed1590edc5f28e28b6c2d7 Mon Sep 17 00:00:00 2001 From: Paul Taylor Date: Thu, 25 Jan 2018 16:05:56 -0800 Subject: [PATCH 2/3] add more view, predicate externs --- js/gulp/closure-task.js | 3 +- js/src/Arrow.externs.js | 80 +++++++++++++++++++++++++++++------------ js/src/Arrow.ts | 7 ++-- 3 files changed, 64 insertions(+), 26 deletions(-) diff --git a/js/gulp/closure-task.js b/js/gulp/closure-task.js index 9633d7199cf88..0b2ef1b846b81 100644 --- a/js/gulp/closure-task.js +++ b/js/gulp/closure-task.js @@ -66,7 +66,8 @@ const createClosureArgs = (entry, externs) => ({ rewrite_polyfills: false, entry_point: `${entry}.js`, module_resolution: `NODE`, - // formatting: `PRETTY_PRINT`, debug: true, + // formatting: `PRETTY_PRINT`, + // debug: true, compilation_level: `ADVANCED`, allow_method_call_decomposing: true, package_json_entry_names: `module,jsnext:main,main`, diff --git a/js/src/Arrow.externs.js b/js/src/Arrow.externs.js index a3d5fad46880e..a549cae5a7c8b 100644 --- a/js/src/Arrow.externs.js +++ b/js/src/Arrow.externs.js @@ -73,6 +73,7 @@ var CountByResult = function() {}; CountByResult.prototype.asJSON; var col = function () {}; +var lit = function () {}; var Value = function() {}; /** @type {?} */ @@ -83,26 +84,35 @@ Value.prototype.lteq; Value.prototype.eq; var Col = function() {}; - -var Literal = function() {}; - +/** @type {?} */ +Col.prototype.bind; +var Or = function() {}; +var And = function() {}; var GTeq = function () {}; /** @type {?} */ GTeq.prototype.and; /** @type {?} */ GTeq.prototype.or; - var LTeq = function () {}; /** @type {?} */ LTeq.prototype.and; /** @type {?} */ LTeq.prototype.or; - var Equals = function () {}; /** @type {?} */ Equals.prototype.and; /** @type {?} */ Equals.prototype.or; +var Predicate = function() {}; +/** @type {?} */ +Predicate.prototype.bind; +/** @type {?} */ +Predicate.prototype.and; +/** @type {?} */ +Predicate.prototype.or; +/** @type {?} */ +Predicate.prototype.ands; +var Literal = function() {}; var TableToStringIterator = function() {}; /** @type {?} */ @@ -142,8 +152,6 @@ Vector.prototype.get; /** @type {?} */ Vector.prototype.set; /** @type {?} */ -Vector.prototype.setData; -/** @type {?} */ Vector.prototype.toArray; /** @type {?} */ Vector.prototype.concat; @@ -465,97 +473,125 @@ var FlatView = function() {}; /** @type {?} */ FlatView.prototype.get; /** @type {?} */ +FlatView.prototype.clone; +/** @type {?} */ FlatView.prototype.isValid; /** @type {?} */ FlatView.prototype.toArray; /** @type {?} */ FlatView.prototype.set; + +var PrimitiveView = function() {}; /** @type {?} */ -FlatView.prototype.setData; +PrimitiveView.prototype.size; +/** @type {?} */ +PrimitiveView.prototype.clone; var NullView = function() {}; /** @type {?} */ NullView.prototype.get; /** @type {?} */ +NullView.prototype.clone; +/** @type {?} */ NullView.prototype.isValid; /** @type {?} */ NullView.prototype.toArray; /** @type {?} */ NullView.prototype.set; -/** @type {?} */ -NullView.prototype.setData; var BoolView = function() {}; /** @type {?} */ BoolView.prototype.get; /** @type {?} */ +BoolView.prototype.clone; +/** @type {?} */ BoolView.prototype.isValid; /** @type {?} */ BoolView.prototype.toArray; /** @type {?} */ BoolView.prototype.set; -/** @type {?} */ -BoolView.prototype.setData; var ValidityView = function() {}; /** @type {?} */ ValidityView.prototype.get; /** @type {?} */ +ValidityView.prototype.clone; +/** @type {?} */ ValidityView.prototype.isValid; /** @type {?} */ ValidityView.prototype.toArray; /** @type {?} */ ValidityView.prototype.set; -/** @type {?} */ -ValidityView.prototype.setData; var DictionaryView = function() {}; /** @type {?} */ DictionaryView.prototype.get; /** @type {?} */ +DictionaryView.prototype.clone; +/** @type {?} */ DictionaryView.prototype.isValid; /** @type {?} */ DictionaryView.prototype.toArray; /** @type {?} */ DictionaryView.prototype.set; -/** @type {?} */ -DictionaryView.prototype.setData; var ListViewBase = function() {}; /** @type {?} */ ListViewBase.prototype.get; /** @type {?} */ +ListViewBase.prototype.clone; +/** @type {?} */ ListViewBase.prototype.isValid; /** @type {?} */ ListViewBase.prototype.toArray; /** @type {?} */ ListViewBase.prototype.set; -/** @type {?} */ -ListViewBase.prototype.setData; var NestedView = function() {}; /** @type {?} */ NestedView.prototype.get; /** @type {?} */ +NestedView.prototype.clone; +/** @type {?} */ NestedView.prototype.isValid; /** @type {?} */ NestedView.prototype.toArray; /** @type {?} */ NestedView.prototype.set; -/** @type {?} */ -NestedView.prototype.setData; var ChunkedView = function() {}; /** @type {?} */ ChunkedView.prototype.get; /** @type {?} */ +ChunkedView.prototype.clone; +/** @type {?} */ ChunkedView.prototype.isValid; /** @type {?} */ ChunkedView.prototype.toArray; /** @type {?} */ ChunkedView.prototype.set; -/** @type {?} */ -ChunkedView.prototype.setData; + +var ListView = function() {}; +var FixedSizeListView = function() {}; +var BinaryView = function() {}; +var Utf8View = function() {}; +var UnionView = function() {}; +var DenseUnionView = function() {}; +var StructView = function() {}; +var MapView = function() {}; +var NullView = function() {}; +var FixedSizeView = function() {}; +var Float16View = function() {}; +var DateDayView = function() {}; +var DateMillisecondView = function() {}; +var TimestampDayView = function() {}; +var TimestampSecondView = function() {}; +var TimestampMillisecondView = function() {}; +var TimestampMicrosecondView = function() {}; +var TimestampNanosecondView = function() {}; +var IntervalYearMonthView = function() {}; +var IntervalYearView = function() {}; +var IntervalMonthView = function() {}; var TypeVisitor = function() {}; /** @type {?} */ diff --git a/js/src/Arrow.ts b/js/src/Arrow.ts index 7ebb4d5dc130b..eefed2d9a3099 100644 --- a/js/src/Arrow.ts +++ b/js/src/Arrow.ts @@ -155,15 +155,16 @@ export namespace view { export namespace predicate { export import col = predicate_.col; - export import Col = predicate_.Col; - //export import Value = predicate_.Value; - export import Literal = predicate_.Literal; + export import lit = predicate_.lit; export import Or = predicate_.Or; + export import Col = predicate_.Col; export import And = predicate_.And; export import GTeq = predicate_.GTeq; export import LTeq = predicate_.LTeq; + export import Value = predicate_.Value; export import Equals = predicate_.Equals; + export import Literal = predicate_.Literal; export import Predicate = predicate_.Predicate; export import PredicateFunc = predicate_.PredicateFunc; From 25cdc4aaf9b0f320eda956791553f59ce094c2bd Mon Sep 17 00:00:00 2001 From: Paul Taylor Date: Thu, 25 Jan 2018 16:27:25 -0800 Subject: [PATCH 3/3] add src/predicate to the list of exports we should save from uglify --- js/gulp/uglify-task.js | 1 + 1 file changed, 1 insertion(+) diff --git a/js/gulp/uglify-task.js b/js/gulp/uglify-task.js index 988830f31bd80..9ba3e41a16f41 100644 --- a/js/gulp/uglify-task.js +++ b/js/gulp/uglify-task.js @@ -91,6 +91,7 @@ const reservePublicNames = ((ESKeywords) => function reservePublicNames(target, `../${src}/table.js`, `../${src}/vector.js`, `../${src}/util/int.js`, + `../${src}/predicate.js`, `../${src}/recordbatch.js`, `../${src}/${mainExport}.js`, ];