Skip to content

Commit

Permalink
Add DictionaryVector optimization for equals predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Hulette committed Jan 12, 2018
1 parent 4d9e8c0 commit aa999f8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion js/perf/table_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const filenames = glob.sync(path.resolve(__dirname, `../test/data/tables/`, `*.a
tests = [
{col: 0, test: 'gteq', value: 0 },
{col: 1, test: 'gteq', value: 0 },
//{col: 2, test: 'eq', value: 'Seattle'},
{col: 2, test: 'eq', value: 'Seattle'},
]

for (const filename of filenames) {
Expand Down
26 changes: 25 additions & 1 deletion js/src/dataframe/predicate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Vector } from "../vector/vector";
import { DictionaryVector } from "../vector/dictionary";

export type ValueFunc<T> = (idx: number, cols: Vector[]) => T|null;
export type PredicateFunc = (idx: number, cols: Vector[]) => boolean;
Expand Down Expand Up @@ -118,7 +119,30 @@ class Equals extends ComparisonPredicate {

protected _bindColLit(cols: Vector<any>[], col: Col , lit: Literal ): PredicateFunc {
const col_func = col.bind(cols);
return (idx: number, cols: Vector[]) => col_func(idx, cols) == lit.v;
if (col.vector instanceof DictionaryVector) {
// Assume that there is only one key with the value `lit.v`
let key = -1
for (; ++key < col.vector.data.length;) {
if (col.vector.data.get(key) === lit.v) {
break;
}
}

if (key == col.vector.data.length) {
// the value doesn't exist in the dictionary - always return
// false
// TODO: special-case of PredicateFunc that encapsulates this
// "always false" behavior. That way filtering operations don't
// have to bother checking
return () => false;
} else {
return (idx: number) => {
return (col.vector as DictionaryVector<any>).getKey(idx) === key;
}
}
} else {
return (idx: number, cols: Vector[]) => col_func(idx, cols) == lit.v;
}
}
}

Expand Down

0 comments on commit aa999f8

Please sign in to comment.