Skip to content

Commit

Permalink
Fixing inheritance. Now returns pow(2, idx_of_label) which seems to b…
Browse files Browse the repository at this point in the history
…e correct
  • Loading branch information
Dtenwolde committed Jan 29, 2024
1 parent 9e353fa commit 5d3a1bb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 34 deletions.
8 changes: 4 additions & 4 deletions duckpgq/src/duckpgq/functions/tablefunctions/match.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ void PGQMatchFunction::CheckInheritance(
const auto itr = std::find(tableref->sub_labels.begin(),
tableref->sub_labels.end(), element->label);

const auto idx_of_element = std::distance(tableref->sub_labels.begin(), itr);
const auto idx_of_label = std::distance(tableref->sub_labels.begin(), itr);
auto constant_expression_idx_label = make_uniq<ConstantExpression>(
Value::INTEGER(static_cast<int32_t>(idx_of_element)));
Value::INTEGER(static_cast<int32_t>(idx_of_label)));

vector<unique_ptr<ParsedExpression>> power_of_children;
power_of_children.push_back(std::move(constant_expression_two));
power_of_children.push_back(std::move(constant_expression_idx_label));
auto power_of_term =
make_uniq<FunctionExpression>("power", std::move(power_of_children));
auto bigint_cast =
make_uniq<CastExpression>(LogicalType::BIGINT, std::move(power_of_term));
make_uniq<CastExpression>(LogicalType::INTEGER, std::move(power_of_term));
auto subcategory_colref = make_uniq<ColumnRefExpression>(
tableref->discriminator, element->variable_binding);
vector<unique_ptr<ParsedExpression>> and_children;
Expand All @@ -69,7 +69,7 @@ void PGQMatchFunction::CheckInheritance(
make_uniq<FunctionExpression>("&", std::move(and_children));

auto constant_expression_idx_label_comparison = make_uniq<ConstantExpression>(
Value::INTEGER(static_cast<int32_t>(idx_of_element + 1)));
Value::INTEGER(static_cast<int32_t>(pow(2, idx_of_label))));

auto subset_compare = make_uniq<ComparisonExpression>(
ExpressionType::COMPARE_EQUAL, std::move(and_expression),
Expand Down
58 changes: 28 additions & 30 deletions test/sql/pattern-matching/inheritance_support.test
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ statement ok
INSERT INTO Person VALUES (0, 'Daniel'), (1, 'Tavneet'), (2, 'Gabor'), (3, 'Peter'), (4, 'David');

statement ok
INSERT INTO worksAt VALUES (0,1), (0,2), (0,3), (3,0), (1,2), (1,3), (2,3), (4,3);
INSERT INTO worksAt VALUES (0,1), (0,2), (0,3), (1,2), (1,3), (2,3), (3,0), (4,3);

statement ok
INSERT INTO University VALUES ('VU', 0, 2), ('UvA', 1, 2);
INSERT INTO University VALUES ('VU', 0, 1), ('UvA', 1, 1);

statement ok
INSERT INTO Company VALUES ('EY', 2, 4), ('CWI', 3, 4);
INSERT INTO Company VALUES ('EY', 2, 2), ('CWI', 3, 2);

statement ok
INSERT INTO Organisation (SELECT * from university union select * from company);
Expand All @@ -58,10 +58,10 @@ FROM GRAPH_TABLE(pg
0 Daniel 1 UvA
0 Daniel 2 EY
0 Daniel 3 CWI
3 Peter 0 VU
1 Tavneet 2 EY
1 Tavneet 3 CWI
2 Gabor 3 CWI
3 Peter 0 VU
4 David 3 CWI

query IIIII
Expand All @@ -71,39 +71,37 @@ FROM GRAPH_TABLE(pg
COLUMNS (p.id, p.name, u.id, u.name, u.mask)
) result
----
0 Daniel 1 UvA 2
0 Daniel 2 EY 4
0 Daniel 3 CWI 4
3 Peter 0 VU 2
1 Tavneet 2 EY 4
1 Tavneet 3 CWI 4
2 Gabor 3 CWI 4
4 David 3 CWI 4

0 Daniel 1 UvA 1
0 Daniel 2 EY 2
0 Daniel 3 CWI 2
1 Tavneet 2 EY 2
1 Tavneet 3 CWI 2
2 Gabor 3 CWI 2
3 Peter 0 VU 1
4 David 3 CWI 2

query IIII
-SELECT *
FROM GRAPH_TABLE(pg
query IIIII
-FROM GRAPH_TABLE(pg
MATCH (p:Person)-[w:worksAt]->(u:university)
COLUMNS (p.id, p.name, u.id, u.name, u.mask)
) result
----
0 Daniel 1 UvA
3 Peter 0 VU
0 Daniel 1 UvA 1
3 Peter 0 VU 1

query IIII
query IIIII
-SELECT *
FROM GRAPH_TABLE(pg
MATCH (p:Person)-[w:worksAt]->(u:company)
COLUMNS (p.id, p.name, u.id, u.name, u.mask)
) result
----
0 Daniel 3 CWI
1 Tavneet 3 CWI
2 Gabor 3 CWI
4 David 3 CWI
0 Daniel 2 EY
1 Tavneet 2 EY
0 Daniel 3 CWI 2
1 Tavneet 3 CWI 2
2 Gabor 3 CWI 2
4 David 3 CWI 2
0 Daniel 2 EY 2
1 Tavneet 2 EY 2

# Should work with different capitalization
query IIII
Expand All @@ -130,21 +128,21 @@ FROM GRAPH_TABLE(pg
1 UvA 0 Daniel
2 EY 0 Daniel
3 CWI 0 Daniel
0 VU 3 Peter
2 EY 1 Tavneet
3 CWI 1 Tavneet
3 CWI 2 Gabor
0 VU 3 Peter
3 CWI 4 David

query IIII
-SELECT *
FROM GRAPH_TABLE(pg
MATCH (p:university)<-[w:worksAt]-(u:person)
COLUMNS (p.id, p.name, u.id, u.mask)
MATCH (u:university)<-[w:worksAt]-(p:person)
COLUMNS (p.id, p.name, u.name, u.mask)
) result
----
1 UvA 0 Daniel
0 VU 3 Peter
0 Daniel UvA 1
3 Peter VU 1

statement ok
-drop property graph pg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,4 @@ query IIIIIIII
COLUMNS(a.firstName, a.lastName, a.birthday, a.locationIP, a.browserUsed, c.id, a.gender, a.creationDate)
) tmp;
----
Ivan Dobrunov 1988-10-21 31.28.20.134 Firefox 865 female 2010-02-09 17:26:35.413

0 comments on commit 5d3a1bb

Please sign in to comment.