1 | import Aggregate from './Aggregate';
|
2 | import {ValidAggregateOps} from './util/AggregateOps';
|
3 | import {extend, inherits} from 'vega-util';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | export default function JoinAggregate(params) {
|
11 | Aggregate.call(this, params);
|
12 | }
|
13 |
|
14 | JoinAggregate.Definition = {
|
15 | 'type': 'JoinAggregate',
|
16 | 'metadata': {'modifies': true},
|
17 | 'params': [
|
18 | { 'name': 'groupby', 'type': 'field', 'array': true },
|
19 | { 'name': 'fields', 'type': 'field', 'null': true, 'array': true },
|
20 | { 'name': 'ops', 'type': 'enum', 'array': true, 'values': ValidAggregateOps },
|
21 | { 'name': 'as', 'type': 'string', 'null': true, 'array': true },
|
22 | { 'name': 'key', 'type': 'field' }
|
23 | ]
|
24 | };
|
25 |
|
26 | var prototype = inherits(JoinAggregate, Aggregate);
|
27 |
|
28 | prototype.transform = function(_, pulse) {
|
29 | var aggr = this,
|
30 | mod = _.modified(),
|
31 | cells;
|
32 |
|
33 |
|
34 | if (aggr.value && (mod || pulse.modified(aggr._inputs, true))) {
|
35 | cells = aggr.value = mod ? aggr.init(_) : {};
|
36 | pulse.visit(pulse.SOURCE, function(t) { aggr.add(t); });
|
37 | } else {
|
38 | cells = aggr.value = aggr.value || this.init(_);
|
39 | pulse.visit(pulse.REM, function(t) { aggr.rem(t); });
|
40 | pulse.visit(pulse.ADD, function(t) { aggr.add(t); });
|
41 | }
|
42 |
|
43 |
|
44 | aggr.changes();
|
45 |
|
46 |
|
47 | pulse.visit(pulse.SOURCE, function(t) {
|
48 | extend(t, cells[aggr.cellkey(t)].tuple);
|
49 | });
|
50 |
|
51 | return pulse.reflow(mod).modifies(this._outputs);
|
52 | };
|
53 |
|
54 | prototype.changes = function() {
|
55 | var adds = this._adds,
|
56 | mods = this._mods,
|
57 | i, n;
|
58 |
|
59 | for (i=0, n=this._alen; i<n; ++i) {
|
60 | this.celltuple(adds[i]);
|
61 | adds[i] = null;
|
62 | }
|
63 |
|
64 | for (i=0, n=this._mlen; i<n; ++i) {
|
65 | this.celltuple(mods[i]);
|
66 | mods[i] = null;
|
67 | }
|
68 |
|
69 | this._alen = this._mlen = 0;
|
70 | };
|