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

Support CREATE OR REPLACE TABLE #2613

Merged
merged 4 commits into from
May 28, 2022
Merged

Support CREATE OR REPLACE TABLE #2613

merged 4 commits into from
May 28, 2022

Conversation

HuSen8891
Copy link
Contributor

Which issue does this PR close?

Closes #2605

Rationale for this change

replace the table content if table already exits
❯ create table xx as values(1,2),(3,4);
+---------+---------+
| column1 | column2 |
+---------+---------+
| 1 | 2 |
| 3 | 4 |
+---------+---------+
2 rows in set. Query took 0.004 seconds.

❯ create or replace table xx as values(5,6);
+---------+---------+
| column1 | column2 |
+---------+---------+
| 5 | 6 |
+---------+---------+
1 row in set. Query took 0.004 seconds.

if 'if not exists' and 'or replace' are both specified, treat as 'or replace'
❯ create or replace table if not exists xx as values(7,8);
+---------+---------+
| column1 | column2 |
+---------+---------+
| 7 | 8 |
+---------+---------+
1 row in set. Query took 0.002 seconds.

What changes are included in this PR?

adjust rules for create table in context.rs

@github-actions github-actions bot added the datafusion Changes in the datafusion crate label May 25, 2022
Copy link
Member

@Ted-Jiang Ted-Jiang left a comment

Choose a reason for hiding this comment

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

@waynexia
Copy link
Member

if 'if not exists' and 'or replace' are both specified, treat as 'or replace'

I personally feel weird about IF NOT EXIST coexist with OR REPLACE. They are asking for two different behaviors. Should we reject this kind of query like others ( 1, 2 )?

@HuSen8891
Copy link
Contributor Author

@AssHero Thanks for your work 👍 Maybe you can add some test like

https://github.com/apache/arrow-datafusion/blob/0c4ffd4f7b064a8f4e4a167e2e4c913389056968/datafusion/core/tests/sql/create_drop.rs#L22-L46

ok, i'll add some test cases

@HuSen8891
Copy link
Contributor Author

if 'if not exists' and 'or replace' are both specified, treat as 'or replace'

I personally feel weird about IF NOT EXIST coexist with OR REPLACE. They are asking for two different behaviors. Should we reject this kind of query like others ( 1, 2 )?

'create or replace if not exists' is not supported in MySQL/PG, and is not permitted in databricks.
we can have a disscussion about how to deal with it.

@andygrove
Copy link
Member

Thanks for the contribution @AssHero. I also would like to see IF NOT EXISTS and OR REPLACE as separate options that cannot be used together. LGTM otherwise.

@HuSen8891
Copy link
Contributor Author

Thanks for the contribution @AssHero. I also would like to see IF NOT EXISTS and OR REPLACE as separate options that cannot be used together. LGTM otherwise.

I'll separate the 'IF NOT EXISTS' and 'OR REPLACE', and report the error if both specified.

@github-actions github-actions bot added core Core DataFusion crate logical-expr Logical plan and expressions sql SQL Planner labels May 28, 2022
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.

Looks great -- thank you @AssHero, @Ted-Jiang and @waynexia

@alamb alamb merged commit df2094f into apache:master May 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core DataFusion crate datafusion Changes in the datafusion crate logical-expr Logical plan and expressions sql SQL Planner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support CREATE OR REPLACE TABLE
5 participants