Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix property graph case-sentisitivity #188

Merged
merged 4 commits into from
Dec 21, 2024

Conversation

dentiny
Copy link
Contributor

@dentiny dentiny commented Dec 21, 2024

Fix issue: #176

Tables names are case-insensitive. Example SQL to display:

-- Create table with lower-case.
D CREATE TABLE test_person (name TEXT);
-- Query table with upper-case.
D SELECT * FROM Test_person;
┌─────────┐
│  name   │
│ varchar │
├─────────┤
│ 0 rows  │
└─────────┘

This PR uses case-intensitive map to store registered property graphs.

Test result:

ubuntu@hjiang-devbox-pg$ ./build/debug/duckdb
v1.1.4-dev1 c380346433
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
D CREATE TABLE Student(id BIGINT, name VARCHAR);
D CREATE TABLE know(src BIGINT, dst BIGINT, createDate BIGINT);
D CREATE TABLE School(school_name VARCHAR, school_id BIGINT, school_kind BIGINT);
D INSERT INTO Student VALUES (0, 'Daniel'), (1, 'Tavneet'), (2, 'Gabor'), (3, 'Peter');
D INSERT INTO know VALUES (0,1, 10), (0,2, 11), (0,3, 12), (1,2, 14), (1,3, 15), (2,3, 16);
D -CREATE PROPERTY GRAPH pg VERTEX TABLES (    Student PROPERTIES ( id, name ) LABEL Person,    School as school_alias PROPERTIES ( school_id, school_name ) LABEL School IN School_kind (Hogeschool, University)    )EDGE TABLES (    know    SOURCE KEY ( src ) REFERENCES Student ( id )            DESTINATION KEY ( dst ) REFERENCES Student ( id )            PROPERTIES ( createDate ) LABEL Knows    );
┌─────────┐
│ Success │
│ boolean │
├─────────┤
│ 0 rows  │
└─────────┘
D -SELECT count(id)FROM  GRAPH_TABLE (PG     MATCH p = (s1:Person)-[k:Knows]->(s2:Person WHERE s2.name='Daniel')     COLUMNS (s1.id));
┌───────────┐
│ count(id) │
│   int64   │
├───────────┤
│         0 │
└───────────┘
D -SELECT count(id)FROM  GRAPH_TABLE (PG     MATCH p = (s1:Person)-[k:Knows]->(s2:Person WHERE s2.name='Tavneet')     COLUMNS (s1.id));
┌───────────┐
│ count(id) │
│   int64   │
├───────────┤
│         1 │
└───────────┘
D -SELECT count(id)FROM  GRAPH_TABLE (PG     MATCH p = (s1:Person)-[k:Knows]->(s2:Person WHERE s2.name='Gabor')     COLUMNS (s1.id));
┌───────────┐
│ count(id) │
│   int64   │
├───────────┤
│         2 │
└───────────┘
D -SELECT count(id)FROM  GRAPH_TABLE (PG     MATCH p = (s1:Person)-[k:Knows]->(s2:Person WHERE s2.name='Peter')     COLUMNS (s1.id));
┌───────────┐
│ count(id) │
│   int64   │
├───────────┤
│         3 │
└───────────┘

@@ -33,7 +34,7 @@ class DuckPGQState : public ClientContextState {
// unnamed graph tables

//! Property graphs that are registered
std::unordered_map<string, unique_ptr<CreateInfo>> registered_property_graphs;
case_insensitive_map_t<unique_ptr<CreateInfo>> registered_property_graphs;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only change, all others are made by linters via make format.

@@ -107,6 +107,7 @@ void DuckPGQState::PopulateEdgeSpecificFields(unique_ptr<DataChunk> &chunk,
void DuckPGQState::ExtractListValues(const Value &list_value,
vector<string> &output) {
auto children = ListValue::GetChildren(list_value);
output.reserve(output.size() + children.size());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reserve memory before emplace.

statement ok
-SELECT count(id)
FROM
GRAPH_TABLE (PG
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The property graph created at L43 is of lower case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to double check, could you change the test to verify it has the right result? Instead of only checking that the query doesn't crash :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the PR description to reflect the manual test result, which looks ok to me.

Let me check how to leverage the testing framework to verify the output as well.
I feel confused at the first place, since other SELECT statements are also annotated as statement ok.

statement ok
SELECT * FROM get_csr_ptr(0);

Let me check and get back to you. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated! PTAL, thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! LGTM

@Dtenwolde
Copy link
Contributor

Thanks for the PR! I wasn't aware this would be such a minor change haha

Regarding the formatting: there is a PR ongoing to add formatting to the CI. Once that's in place we'll focus more on making sure the formatting is correct. duckdb/extension-ci-tools#121

@dentiny
Copy link
Contributor Author

dentiny commented Dec 21, 2024

Thanks for the PR! I wasn't aware this would be such a minor change haha

Thank you for the quick review, and giving me the opportunity! And apologize for the latency (was working on something else) :(

Regarding the formatting: there is a PR ongoing to add formatting to the CI. Once that's in place we'll focus more on making sure the formatting is correct. duckdb/extension-ci-tools#121

Yeah I'm aware of it (last time you pointed me to your formatting CI PR), looking forward to the integration!

@dentiny dentiny requested a review from Dtenwolde December 21, 2024 14:22
@Dtenwolde
Copy link
Contributor

Dtenwolde commented Dec 21, 2024

I appreciate your contribution very much, even if it was a minor fix. Don't worry about the latency!

Just going to wait for the CI to finish before merging this :)

@Dtenwolde Dtenwolde merged commit bac1372 into cwida:main Dec 21, 2024
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants