From f6adfb35598b6ae26dd156e7618fab874cc8f22f Mon Sep 17 00:00:00 2001 From: Brian Hulette Date: Thu, 25 Jan 2018 18:46:47 -0500 Subject: [PATCH] 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 | 7 +++---- 4 files changed, 54 insertions(+), 19 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 d1e441c540459..f346ed61056e9 100644 --- a/js/test/unit/table-tests.ts +++ b/js/test/unit/table-tests.ts @@ -17,10 +17,9 @@ import Arrow from '../Arrow'; -const { - col, - Table, -} = Arrow; +const { predicate, Table } = Arrow; + +const { col } = predicate; describe(`Table`, () => { test(`can create an empty table`, () => {