eagerly consume and aggregate all the records from the lhs (if exists). pass the aggregated record-list to the ArgumentList operation(s) after aggregating, return records to caller. if the subquery is returning, return the consumed record(s) from the body. otherwise, return the input record(s)
| 172 | // return the consumed record(s) from the body. otherwise, return the input |
| 173 | // record(s) |
| 174 | static Record CallSubqueryConsumeEager |
| 175 | ( |
| 176 | OpBase *opBase // operation |
| 177 | ) { |
| 178 | OpCallSubquery *op = (OpCallSubquery *)opBase; |
| 179 | |
| 180 | // if eager consumption has already occurred, don't consume again |
| 181 | if(!op->first) { |
| 182 | return _handoff_eager(op); |
| 183 | } |
| 184 | |
| 185 | op->first = false; |
| 186 | |
| 187 | ASSERT(op->records == NULL); |
| 188 | op->records = array_new(Record, 1); |
| 189 | // eagerly consume all records from lhs if exists or create a |
| 190 | // dummy-record, and place them\it in op->records |
| 191 | Record r; |
| 192 | if(op->lhs) { |
| 193 | while((r = OpBase_Consume(op->lhs))) { |
| 194 | array_append(op->records, r); |
| 195 | } |
| 196 | // propagate reset to lhs, to release RediSearch index locks (if any) |
| 197 | OpBase_PropagateReset(op->lhs); |
| 198 | } else { |
| 199 | r = OpBase_CreateRecord((OpBase *)op); |
| 200 | array_append(op->records, r); |
| 201 | } |
| 202 | |
| 203 | _plant_records_ArgumentLists(op); |
| 204 | |
| 205 | int n_branches = (int)array_len(op->feeders.argumentLists); |
| 206 | if(op->is_returning) { |
| 207 | // give the last branch the original records |
| 208 | ArgumentList_AddRecordList( |
| 209 | op->feeders.argumentLists[n_branches - 1], op->records); |
| 210 | |
| 211 | // responsibility for the records is passed to the argumentList op(s) |
| 212 | op->records = NULL; |
| 213 | } else { |
| 214 | // give the last branch a clone of the original record(s) |
| 215 | Record *records_clone; |
| 216 | array_clone_with_cb(records_clone, op->records, |
| 217 | OpBase_DeepCloneRecord); |
| 218 | ArgumentList_AddRecordList( |
| 219 | op->feeders.argumentLists[n_branches - 1], records_clone); |
| 220 | } |
| 221 | |
| 222 | if(!op->is_returning) { |
| 223 | // deplete body and discard records |
| 224 | while((r = OpBase_Consume(op->body))) { |
| 225 | OpBase_DeleteRecord(r); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | return _handoff_eager(op); |
| 230 | } |
| 231 |
nothing calls this directly
no test coverage detected