Skip to content

Commit

Permalink
fix: Include window frame in operator parsing lookup key. (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
jheer committed Sep 20, 2021
1 parent 45dc82a commit bf328b9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/engine/window/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import unroll from '../../util/unroll';
import windowState from './window-state';

const frameValue = op =>
(op.frame || [null, null]).map(v => Number.isFinite(v) ? v : null);
(op.frame || [null, null]).map(v => Number.isFinite(v) ? Math.abs(v) : null);

const peersValue = op => !!op.peers;

Expand Down
11 changes: 10 additions & 1 deletion src/expression/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function(input, opt = {}) {
// parser context
const ctx = {
op(op) {
const key = `${op.name}(${op.fields.concat(op.params).join(',')})`;
const key = opKey(op);
return opcall[key] || (op.id = ++opId, opcall[key] = op);
},
field(node) {
Expand Down Expand Up @@ -95,6 +95,15 @@ export default function(input, opt = {}) {
return { names, exprs, ops };
}

function opKey(op) {
let key = `${op.name}(${op.fields.concat(op.params).join(',')})`;
if (op.frame) {
const frame = op.frame.map(v => Number.isFinite(v) ? Math.abs(v) : -1);
key += `[${frame},${!!op.peers}]`;
}
return key;
}

function getParams(opt) {
return (opt.table ? getTableParams(opt.table)
: opt.join ? {
Expand Down
21 changes: 21 additions & 0 deletions test/verbs/derive-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,27 @@ tape('derive supports parameters', t => {
t.end();
});

tape('derive supports differing window frames', t => {
const dt = table({ x: [1, 2, 3, 4, 5, 6] })
.derive({
cs0: rolling(d => op.sum(d.x)),
cs4: rolling(d => op.sum(d.x), [-4, 0]),
cs2: rolling(d => op.sum(d.x), [-2, 0])
});

tableEqual(t, dt,
{
x: [1, 2, 3, 4, 5, 6],
cs0: [1, 3, 6, 10, 15, 21],
cs4: [1, 3, 6, 10, 15, 20],
cs2: [1, 3, 6, 9, 12, 15]
},
'derive data'
);

t.end();
});

tape('derive supports streaming value windows', t => {
const dt = table({ val: [1, 2, 3, 4, 5] })
.orderby('val')
Expand Down

0 comments on commit bf328b9

Please sign in to comment.