Skip to content

Commit

Permalink
Adding edges test
Browse files Browse the repository at this point in the history
  • Loading branch information
Dtenwolde committed Jan 18, 2024
1 parent d87c9d5 commit 47a10d4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 38 deletions.
24 changes: 15 additions & 9 deletions duckpgq/src/duckpgq/functions/tablefunctions/match.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,18 +703,16 @@ namespace duckdb {
}
if (parsed_ref->function_name == "element_id") {
// Check subpath name matches the column referenced in the function --> element_id(named_subpath)
column_list.erase(column_list.begin() + idx_i);
auto shortest_path_function = CreatePathFindingFunction(subpath.path_list, pg_table);

if (column_alias.empty()) {
shortest_path_function->alias = "element_id(" + subpath.path_variable + ")";
} else {
shortest_path_function->alias = column_alias;
}
// shortest_path_function->alias = parsed_ref->alias == "" ? "element_id(" + subpath.path_variable + ")" : parsed_ref->alias;
column_list.erase(column_list.begin() + idx_i);
column_list.insert(column_list.begin() + idx_i, std::move(shortest_path_function));
} else if (parsed_ref->function_name == "path_length") {
column_list.erase(column_list.begin() + idx_i);
auto shortest_path_function = CreatePathFindingFunction(subpath.path_list, pg_table);
auto path_len_children = vector<unique_ptr<ParsedExpression>>();
path_len_children.push_back(std::move(shortest_path_function));
Expand All @@ -727,23 +725,31 @@ namespace duckdb {
auto path_length_function =
make_uniq<FunctionExpression>("//", std::move(div_children));
path_length_function->alias = column_alias.empty() ? "path_length(" + subpath.path_variable + ")" : column_alias;

column_list.insert(column_list.begin() + idx_i, std::move(path_length_function));
} else if (parsed_ref->function_name == "vertices") {
column_list.erase(column_list.begin() + idx_i);
column_list.insert(column_list.begin() + idx_i, std::move(path_length_function));
} else if (parsed_ref->function_name == "vertices" || parsed_ref->function_name == "edges") {
auto shortest_path_function = CreatePathFindingFunction(subpath.path_list, pg_table);
auto list_slice_children = vector<unique_ptr<ParsedExpression>>();
auto slice_begin = make_uniq<ConstantExpression>(Value::INTEGER(2));
list_slice_children.push_back(std::move(shortest_path_function));

if (parsed_ref->function_name == "vertices") {
list_slice_children.push_back(make_uniq<ConstantExpression>(Value::INTEGER(1)));
} else {
list_slice_children.push_back(make_uniq<ConstantExpression>(Value::INTEGER(2)));
}
auto slice_end = make_uniq<ConstantExpression>(Value::INTEGER(-1));
auto slice_step = make_uniq<ConstantExpression>(Value::INTEGER(2));

list_slice_children.push_back(std::move(shortest_path_function));
list_slice_children.push_back(std::move(slice_begin));
list_slice_children.push_back(std::move(slice_end));
list_slice_children.push_back(std::move(slice_step));
auto list_slice =
make_uniq<FunctionExpression>("list_slice", std::move(list_slice_children));
if (parsed_ref->function_name == "vertices") {
list_slice->alias = column_alias.empty() ? "vertices(" + subpath.path_variable + ")" : column_alias;
} else {
list_slice->alias = column_alias.empty() ? "edges(" + subpath.path_variable + ")" : column_alias;
}
column_list.erase(column_list.begin() + idx_i);
column_list.insert(column_list.begin() + idx_i, std::move(list_slice));
}
}
Expand Down
58 changes: 29 additions & 29 deletions test/sql/path-finding/complex_matching.test
Original file line number Diff line number Diff line change
Expand Up @@ -49,39 +49,39 @@ EDGE TABLES (
LABEL replyOf
);

