| 265 | } |
| 266 | |
| 267 | static Record AggregateConsume |
| 268 | ( |
| 269 | OpBase *opBase |
| 270 | ) { |
| 271 | OpAggregate *op = (OpAggregate *)opBase; |
| 272 | if(op->group_iter != NULL) { |
| 273 | return _handoff(op); |
| 274 | } |
| 275 | |
| 276 | Record r; |
| 277 | if(op->op.childCount == 0) { |
| 278 | // RETURN max (1) |
| 279 | // create a 'fake' record |
| 280 | r = OpBase_CreateRecord(opBase); |
| 281 | _aggregateRecord(op, r); |
| 282 | } else { |
| 283 | OpBase *child = op->op.children[0]; |
| 284 | // eager consumption! |
| 285 | while((r = OpBase_Consume(child))) { |
| 286 | _aggregateRecord(op, r); |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | // did we process any records? |
| 291 | // does aggregation contains keys? |
| 292 | // e.g. |
| 293 | // MATCH (n:N) WHERE n.noneExisting = 2 RETURN count(n) |
| 294 | if(HashTableElemCount(op->groups) == 0 && op->key_count == 0) { |
| 295 | |
| 296 | // no data was processed and aggregation doesn't have a key |
| 297 | // in this case we want to return aggregation default value |
| 298 | // aggregate on an empty record |
| 299 | ASSERT(op->op.childCount > 0); |
| 300 | |
| 301 | // use child record |
| 302 | // this is required in case this aggregation is perford within the |
| 303 | // context of a WITH projection as we need the child's mapping for |
| 304 | // expression evaluation |
| 305 | // there's no harm in doing so when not in a WITH aggregation, |
| 306 | // as we'll be using the same mapping; |
| 307 | // this operation and it child are in the same scope |
| 308 | OpBase *child = op->op.children[0]; |
| 309 | r = OpBase_CreateRecord(child); |
| 310 | |
| 311 | // get group |
| 312 | _GetGroup(op, r); |
| 313 | |
| 314 | // free record |
| 315 | OpBase_DeleteRecord(r); |
| 316 | } |
| 317 | |
| 318 | // create group iterator |
| 319 | op->group_iter = HashTableGetIterator(op->groups); |
| 320 | |
| 321 | return _handoff(op); |
| 322 | } |
| 323 | |
| 324 | static OpResult AggregateReset |
nothing calls this directly
no test coverage detected