| 198 | } |
| 199 | |
| 200 | aggregate(rows: any[]) { |
| 201 | let groupKeys = []; |
| 202 | let groups = {}; |
| 203 | for(let row of rows) { |
| 204 | resolve(this.projectionVars, row, this.resolvedProjection) |
| 205 | resolve(this.groupVars, row, this.resolvedGroup) |
| 206 | let group = this.resolvedAggregate.group; |
| 207 | let projection = this.resolvedAggregate.projection; |
| 208 | let token = toValue(this.token, row); |
| 209 | let index = toValue(this.index, row); |
| 210 | let sepwith = toValue(this.sepwith, row); |
| 211 | |
| 212 | if (sepwith === undefined) sepwith = ""; |
| 213 | |
| 214 | let groupKey = "[]"; |
| 215 | if(group.length !== 0) { |
| 216 | groupKey = JSON.stringify(group); |
| 217 | } |
| 218 | let groupValues = groups[groupKey]; |
| 219 | if(groupValues === undefined) { |
| 220 | groupKeys.push(groupKey); |
| 221 | groupValues = groups[groupKey] = {result:[]}; |
| 222 | } |
| 223 | let projectionKey = JSON.stringify(projection); |
| 224 | if(groupValues[projectionKey] === undefined) { |
| 225 | groupValues[projectionKey] = true; |
| 226 | groupValues.result.push({token: token, index:index, sepwith:sepwith}) |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | for (let g in groups) { |
| 231 | let s = groups[g].result.sort((a, b) => |
| 232 | {if (a.index > b.index) return 1; |
| 233 | if (a.index === b.index) return 0; |
| 234 | return -1;}) |
| 235 | let len = s.length |
| 236 | let result = "" |
| 237 | for (var i=0; i<len; ++i) { |
| 238 | // this means that the sep assocated with a value |
| 239 | // is the one which occurs before the value |
| 240 | if (i != 0) result += s[i].sepwith |
| 241 | result += s[i].token |
| 242 | } |
| 243 | groups[g].result = result; |
| 244 | } |
| 245 | this.aggregateResults = groups; |
| 246 | return groups; |
| 247 | } |
| 248 | // unused but to keep mr. class happy |
| 249 | adjustAggregate(group, value, projection) {} |
| 250 | } |