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

Function validate_config

src/procedures/proc_ss_paths.c:180–313  ·  view source on GitHub ↗

validate config map and initialize SingleSourceCtx

Source from the content-addressed store, hash-verified

178
179// validate config map and initialize SingleSourceCtx
180static ProcedureResult validate_config
181(
182 SIValue config,
183 SingleSourceCtx *ctx
184) {
185 SIValue start; // start node
186 SIValue relationships; // relationship types allowed
187 SIValue dir; // direction
188 SIValue max_length; // max traverse length
189 SIValue weight_prop; // weight attribute name
190 SIValue cost_prop; // cost attribute name
191 SIValue max_cost; // maximum cost
192 SIValue path_count; // # of paths to return
193
194 bool start_exists = MAP_GET(config, "sourceNode", start);
195 bool relationships_exists = MAP_GET(config, "relTypes", relationships);
196 bool dir_exists = MAP_GET(config, "relDirection", dir);
197 bool max_length_exists = MAP_GET(config, "maxLen", max_length);
198 bool weight_prop_exists = MAP_GET(config, "weightProp", weight_prop);
199 bool cost_prop_exists = MAP_GET(config, "costProp", cost_prop);
200 bool max_cost_exists = MAP_GET(config, "maxCost", max_cost);
201 bool path_count_exists = MAP_GET(config, "pathCount", path_count);
202
203
204 if(!start_exists) {
205 ErrorCtx_SetError("sourceNode is required");
206 return false;
207 }
208 if(SI_TYPE(start) != T_NODE) {
209 ErrorCtx_SetError("sourceNode must be of type Node");
210 return false;
211 }
212
213 GRAPH_EDGE_DIR direction = GRAPH_EDGE_DIR_OUTGOING;
214 if(dir_exists) {
215 if(SI_TYPE(dir) != T_STRING) {
216 ErrorCtx_SetError("relDirection values must be 'incoming', 'outgoing' or 'both'");
217 return false;
218 }
219 if(strcasecmp(dir.stringval, "incoming") == 0) {
220 direction = GRAPH_EDGE_DIR_INCOMING;
221 } else if(strcasecmp(dir.stringval, "outgoing") == 0) {
222 direction = GRAPH_EDGE_DIR_OUTGOING;
223 } else if(strcasecmp(dir.stringval, "both") == 0) {
224 direction = GRAPH_EDGE_DIR_BOTH;
225 } else {
226 ErrorCtx_SetError("relDirection values must be 'incoming', 'outgoing' or 'both'");
227 return false;
228 }
229 }
230
231 int64_t max_length_val = LONG_MAX - 1;
232 if(max_length_exists) {
233 if(SI_TYPE(max_length) != T_INT64) {
234 ErrorCtx_SetError("maxLen must be integer");
235 return false;
236 }
237 max_length_val = SI_GET_NUMERIC(max_length);

Callers 1

Proc_SSpathsInvokeFunction · 0.70

Calls 11

ErrorCtx_SetErrorFunction · 0.85
QueryCtx_GetGraphCtxFunction · 0.85
QueryCtx_GetGraphFunction · 0.85
SIArray_AllOfTypeFunction · 0.85
SIArray_LengthFunction · 0.85
SIArray_GetFunction · 0.85
GraphContext_GetSchemaFunction · 0.85
Schema_GetIDFunction · 0.85
array_lenFunction · 0.85
SingleSourceCtx_NewFunction · 0.85

Tested by

no test coverage detected