Skip to content

Commit

Permalink
Create predicate namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Hulette committed Jan 25, 2018
1 parent 016ba78 commit 25e6af7
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 21 deletions.
32 changes: 28 additions & 4 deletions js/src/Arrow.externs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {?} */
Expand Down
28 changes: 20 additions & 8 deletions js/src/Arrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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');
Expand All @@ -165,6 +180,7 @@ try {
Arrow['view'] = view;
Arrow['vector'] = vector;
Arrow['visitor'] = visitor;
Arrow['predicate'] = predicate;

Arrow['read'] = read;
Arrow['readAsync'] = readAsync;
Expand All @@ -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 */
Expand Down
6 changes: 3 additions & 3 deletions js/src/predicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ export abstract class ComparisonPredicate<T= any> 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);
Expand All @@ -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);
Expand Down
10 changes: 4 additions & 6 deletions js/test/unit/table-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`, () => {
Expand Down

0 comments on commit 25e6af7

Please sign in to comment.