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

[ISSUE-2457] Add support for CTAS(Create Table As Select) statement #3400

Merged
merged 2 commits into from
Dec 13, 2021

Conversation

junli1026
Copy link
Contributor

@junli1026 junli1026 commented Dec 12, 2021

I hereby agree to the terms of the CLA available at: https://databend.rs/policies/cla/

Summary

Add support for create table as select statement

Changelog

  • Improvement

Related Issues

Fixes #2457

Test Plan

Unit Tests

Stateless Tests

DOC

Screen Shot 2021-12-12 at 4 59 18 PM
Screen Shot 2021-12-12 at 5 00 38 PM

@databend-bot
Copy link
Member

Thanks for the contribution!
I have applied any labels matching special text in your PR Changelog.

Please review the labels and make any necessary changes.

@vercel
Copy link

vercel bot commented Dec 12, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/databend/databend/4N4KUCXQbkenQrLoByPpCdZKHkPe
✅ Preview: https://databend-git-fork-junli1026-jun-dev-databend.vercel.app

[Deployment for 148faec canceled]

@mergify
Copy link
Contributor

mergify bot commented Dec 12, 2021

This pull request has merge conflicts that must be resolved before it can be merged. @junli1026 please rebase it 🙏

@codecov-commenter
Copy link

codecov-commenter commented Dec 12, 2021

Codecov Report

Merging #3400 (148faec) into main (4cdb600) will decrease coverage by 0%.
The diff coverage is 33%.

Impacted file tree graph

@@          Coverage Diff           @@
##            main   #3400    +/-   ##
======================================
- Coverage     61%     61%    -1%     
======================================
  Files        609     610     +1     
  Lines      34059   34185   +126     
======================================
+ Hits       20971   20995    +24     
- Misses     13088   13190   +102     
Impacted Files Coverage Δ
query/src/interpreters/interpreter_table_create.rs 44% <16%> (-50%) ⬇️
query/src/sql/statements/statement_create_table.rs 66% <41%> (-5%) ⬇️
common/planners/src/plan_display_indent.rs 97% <100%> (+<1%) ⬆️
common/planners/src/plan_table_create.rs 96% <100%> (+<1%) ⬆️
...ommon/functions/src/scalars/strings/find_in_set.rs 5% <0%> (ø)
common/functions/src/scalars/strings/string.rs 97% <0%> (+<1%) ⬆️
query/src/sql/sql_parser.rs 85% <0%> (+<1%) ⬆️
common/management/src/cluster/cluster_mgr.rs 81% <0%> (+2%) ⬆️
query/src/api/http/v1/logs.rs 82% <0%> (+3%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4cdb600...148faec. Read the comment docs.

@junli1026 junli1026 changed the title Add support for CTAS(Create Table As Select) statement [ISSUE-2457] Add support for CTAS(Create Table As Select) statement Dec 13, 2021
@junli1026 junli1026 marked this pull request as ready for review December 13, 2021 00:07
@junli1026 junli1026 requested a review from BohuTANG as a code owner December 13, 2021 00:07
@BohuTANG BohuTANG requested a review from sundy-li December 13, 2021 00:13
@junli1026
Copy link
Contributor Author

Thanks @dantengsky for adding the 'query' field in the sql parser. It is very helpful!

@BohuTANG
Copy link
Member

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented Dec 13, 2021

update

✅ Branch has been successfully updated

@dantengsky
Copy link
Member

look great to me, thanks @junli1026 !

@BohuTANG

do we need to clarify(in doc) that the "append columns" semantic of MySQL CTAS are not supported(by design) in our impl?

from https://dev.mysql.com/doc/refman/8.0/en/create-table-select.html,

Notice that the columns from the SELECT statement are appended to the right side of the table, not overlapped onto it. Take the following example




mysql> SELECT * FROM foo;
+---+
| n |
+---+
| 1 |
+---+

mysql> CREATE TABLE bar (m INT) SELECT n FROM foo;
Query OK, 1 row affected (0.02 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> SELECT * FROM bar;
+------+---+
| m    | n |
+------+---+
| NULL | 1 |
+------+---+
1 row in set (0.00 sec)

personally, I never used this feature of MySQL. not mention this in the doc is ok for me.

@dantengsky
Copy link
Member

Thanks @dantengsky for adding the 'query' field in the sql parser. It is very helpful!

Yes, it is! but it is contributed by @AngleNet in PR #3356, thanks @AngleNet !

CREATE TABLE db2.test2 LIKE db1.test1;
INSERT INTO db2.test2 VALUES (3, 5);
SELECT a+b FROM db2.test2;
-- test 'create table as select' statement, expect db2.test3 has the data from db1.test1 with casting
CREATE TABLE db2.test3(x Varchar, y Varchar) AS SELECT * FROM db1.test1;
Copy link
Member

@BohuTANG BohuTANG Dec 13, 2021

Choose a reason for hiding this comment

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

Looks great 👍
Do you have the plan change this test to

CREATE TABLE db1.test1(a INT, b INT) ENGINE=MEMORY;

... ...

CREATE TABLE db2.test3(x Varchar, y Varchar) ENGINE=FUSE AS SELECT * FROM db1.test1;
... ...

🤔

@BohuTANG
Copy link
Member

@dantengsky
This will be addressed in #3439

@junli1026
Copy link
Contributor Author

Thanks @dantengsky for adding the 'query' field in the sql parser. It is very helpful!

Yes, it is! but it is contributed by @AngleNet in PR #3356, thanks @AngleNet !

Thank you @dantengsky all the same for pointing me to @AngleNet

Thank you @AngleNet for you contribution !

@dantengsky
Copy link
Member

/LGTM

@databend-bot
Copy link
Member

Wait for another reviewer approval

@BohuTANG
Copy link
Member

/LGTM

Thank you @junli1026 !

@databend-bot
Copy link
Member

CI Passed
Reviewers Approved
Let's Merge
Thank you for the PR @junli1026

@databend-bot databend-bot merged commit 1f29cfc into databendlabs:main Dec 13, 2021
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.

Support create table as/like query
5 participants