create index structure
| 172 | |
| 173 | // create index structure |
| 174 | static void _index_operation_create |
| 175 | ( |
| 176 | RedisModuleCtx *ctx, |
| 177 | GraphContext *gc, |
| 178 | AST *ast |
| 179 | ) { |
| 180 | ASSERT(gc != NULL); |
| 181 | ASSERT(ctx != NULL); |
| 182 | ASSERT(ast != NULL); |
| 183 | |
| 184 | uint nprops = 0; // number of fields indexed |
| 185 | const char *label = NULL; // label being indexed |
| 186 | SchemaType schema_type = SCHEMA_NODE; // type of entities being indexed |
| 187 | |
| 188 | const cypher_astnode_t *index_op = ast->root; |
| 189 | cypher_astnode_type_t t = cypher_astnode_type(index_op); |
| 190 | |
| 191 | //-------------------------------------------------------------------------- |
| 192 | // retrieve label and attributes from AST |
| 193 | //-------------------------------------------------------------------------- |
| 194 | |
| 195 | if(t == CYPHER_AST_CREATE_NODE_PROPS_INDEX) { |
| 196 | // old format |
| 197 | // CREATE INDEX ON :N(name) |
| 198 | nprops = cypher_ast_create_node_props_index_nprops(index_op); |
| 199 | label = cypher_ast_label_get_name( |
| 200 | cypher_ast_create_node_props_index_get_label(index_op)); |
| 201 | } else { |
| 202 | // new format |
| 203 | // CREATE INDEX FOR (n:N) ON n.name |
| 204 | nprops = cypher_ast_create_pattern_props_index_nprops(index_op); |
| 205 | label = cypher_ast_label_get_name( |
| 206 | cypher_ast_create_pattern_props_index_get_label(index_op)); |
| 207 | |
| 208 | // determine if index is created over node label or edge relationship |
| 209 | // default to node |
| 210 | if(cypher_ast_create_pattern_props_index_pattern_is_relation(index_op)) { |
| 211 | schema_type = SCHEMA_EDGE; |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | ASSERT(nprops > 0); |
| 216 | ASSERT(label != NULL); |
| 217 | |
| 218 | const char *fields[nprops]; |
| 219 | for(uint i = 0; i < nprops; i++) { |
| 220 | const cypher_astnode_t *prop_name = |
| 221 | (t == CYPHER_AST_CREATE_NODE_PROPS_INDEX) ? |
| 222 | cypher_ast_create_node_props_index_get_prop_name(index_op, i) : |
| 223 | cypher_ast_property_operator_get_prop_name |
| 224 | (cypher_ast_create_pattern_props_index_get_property_operator(index_op, i)); |
| 225 | |
| 226 | fields[i] = cypher_ast_prop_name_get_value(prop_name); |
| 227 | } |
| 228 | |
| 229 | // lock |
| 230 | QueryCtx_LockForCommit(); |
| 231 |
no test coverage detected