Skip to content

Commit 52f1e0e

Browse files
author
Brian Hulette
committed
<, > are not commutative, misc cleanup
1 parent 04b1838 commit 52f1e0e

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

js/src/predicate.ts

+18-4
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ export class Col<T= any> extends Value<T> {
6464
this.vector = batch.getChildAt(this.colidx)!;
6565
return this.vector.get.bind(this.vector);
6666
}
67-
68-
emitString() { return `cols[${this.colidx}].get(idx)`; }
6967
}
7068

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

89-
return this._bindColLit(batch, this.right as Col, this.left);
87+
return this._bindLitCol(batch, this.left, this.right as Col);
9088
}
9189
} else { // left is a Col
9290
if (this.right instanceof Literal) {
@@ -100,6 +98,7 @@ export abstract class ComparisonPredicate<T= any> extends Predicate {
10098
protected abstract _bindLitLit(batch: RecordBatch, left: Literal, right: Literal): PredicateFunc;
10199
protected abstract _bindColCol(batch: RecordBatch, left: Col, right: Col): PredicateFunc;
102100
protected abstract _bindColLit(batch: RecordBatch, col: Col, lit: Literal): PredicateFunc;
101+
protected abstract _bindLitCol(batch: RecordBatch, lit: Literal, col: Col): PredicateFunc;
103102
}
104103

105104
export abstract class CombinationPredicate extends Predicate {
@@ -169,6 +168,11 @@ export class Equals extends ComparisonPredicate {
169168
return (idx: number, cols: RecordBatch) => col_func(idx, cols) == lit.v;
170169
}
171170
}
171+
172+
protected _bindLitCol(batch: RecordBatch, lit: Literal, col: Col) {
173+
// Equals is comutative
174+
return this._bindColLit(batch, col, lit);
175+
}
172176
}
173177

174178
export class LTeq extends ComparisonPredicate {
@@ -187,6 +191,11 @@ export class LTeq extends ComparisonPredicate {
187191
const col_func = col.bind(batch);
188192
return (idx: number, cols: RecordBatch) => col_func(idx, cols) <= lit.v;
189193
}
194+
195+
protected _bindLitCol(batch: RecordBatch, lit: Literal, col: Col) {
196+
const col_func = col.bind(batch);
197+
return (idx: number, cols: RecordBatch) => lit.v <= col_func(idx, cols);
198+
}
190199
}
191200

192201
export class GTeq extends ComparisonPredicate {
@@ -205,7 +214,12 @@ export class GTeq extends ComparisonPredicate {
205214
const col_func = col.bind(batch);
206215
return (idx: number, cols: RecordBatch) => col_func(idx, cols) >= lit.v;
207216
}
217+
218+
protected _bindLitCol(batch: RecordBatch, lit: Literal, col: Col) {
219+
const col_func = col.bind(batch);
220+
return (idx: number, cols: RecordBatch) => lit.v >= col_func(idx, cols);
221+
}
208222
}
209223

210-
export function lit(n: number): Value<any> { return new Literal(n); }
224+
export function lit(v: any): Value<any> { return new Literal(v); }
211225
export function col(n: string): Col<any> { return new Col(n); }

js/src/table.ts

+3
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ class FilteredDataFrame implements DataFrame {
201201
for (let batchIndex = -1; ++batchIndex < numBatches;) {
202202
// load batches
203203
const batch = batches[batchIndex];
204+
// TODO: bind batches lazily
205+
// If predicate doesn't match anything in the batch we don't need
206+
// to bind the callback
204207
if (bind) { bind(batch); }
205208
const predicate = this.predicate.bind(batch);
206209
// yield all indices

0 commit comments

Comments
 (0)