MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / ProjectConsume

Function ProjectConsume

src/execution_plan/ops/op_project.c:43–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41}
42
43static Record ProjectConsume(OpBase *opBase) {
44 OpProject *op = (OpProject *)opBase;
45
46 if(op->op.childCount) {
47 OpBase *child = op->op.children[0];
48 op->r = OpBase_Consume(child);
49 if(!op->r) return NULL;
50 } else {
51 // QUERY: RETURN 1+2
52 // Return a single record followed by NULL on the second call.
53 if(op->singleResponse) return NULL;
54 op->singleResponse = true;
55 op->r = OpBase_CreateRecord(opBase);
56 }
57
58 op->projection = OpBase_CreateRecord(opBase);
59
60 for(uint i = 0; i < op->exp_count; i++) {
61 AR_ExpNode *exp = op->exps[i];
62 SIValue v = AR_EXP_Evaluate(exp, op->r);
63 int rec_idx = op->record_offsets[i];
64
65 // persisting a value is only necessary when
66 // 'v' refers to a scalar held in Record 'r'
67 // graph entities don't need to be persisted here as
68 // Record_Add will copy them internally
69 //
70 // the RETURN projection here requires persistence:
71 // MATCH (a) WITH toUpper(a.name) AS e RETURN e
72 // TODO: this is a rare case;
73 // the logic of when to persist can be improved
74
75 if(!(v.type & SI_GRAPHENTITY)) SIValue_Persist(&v);
76 Record_Add(op->projection, rec_idx, v);
77
78 // if the value was a graph entity with its own allocation
79 // as with a query like:
80 // MATCH p = (src) RETURN nodes(p)[0]
81 // ensure that the allocation is freed here
82 if((v.type & SI_GRAPHENTITY)) {
83 SIValue_Free(v);
84 }
85 }
86
87 OpBase_DeleteRecord(op->r);
88 op->r = NULL;
89
90 // Emit the projected Record once.
91 Record projection = op->projection;
92 op->projection = NULL;
93 return projection;
94}
95
96static OpResult ProjectReset(OpBase *opBase) {
97 OpProject *op = (OpProject *)opBase;

Callers

nothing calls this directly

Calls 7

OpBase_ConsumeFunction · 0.85
OpBase_CreateRecordFunction · 0.85
AR_EXP_EvaluateFunction · 0.85
SIValue_PersistFunction · 0.85
Record_AddFunction · 0.85
SIValue_FreeFunction · 0.85
OpBase_DeleteRecordFunction · 0.85

Tested by

no test coverage detected