Skip to content

Commit

Permalink
<, > are not commutative, misc cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Hulette committed Jan 29, 2018
1 parent 04b1838 commit 52f1e0e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
22 changes: 18 additions & 4 deletions js/src/predicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ export class Col<T= any> extends Value<T> {
this.vector = batch.getChildAt(this.colidx)!;
return this.vector.get.bind(this.vector);
}

emitString() { return `cols[${this.colidx}].get(idx)`; }
}

export abstract class Predicate {
Expand All @@ -86,7 +84,7 @@ export abstract class ComparisonPredicate<T= any> extends Predicate {
return this._bindLitLit(batch, this.left, this.right);
} else { // right is a Col

return this._bindColLit(batch, this.right as Col, this.left);
return this._bindLitCol(batch, this.left, this.right as Col);
}
} else { // left is a Col
if (this.right instanceof Literal) {
Expand All @@ -100,6 +98,7 @@ export abstract class ComparisonPredicate<T= any> extends Predicate {
protected abstract _bindLitLit(batch: RecordBatch, left: Literal, right: Literal): PredicateFunc;
protected abstract _bindColCol(batch: RecordBatch, left: Col, right: Col): PredicateFunc;
protected abstract _bindColLit(batch: RecordBatch, col: Col, lit: Literal): PredicateFunc;
protected abstract _bindLitCol(batch: RecordBatch, lit: Literal, col: Col): PredicateFunc;
}

export abstract class CombinationPredicate extends Predicate {
Expand Down Expand Up @@ -169,6 +168,11 @@ export class Equals extends ComparisonPredicate {
return (idx: number, cols: RecordBatch) => col_func(idx, cols) == lit.v;
}
}

protected _bindLitCol(batch: RecordBatch, lit: Literal, col: Col) {
// Equals is comutative
return this._bindColLit(batch, col, lit);
}
}

export class LTeq extends ComparisonPredicate {
Expand All @@ -187,6 +191,11 @@ export class LTeq extends ComparisonPredicate {
const col_func = col.bind(batch);
return (idx: number, cols: RecordBatch) => col_func(idx, cols) <= lit.v;
}

protected _bindLitCol(batch: RecordBatch, lit: Literal, col: Col) {
const col_func = col.bind(batch);
return (idx: number, cols: RecordBatch) => lit.v <= col_func(idx, cols);
}
}

export class GTeq extends ComparisonPredicate {
Expand All @@ -205,7 +214,12 @@ export class GTeq extends ComparisonPredicate {
const col_func = col.bind(batch);
return (idx: number, cols: RecordBatch) => col_func(idx, cols) >= lit.v;
}

protected _bindLitCol(batch: RecordBatch, lit: Literal, col: Col) {
const col_func = col.bind(batch);
return (idx: number, cols: RecordBatch) => lit.v >= col_func(idx, cols);
}
}

export function lit(n: number): Value<any> { return new Literal(n); }
export function lit(v: any): Value<any> { return new Literal(v); }
export function col(n: string): Col<any> { return new Col(n); }
3 changes: 3 additions & 0 deletions js/src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ class FilteredDataFrame implements DataFrame {
for (let batchIndex = -1; ++batchIndex < numBatches;) {
// load batches
const batch = batches[batchIndex];
// TODO: bind batches lazily
// If predicate doesn't match anything in the batch we don't need
// to bind the callback
if (bind) { bind(batch); }
const predicate = this.predicate.bind(batch);
// yield all indices
Expand Down

0 comments on commit 52f1e0e

Please sign in to comment.