Skip to content

Commit

Permalink
Merge pull request #73 from cwida/72-inheritance-not-returning-correc…
Browse files Browse the repository at this point in the history
…t-result

Adding a projected snb test
  • Loading branch information
Dtenwolde authored Jan 29, 2024
2 parents b6cd180 + 5d3a1bb commit 971d28f
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 42 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
74 changes: 36 additions & 38 deletions test/sql/pattern-matching/inheritance_support.test
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ statement ok
CREATE TABLE Organisation(name VARCHAR, id BIGINT, mask BIGINT);

statement ok
CREATE TABLE Company(name VARCHAR, id BIGINT, kind VARCHAR);
CREATE TABLE Company(name VARCHAR, id BIGINT, mask VARCHAR);

statement ok
CREATE TABLE University(name VARCHAR, id BIGINT, kind VARCHAR);
CREATE TABLE University(name VARCHAR, id BIGINT, mask VARCHAR);

statement ok
CREATE TABLE worksAt(personId BIGINT, organisationId BIGINT);
Expand All @@ -25,10 +25,10 @@ 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, 1), ('UVA', 1, 1);
INSERT INTO University VALUES ('VU', 0, 1), ('UvA', 1, 1);

statement ok
INSERT INTO Company VALUES ('EY', 2, 2), ('CWI', 3, 2);
Expand All @@ -55,55 +55,53 @@ FROM GRAPH_TABLE(pg
COLUMNS (p.id, p.name, u.id, u.name)
) result
----
0 Daniel 1 UVA
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 IIII
query IIIII
-SELECT *
FROM GRAPH_TABLE(pg
MATCH (p:Person)-[w:worksAt]->(u:ORGANISATION)
COLUMNS (p.id, p.name, u.id, u.name)
COLUMNS (p.id, p.name, u.id, u.name, u.mask)
) result
----
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
4 David 3 CWI


query IIII
-SELECT *
FROM GRAPH_TABLE(pg
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 IIIII
-FROM GRAPH_TABLE(pg
MATCH (p:Person)-[w:worksAt]->(u:university)
COLUMNS (p.id, p.name, u.id, u.name)
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)
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 @@ -127,24 +125,24 @@ FROM GRAPH_TABLE(pg
COLUMNS (p.id, p.name, u.id, u.name)
) result
----
1 UVA 0 Daniel
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.name)
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
105 changes: 105 additions & 0 deletions test/sql/snb/snb-projected.test_slow
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
require duckpgq

statement ok
import database 'duckdb-pgq/data/SNB1-projected|';

