Skip to content

Commit

Permalink
Add case for upper and lower bound being 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Dtenwolde committed Dec 5, 2024
1 parent bfe3a87 commit 6f61efd
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/core/functions/table/match.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ComparisonExpression>(
ExpressionType::COMPARE_EQUAL,
make_uniq<ColumnRefExpression>("rowid", previous_vertex_element->variable_binding),
make_uniq<ColumnRefExpression>("rowid", next_vertex_element->variable_binding)));
}

if (edge_subpath->upper > 1) {
// Add the path-finding
Expand Down Expand Up @@ -979,6 +991,7 @@ PGQMatchFunction::MatchBindReplace(ClientContext &context,
duckpgq_state->unnamed_graphtable_index++;
}
auto result = make_uniq<SubqueryRef>(std::move(subquery), ref->alias);
result->Print();
return std::move(result);
}

Expand Down
59 changes: 59 additions & 0 deletions test/sql/path_finding/quantified_path_pattern.test
Original file line number Diff line number Diff line change
@@ -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 []

0 comments on commit 6f61efd

Please sign in to comment.