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

Function UpdateNodeLabels

src/graph/graph_hub.c:322–438  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

320}
321
322void UpdateNodeLabels
323(
324 GraphContext *gc, // graph context to update the entity
325 Node *node, // the node to be updated
326 const char **add_labels, // labels to add to the node
327 const char **remove_labels, // labels to add to the node
328 uint n_add_labels, // number of labels to add
329 uint n_remove_labels, // number of labels to remove
330 bool log // log this operation in undo-log
331) {
332 ASSERT(gc != NULL);
333 ASSERT(node != NULL);
334
335 // quick return if there are no labels
336 if(add_labels == NULL && remove_labels == NULL) {
337 return;
338 }
339
340 // if add_labels is specified its count must be > 0
341 ASSERT((add_labels != NULL && n_add_labels > 0) ||
342 (add_labels == NULL && n_add_labels == 0));
343
344 // if remove_labels is specified its count must be > 0
345 ASSERT((remove_labels != NULL && n_remove_labels > 0) ||
346 (remove_labels == NULL && n_remove_labels == 0));
347
348 EffectsBuffer *eb = NULL;
349 UndoLog undo_log = NULL;
350
351 if(log == true) {
352 eb = QueryCtx_GetEffectsBuffer();
353 undo_log = QueryCtx_GetUndoLog();
354 }
355
356 if(add_labels != NULL) {
357 int add_labels_ids[n_add_labels];
358 uint add_labels_index = 0;
359
360 for (uint i = 0; i < n_add_labels; i++) {
361 const char *label = add_labels[i];
362 // get or create label matrix
363 const Schema *s = GraphContext_GetSchema(gc, label, SCHEMA_NODE);
364 bool schema_created = false;
365 if(s == NULL) {
366 s = AddSchema(gc, label, SCHEMA_NODE, log);
367 schema_created = true;
368 }
369
370 int schema_id = Schema_GetID(s);
371 bool node_labeled = Graph_IsNodeLabeled(gc->g, ENTITY_GET_ID(node),
372 schema_id);
373
374 if(!node_labeled) {
375 // sync matrix
376 // make sure label matrix is of the right dimensions
377 if(schema_created) {
378 RG_Matrix m = Graph_GetLabelMatrix(gc->g, schema_id);
379 }

Callers 2

ApplyLabelsFunction · 0.85
CommitUpdatesFunction · 0.85

Calls 15

QueryCtx_GetUndoLogFunction · 0.85
GraphContext_GetSchemaFunction · 0.85
AddSchemaFunction · 0.85
Schema_GetIDFunction · 0.85
Graph_IsNodeLabeledFunction · 0.85
Graph_GetLabelMatrixFunction · 0.85
Schema_AddNodeToIndicesFunction · 0.85
Graph_LabelNodeFunction · 0.85
UndoLog_AddLabelsFunction · 0.85

Tested by

no test coverage detected