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

Add primary key information to CreateMemoryTable LogicalPlan node #5835

Merged
merged 4 commits into from
Apr 3, 2023

Conversation

avantgardnerio
Copy link
Contributor

Which issue does this PR close?

Closes #5834.

Rationale for this change

As a developer building a database atop DataFusion, it would be useful to have knowledge of primary keys retained in the LogicalPlan.

What changes are included in this PR?

A new primary_key field on LogicalPlan::CreateMemoryTable

Are these changes tested?

Sort of - there's a test that broke before, but I couldn't figure out what prints this LogicalPlan node, so I wasn't able to add the pk info to the Debug trait and assert that.

Are there any user-facing changes?

create table statements that used to fail (e.g. with primary key clauses) will now not fail. I'm not sure if that's an issue for anyone.

@github-actions github-actions bot added core Core DataFusion crate logical-expr Logical plan and expressions sql SQL Planner labels Apr 3, 2023
@avantgardnerio avantgardnerio changed the title Bg pks Add primary key information to CreateMemoryTable LogicalPlan node Apr 3, 2023
Copy link
Member

@yjshen yjshen left a comment

Choose a reason for hiding this comment

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

Thanks @avantgardnerio! Looks good overall, I left some minor comments.

Also, I find it easier to review without whitespace: https://github.com/apache/arrow-datafusion/pull/5835/files?diff=split&w=1

datafusion/sql/src/statement.rs Outdated Show resolved Hide resolved
datafusion/expr/src/logical_plan/plan.rs Show resolved Hide resolved
datafusion/sql/tests/integration_test.rs Show resolved Hide resolved
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks @avantgardnerio -- this is looking good

datafusion/sql/src/statement.rs Show resolved Hide resolved
datafusion/sql/src/statement.rs Outdated Show resolved Hide resolved
Brent Gardner added 2 commits April 3, 2023 08:50
@avantgardnerio avantgardnerio requested review from alamb and yjshen April 3, 2023 15:16
@avantgardnerio
Copy link
Contributor Author

Okay fellas, I think this is ready...

fn plan_create_table_with_pk() {
let sql = "create table person (id int, name string, primary key(id))";
let plan = r#"
CreateMemoryTable: Bare { table: "person" } primary_key=[id]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should show PK

fn plan_create_table_no_pk() {
let sql = "create table person (id int, name string)";
let plan = r#"
CreateMemoryTable: Bare { table: "person" }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does not change existing behavior if no PK

}

#[test]
#[should_panic(expected = "Non-primary unique constraints are not supported")]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unhanded syntax causes errors.

@avantgardnerio avantgardnerio merged commit 536f2b8 into apache:main Apr 3, 2023
@avantgardnerio avantgardnerio deleted the bg_pks branch April 3, 2023 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core DataFusion crate logical-expr Logical plan and expressions sql SQL Planner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Carry primary key information from AST to LogicalPlan
3 participants