query IIII
query IIIIIII
-FROM GRAPH_TABLE (snb
MATCH o = ANY SHORTEST (p4:Person where p4.rowid = 0)-[w3:knows]->(p:Person)-[w:knows]->{1,3}(p2:Person)-[w2:knows]->(p3:Person)
COLUMNS (p3.id, element_id(o), path_length(o), vertices(o), p4.id, p.id)
COLUMNS (p3.id, element_id(o), path_length(o), vertices(o), edges(o), p4.id, p.id)
) tmp;
----
28587302322180 [0, 0, 13, 42, 29, 68, 33] 3 14 10995116277782
28587302322204 [0, 0, 13, 42, 29, 69, 36] 3 14 10995116277782
28587302322196 [0, 0, 13, 43, 31, 71, 35] 3 14 10995116277782
30786325577740 [0, 0, 13, 43, 31, 72, 40] 3 14 10995116277782
35184372088850 [0, 0, 13, 43, 31, 73, 45] 3 14 10995116277782
35184372088856 [0, 0, 13, 43, 31, 74, 46] 3 14 10995116277782
28587302322204 [0, 0, 13, 44, 33, 77, 36] 3 14 10995116277782
28587302322223 [0, 0, 13, 44, 33, 78, 38] 3 14 10995116277782
30786325577731 [0, 0, 13, 44, 33, 79, 39] 3 14 10995116277782
32985348833329 [0, 0, 13, 44, 33, 80, 43] 3 14 10995116277782
35184372088850 [0, 0, 13, 45, 36, 82, 45] 3 14 10995116277782
28587302322196 [0, 1, 26, 62, 31, 71, 35] 3 14 24189255811081
30786325577740 [0, 1, 26, 62, 31, 72, 40] 3 14 24189255811081
35184372088850 [0, 1, 26, 62, 31, 73, 45] 3 14 24189255811081
35184372088856 [0, 1, 26, 62, 31, 74, 46] 3 14 24189255811081
28587302322180 [0, 1, 26, 63, 32, 75, 33] 3 14 24189255811081
28587302322204 [0, 1, 26, 63, 32, 76, 36] 3 14 24189255811081
28587302322204 [0, 1, 26, 64, 33, 77, 36] 3 14 24189255811081
28587302322223 [0, 1, 26, 64, 33, 78, 38] 3 14 24189255811081
30786325577731 [0, 1, 26, 64, 33, 79, 39] 3 14 24189255811081
32985348833329 [0, 1, 26, 64, 33, 80, 43] 3 14 24189255811081
35184372088850 [0, 1, 26, 63, 32, 76, 36, 82, 45] 4 14 24189255811081
28587302322204 [0, 2, 32, 75, 33, 77, 36] 3 14 26388279066668
28587302322223 [0, 2, 32, 75, 33, 78, 38] 3 14 26388279066668
30786325577731 [0, 2, 32, 75, 33, 79, 39] 3 14 26388279066668
32985348833329 [0, 2, 32, 75, 33, 80, 43] 3 14 26388279066668
35184372088850 [0, 2, 32, 76, 36, 82, 45] 3 14 26388279066668
28587302322180 [0, 0, 13, 42, 29, 68, 33] 3 [0, 13, 29, 33] [0, 42, 68] 14 10995116277782
28587302322204 [0, 0, 13, 42, 29, 69, 36] 3 [0, 13, 29, 36] [0, 42, 69] 14 10995116277782
28587302322196 [0, 0, 13, 43, 31, 71, 35] 3 [0, 13, 31, 35] [0, 43, 71] 14 10995116277782
30786325577740 [0, 0, 13, 43, 31, 72, 40] 3 [0, 13, 31, 40] [0, 43, 72] 14 10995116277782
35184372088850 [0, 0, 13, 43, 31, 73, 45] 3 [0, 13, 31, 45] [0, 43, 73] 14 10995116277782
35184372088856 [0, 0, 13, 43, 31, 74, 46] 3 [0, 13, 31, 46] [0, 43, 74] 14 10995116277782
28587302322204 [0, 0, 13, 44, 33, 77, 36] 3 [0, 13, 33, 36] [0, 44, 77] 14 10995116277782
28587302322223 [0, 0, 13, 44, 33, 78, 38] 3 [0, 13, 33, 38] [0, 44, 78] 14 10995116277782
30786325577731 [0, 0, 13, 44, 33, 79, 39] 3 [0, 13, 33, 39] [0, 44, 79] 14 10995116277782
32985348833329 [0, 0, 13, 44, 33, 80, 43] 3 [0, 13, 33, 43] [0, 44, 80] 14 10995116277782
35184372088850 [0, 0, 13, 45, 36, 82, 45] 3 [0, 13, 36, 45] [0, 45, 82] 14 10995116277782
28587302322196 [0, 1, 26, 62, 31, 71, 35] 3 [0, 26, 31, 35] [1, 62, 71] 14 24189255811081
30786325577740 [0, 1, 26, 62, 31, 72, 40] 3 [0, 26, 31, 40] [1, 62, 72] 14 24189255811081
35184372088850 [0, 1, 26, 62, 31, 73, 45] 3 [0, 26, 31, 45] [1, 62, 73] 14 24189255811081
35184372088856 [0, 1, 26, 62, 31, 74, 46] 3 [0, 26, 31, 46] [1, 62, 74] 14 24189255811081
28587302322180 [0, 1, 26, 63, 32, 75, 33] 3 [0, 26, 32, 33] [1, 63, 75] 14 24189255811081
28587302322204 [0, 1, 26, 63, 32, 76, 36] 3 [0, 26, 32, 36] [1, 63, 76] 14 24189255811081
28587302322204 [0, 1, 26, 64, 33, 77, 36] 3 [0, 26, 33, 36] [1, 64, 77] 14 24189255811081
28587302322223 [0, 1, 26, 64, 33, 78, 38] 3 [0, 26, 33, 38] [1, 64, 78] 14 24189255811081
30786325577731 [0, 1, 26, 64, 33, 79, 39] 3 [0, 26, 33, 39] [1, 64, 79] 14 24189255811081
32985348833329 [0, 1, 26, 64, 33, 80, 43] 3 [0, 26, 33, 43] [1, 64, 80] 14 24189255811081
35184372088850 [0, 1, 26, 63, 32, 76, 36, 82, 45] 4 [0, 26, 32, 36, 45] [1, 63, 76, 82] 14 24189255811081
28587302322204 [0, 2, 32, 75, 33, 77, 36] 3 [0, 32, 33, 36] [2, 75, 77] 14 26388279066668
28587302322223 [0, 2, 32, 75, 33, 78, 38] 3 [0, 32, 33, 38] [2, 75, 78] 14 26388279066668
30786325577731 [0, 2, 32, 75, 33, 79, 39] 3 [0, 32, 33, 39] [2, 75, 79] 14 26388279066668
32985348833329 [0, 2, 32, 75, 33, 80, 43] 3 [0, 32, 33, 43] [2, 75, 80] 14 26388279066668
35184372088850 [0, 2, 32, 76, 36, 82, 45] 3 [0, 32, 36, 45] [2, 76, 82] 14 26388279066668

statement error
-FROM GRAPH_TABLE (snb
Expand Down

0 comments on commit 47a10d4

Please sign in to comment.