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

Function AR_HAS_LABELS

src/arithmetic/entity_funcs/entity_funcs.c:49–88  ·  view source on GitHub ↗

returns true if input node contains all specified labels, otherwise false

Source from the content-addressed store, hash-verified

47
48// returns true if input node contains all specified labels, otherwise false
49SIValue AR_HAS_LABELS(SIValue *argv, int argc, void *private_data) {
50 if(SI_TYPE(argv[0]) == T_NULL) return SI_NullVal();
51
52 bool res = true;
53 Node *node = argv[0].ptrval;
54 SIValue labels = argv[1];
55 EntityID id = ENTITY_GET_ID(node);
56 GraphContext *gc = QueryCtx_GetGraphCtx();
57 Graph *g = gc->g;
58
59 // iterate over given labels
60 uint32_t labels_length = SIArray_Length(labels);
61 for (uint32_t i = 0; i < labels_length; i++) {
62 SIValue label_value = SIArray_Get(labels, i);
63 if(SI_TYPE(label_value) != T_STRING) {
64 Error_SITypeMismatch(label_value, T_STRING);
65 return SI_NullVal();
66 }
67 char *label = label_value.stringval;
68 Schema *s = GraphContext_GetSchema(gc, label, SCHEMA_NODE);
69
70 // validate schema exists
71 if(!s) {
72 res = false;
73 break;
74 }
75
76 // validate label is set
77 bool x;
78 RG_Matrix M = Graph_GetLabelMatrix(g, Schema_GetID(s));
79 ASSERT(M != NULL);
80
81 if(RG_Matrix_extractElement_BOOL(&x, M, id, id) == GrB_NO_VALUE) {
82 res = false;
83 break;
84 }
85 }
86
87 return SI_BoolVal(res);
88}
89
90/* returns a string representation of the type of a relation. */
91SIValue AR_TYPE(SIValue *argv, int argc, void *private_data) {

Callers

nothing calls this directly

Calls 10

SI_NullValFunction · 0.85
QueryCtx_GetGraphCtxFunction · 0.85
SIArray_LengthFunction · 0.85
SIArray_GetFunction · 0.85
Error_SITypeMismatchFunction · 0.85
GraphContext_GetSchemaFunction · 0.85
Graph_GetLabelMatrixFunction · 0.85
Schema_GetIDFunction · 0.85
SI_BoolValFunction · 0.85

Tested by

no test coverage detected