statement ok
-CREATE PROPERTY GRAPH snb_projected
VERTEX TABLES (
Forum LABEL Forum,
Message LABEL Message IN Subcategory(Comment, Post),
Organisation LABEL Organisation IN Subcategory(University, Company),
Person LABEL Person,
Place LABEL Place IN Subcategory(Continent, Country, City),
Tag LABEL Tag,
TagClass LABEL TagClass
)
EDGE TABLES (
Comment_hasCreator_Person SOURCE KEY (CommentId) REFERENCES Message (id)
DESTINATION KEY (PersonId) REFERENCES Person (id)
LABEL Comment_hasCreator,
Comment_hasTag_Tag SOURCE KEY (CommentId) REFERENCES Message (id)
DESTINATION KEY (TagId) REFERENCES Tag (id)
LABEL Comment_hasTag,
Comment_isLocatedIn_Country SOURCE KEY (CommentId) REFERENCES Message (id)
DESTINATION KEY (CountryId) REFERENCES Tag (id)
LABEL Comment_isLocatedIn,
Comment_replyOf_Comment SOURCE KEY (Comment1Id) REFERENCES Message (id)
DESTINATION KEY (Comment2Id) REFERENCES Message (id)
LABEL replyOf_Comment,
Comment_replyOf_Post SOURCE KEY (CommentId) REFERENCES Message (id)
DESTINATION KEY (PostId) REFERENCES Message (id)
LABEL replyOf_Post,
Forum_containerOf_Post SOURCE KEY (ForumId) REFERENCES Forum (id)
DESTINATION KEY (PostId) REFERENCES Message (id)
LABEL containerOf,
Forum_hasMember_Person SOURCE KEY (ForumId) REFERENCES Forum (id)
DESTINATION KEY (PersonId) REFERENCES Person (id)
LABEL hasMember,
Forum_hasModerator_Person SOURCE KEY (ForumId) REFERENCES Forum (id)
DESTINATION KEY (PersonId) REFERENCES Person (id)
LABEL hasModerator,
Forum_hasTag_Tag SOURCE KEY (ForumId) REFERENCES Forum (id)
DESTINATION KEY (TagId) REFERENCES Tag (id)
LABEL Forum_hasTag,
Organisation_isLocatedIn_Place SOURCE KEY (OrganisationId) REFERENCES Organisation (id)
DESTINATION KEY (PlaceId) REFERENCES Place (id)
LABEL Organisation_isLocatedIn,
Person_hasInterest_Tag SOURCE KEY (PersonId) REFERENCES Person (id)
DESTINATION KEY (interestId) REFERENCES Tag (id)
LABEL hasInterest,
Person_isLocatedIn_City SOURCE KEY (PersonId) REFERENCES Person (id)
DESTINATION KEY (CityId) REFERENCES Place (id)
LABEL Person_isLocatedIn,
Person_knows_person SOURCE KEY (Person1Id) REFERENCES Person (id)
DESTINATION KEY (Person2Id) REFERENCES Person (id)
LABEL Knows,
Person_likes_Comment SOURCE KEY (PersonId) REFERENCES Person (id)
DESTINATION KEY (CommentId) REFERENCES Message (id)
LABEL likes_Comment,
Person_likes_Post SOURCE KEY (PersonId) REFERENCES Person (id)
DESTINATION KEY (PostId) REFERENCES Message (id)
LABEL likes_Post,
Person_studyAt_University SOURCE KEY (PersonId) REFERENCES Person (id)
DESTINATION KEY (UniversityId) REFERENCES Organisation (id)
LABEL studyAt,
Person_workAt_Company SOURCE KEY (PersonId) REFERENCES Person (id)
DESTINATION KEY (CompanyId) REFERENCES Organisation (id)
LABEL workAt,
Place_isPartOf_Place SOURCE KEY (Place1Id) REFERENCES Place (id)
DESTINATION KEY (Place2Id) REFERENCES Place (id)
LABEL isPartOf,
Post_hasCreator_Person SOURCE KEY (PostId) REFERENCES Message (id)
DESTINATION KEY (PersonId) REFERENCES Person (id)
LABEL Post_hasCreator,
Message_hasCreator_Person SOURCE KEY (MessageId) REFERENCES Message (id)
DESTINATION KEY (PersonId) REFERENCES Person (id)
LABEL Message_hasCreator,
Message_hasTag_Tag SOURCE KEY (MessageId) REFERENCES Message (id)
DESTINATION KEY (TagId) REFERENCES Tag (id)
LABEL Message_hasTag,
Message_isLocatedIn_Country SOURCE KEY (MessageId) REFERENCES Message (id)
DESTINATION KEY (CountryId) REFERENCES Place (id)
LABEL Message_isLocatedIn,
Post_hasTag_Tag SOURCE KEY (PostId) REFERENCES Message (id)
DESTINATION KEY (TagId) REFERENCES Tag (id)
LABEL Post_hasTag,
Post_isLocatedIn_Country SOURCE KEY (PostId) REFERENCES Message (id)
DESTINATION KEY (CountryId) REFERENCES Place (id)
LABEL Post_isLocatedIn,
Tag_hasType_TagClass SOURCE KEY (TagId) REFERENCES Tag (id)
DESTINATION KEY (TagClassId) REFERENCES TagClass (id)
LABEL hasType,
TagClass_isSubClassOf_TagClass SOURCE KEY (TagClass1Id) REFERENCES TagClass (id)
DESTINATION KEY (TagClass2Id) REFERENCES TagClass (id)
LABEL isSubClassOf
);

# IS2
query IIIIIIII
-FROM GRAPH_TABLE (snb_projected
MATCH (a:person where a.id = 4026)-[i:Person_isLocatedIn]->(c:City)
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 971d28f

Please sign in to comment.