diff --git a/src/core/functions/table/match.cpp b/src/core/functions/table/match.cpp index 52aac7bb..dedec4d0 100644 --- a/src/core/functions/table/match.cpp +++ b/src/core/functions/table/match.cpp @@ -835,6 +835,18 @@ void PGQMatchFunction::ProcessPathList( } edge_element = GetPathElement(edge_subpath->path_list[0]); auto edge_table = FindGraphTable(edge_element->label, pg_table); + if (edge_subpath->lower == 0 && edge_subpath->upper == 0) { + AddEdgeJoins(edge_table, previous_vertex_table, next_vertex_table, + edge_element->match_type, edge_element->variable_binding, + previous_vertex_element->variable_binding, + next_vertex_element->variable_binding, conditions, + alias_map, extra_alias_counter, final_select_node->from_table); + + conditions.push_back(make_uniq( + ExpressionType::COMPARE_EQUAL, + make_uniq("rowid", previous_vertex_element->variable_binding), + make_uniq("rowid", next_vertex_element->variable_binding))); + } if (edge_subpath->upper > 1) { // Add the path-finding @@ -979,6 +991,7 @@ PGQMatchFunction::MatchBindReplace(ClientContext &context, duckpgq_state->unnamed_graphtable_index++; } auto result = make_uniq(std::move(subquery), ref->alias); + result->Print(); return std::move(result); } diff --git a/test/sql/path_finding/quantified_path_pattern.test b/test/sql/path_finding/quantified_path_pattern.test new file mode 100644 index 00000000..7ef4e5f1 --- /dev/null +++ b/test/sql/path_finding/quantified_path_pattern.test @@ -0,0 +1,59 @@ + + +require duckpgq + +statement ok +create table student(id INT); INSERT INTO student(id) VALUES (10), (20), (30), (40); + +statement ok +create table know(src INT, dst INT); INSERT INTO know(src, dst) VALUES (40, 20), (10,30), (10,10), (20,10), (30,10); + +statement ok +-create property graph g vertex tables (student) edge tables (know source key (src) references student (id) destination key (dst) references student (id)); + +query IIII +-FROM GRAPH_TABLE (g + MATCH p = ANY SHORTEST (a:student)-[k:know]->{0,0}(b:student) + WHERE a.id = 10 + COLUMNS (a.id as a_id, b.id as b_id, path_length(p) as path_length, element_id(p) as path) +); +---- +10 10 0 [] + +query II +-FROM GRAPH_TABLE (g + MATCH + ANY SHORTEST (a:student)-[k:know]->{1,1}(b:student) + WHERE a.id = 10 + COLUMNS (a.id as a_id, b.id as b_id) + ); +---- +10 10 +10 30 + +query II +-FROM GRAPH_TABLE (g + MATCH + ANY SHORTEST (a:student)-[k:know]->{0,0}(b:student) + WHERE a.id = 10 + COLUMNS (a.id as a_id, b.id as b_id) + ); +---- + +query II +-FROM GRAPH_TABLE (g + MATCH p = ANY SHORTEST (a:student)-[k:know]->{0,0}(b:student) + WHERE a.id = 10 + COLUMNS (a.id as a_id, b.id as b_id) + ); +---- + +query IIII +-FROM GRAPH_TABLE (g + MATCH p = ANY SHORTEST (a:student)-[k:know]->{0,0}(b:student) + WHERE a.id = 10 + COLUMNS (a.id as a_id, b.id as b_id, path_length(p) as path_length, element_id(p) as path) + ); +---- +10 10 0 [] +