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

Function test_QueryGraphExtractSubGraph

tests/unit/test_query_graph.c:355–448  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

353}
354
355void test_QueryGraphExtractSubGraph() {
356 //--------------------------------------------------------------------------
357 // construct graph
358 //--------------------------------------------------------------------------
359
360 // (A)->(B)->(C)->(D)
361 const char *relation = "R";
362
363 QGNode *A = QGNode_New("A");
364 QGNode *B = QGNode_New("B");
365 QGNode *C = QGNode_New("C");
366 QGNode *D = QGNode_New("D");
367
368 QGEdge *AB = QGEdge_New(relation, "AB");
369 QGEdge *BC = QGEdge_New(relation, "BC");
370 QGEdge *CD = QGEdge_New(relation, "CD");
371
372 uint node_cap = 4;
373 uint edge_cap = 3;
374 QueryGraph *qg = QueryGraph_New(node_cap, edge_cap);
375 QueryGraph_AddNode(qg, A);
376 QueryGraph_AddNode(qg, B);
377 QueryGraph_AddNode(qg, C);
378 QueryGraph_AddNode(qg, D);
379
380 QueryGraph_ConnectNodes(qg, A, B, AB);
381 QueryGraph_ConnectNodes(qg, B, C, BC);
382 QueryGraph_ConnectNodes(qg, C, A, CD);
383
384 //--------------------------------------------------------------------------
385 // extract portions of the original query graph
386 //--------------------------------------------------------------------------
387
388 const char *query =
389 "MATCH (A)-[AB]->(B), (B)-[BC]->(C) MATCH (C)-[CD]->(D) MATCH (D)-[DE]->(E) RETURN D";
390 cypher_parse_result_t *parse_result = cypher_parse(query, NULL, NULL, CYPHER_PARSE_ONLY_STATEMENTS);
391 AST *ast = AST_Build(parse_result);
392 ast->referenced_entities = raxNew();
393
394 const cypher_astnode_t **match_clauses = AST_GetClauses(ast, CYPHER_AST_MATCH);
395 const cypher_astnode_t *patterns[3];
396
397 // extract patterns, one per MATCH clause
398 patterns[0] = cypher_ast_match_get_pattern(match_clauses[0]);
399 patterns[1] = cypher_ast_match_get_pattern(match_clauses[1]);
400 patterns[2] = cypher_ast_match_get_pattern(match_clauses[2]);
401
402 // empty sub graph, as the number of patterns specified is 0
403 QueryGraph *sub = QueryGraph_ExtractPatterns(qg, patterns, 0);
404
405 // validation, expecting an empty query graph
406 TEST_ASSERT(QueryGraph_NodeCount(sub) == 0);
407 TEST_ASSERT(QueryGraph_EdgeCount(sub) == 0);
408 QueryGraph_Free(sub);
409
410 // single pattern, 2 paths, sub graph: a->b->c
411 sub = QueryGraph_ExtractPatterns(qg, patterns, 1);
412 TEST_ASSERT(QueryGraph_NodeCount(sub) == 3);

Callers

nothing calls this directly

Calls 15

QGNode_NewFunction · 0.85
QGEdge_NewFunction · 0.85
QueryGraph_NewFunction · 0.85
QueryGraph_AddNodeFunction · 0.85
QueryGraph_ConnectNodesFunction · 0.85
AST_BuildFunction · 0.85
AST_GetClausesFunction · 0.85
QueryGraph_NodeCountFunction · 0.85
QueryGraph_EdgeCountFunction · 0.85
QueryGraph_FreeFunction · 0.85

Tested by

no test coverage detected