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 CREATE SCHEMA schema name double quoting issue. #5059

Merged
merged 1 commit into from
Jan 26, 2023

Conversation

neumark
Copy link
Contributor

@neumark neumark commented Jan 25, 2023

Which issue does this PR close?

Closes #5058

Rationale for this change

The changes fix a bug resulting in double-quoted identifiers in SQL query plans.

What changes are included in this PR?

The changes affect logical plan creation in datafusion/sql/src/statement.rs

Are these changes tested?

The PR includes an integration test for the CREATE SCHEMA SQL statement.

Are there any user-facing changes?

User queries with quoted identifiers will work as expected due to this change.

@github-actions github-actions bot added the sql SQL Planner label Jan 25, 2023
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.

Thank you @neumark -- this is looking great. I had a question about some other corner cases but I think this PR is an improvement on master so it could be merged

SchemaName::UnnamedAuthorization(auth) => ident_to_string(auth),
SchemaName::NamedAuthorization(schema_name, auth) => format!(
"{}.{}",
object_name_to_string(schema_name),
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this name needs to be normalized too

like CREATE SCHEMA Foo should create the schema foo (not Foo)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey, thank you so much for the quick and positive response!
Honestly, I have no idea if Foo should become foo, but I'm happy to update the code to call utils::normalize_ident() on ident.value if necessary!

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I think it should be lowercase, here is a demonstration of how that works in postgres:

postgres=# drop schema foo;
DROP SCHEMA
postgres=# create schema foo;
CREATE SCHEMA
postgres=# drop schema foo;
DROP SCHEMA
postgres=# create schema FoO;
CREATE SCHEMA
postgres=# create schema foo;
ERROR:  schema "foo" already exists

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the input! The code in the PR now calls normalize_ident and includes an integration test asserting this behavior.

@alamb alamb merged commit 8b716d3 into apache:master Jan 26, 2023
@alamb
Copy link
Contributor

alamb commented Jan 26, 2023

Thanks @neumark

@ursabot
Copy link

ursabot commented Jan 26, 2023

Benchmark runs are scheduled for baseline = e24a7ec and contender = 8b716d3. 8b716d3 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sql SQL Planner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Quoted schema and table names result in double-quoted names in logical plan.
3 participants