Skip to content

Commit aa999f8

Browse files
author
Brian Hulette
committed
Add DictionaryVector optimization for equals predicate
1 parent 4d9e8c0 commit aa999f8

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

js/perf/table_config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const filenames = glob.sync(path.resolve(__dirname, `../test/data/tables/`, `*.a
2525
tests = [
2626
{col: 0, test: 'gteq', value: 0 },
2727
{col: 1, test: 'gteq', value: 0 },
28-
//{col: 2, test: 'eq', value: 'Seattle'},
28+
{col: 2, test: 'eq', value: 'Seattle'},
2929
]
3030

3131
for (const filename of filenames) {

js/src/dataframe/predicate.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Vector } from "../vector/vector";
2+
import { DictionaryVector } from "../vector/dictionary";
23

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

119120
protected _bindColLit(cols: Vector<any>[], col: Col , lit: Literal ): PredicateFunc {
120121
const col_func = col.bind(cols);
121-
return (idx: number, cols: Vector[]) => col_func(idx, cols) == lit.v;
122+
if (col.vector instanceof DictionaryVector) {
123+
// Assume that there is only one key with the value `lit.v`
124+
let key = -1
125+
for (; ++key < col.vector.data.length;) {
126+
if (col.vector.data.get(key) === lit.v) {
127+
break;
128+
}
129+
}
130+
131+
if (key == col.vector.data.length) {
132+
// the value doesn't exist in the dictionary - always return
133+
// false
134+
// TODO: special-case of PredicateFunc that encapsulates this
135+
// "always false" behavior. That way filtering operations don't
136+
// have to bother checking
137+
return () => false;
138+
} else {
139+
return (idx: number) => {
140+
return (col.vector as DictionaryVector<any>).getKey(idx) === key;
141+
}
142+
}
143+
} else {
144+
return (idx: number, cols: Vector[]) => col_func(idx, cols) == lit.v;
145+
}
122146
}
123147
}
124148

0 commit comments

Comments
 (0)