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

feat: support Create Table ... Like #3372

Merged
merged 5 commits into from
Mar 2, 2024
Merged

Conversation

KKould
Copy link
Collaborator

@KKould KKould commented Feb 23, 2024

I hereby agree to the terms of the GreptimeDB CLA

What's changed and what's your intention?

Support: create table xxx like yyy
ref: https://dev.mysql.com/doc/refman/8.0/en/create-table-like.html

public=> CREATE TABLE t1 ( a INT, b STRING, c INT, ts timestamp TIME INDEX);
OK 0
public=> CREATE TABLE t2 LIKE t1;
OK 0
public=> DESCRIBE t2;
 Column |         Type         | Key | Null | Default | Semantic Type 
--------+----------------------+-----+------+---------+---------------
 a      | Int32                |     | YES  |         | FIELD
 b      | String               |     | YES  |         | FIELD
 c      | Int32                |     | YES  |         | FIELD
 ts     | TimestampMillisecond | PRI | NO   |         | TIMESTAMP
(4 rows)

Tips:
I was using this case: CREATE TABLE t1 ( a INT, b STRING, c INT, ts timestamp TIME INDEX); then run CREATE TABLE t2 LIKE t1;, the create_partitions_stmt method returned Some and caused the index to go out of bounds, so I did additional checks. Is this a bug? Because this table does not specify Partitions
bebd5cede7cdff3aef71baa6efbb7a2

ref: https://github.com/GreptimeTeam/greptimedb/pull/3372/files#diff-2563d4135f7e232aaec6a39204e6e9afc21801dff0c957772ce4dd7d3bd271d4R109

Checklist

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.
  • This PR does not require documentation updates.

Refer to a related PR or issue link (optional)

#2509

@github-actions github-actions bot added the docs-not-required This change does not impact docs. label Feb 23, 2024
Copy link

codecov bot commented Feb 23, 2024

Codecov Report

Attention: Patch coverage is 72.13115% with 17 lines in your changes are missing coverage. Please review.

Project coverage is 84.60%. Comparing base (dc205a2) to head (0d5948e).
Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3372      +/-   ##
==========================================
- Coverage   85.07%   84.60%   -0.47%     
==========================================
  Files         889      889              
  Lines      146377   146454      +77     
==========================================
- Hits       124525   123906     -619     
- Misses      21852    22548     +696     

Copy link
Contributor

@killme2008 killme2008 left a comment

Choose a reason for hiding this comment

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

Great work! Thank you. I have a few suggestions, please take a look.

src/operator/src/expr_factory.rs Outdated Show resolved Hide resolved
show_create_table::create_table_stmt(&table_ref.table_info(), quote_style)
.context(error::ParseQuerySnafu)?;
create_stmt.name = stmt.name;
create_stmt.if_not_exists = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like create table like can support if_not_exists too, just like

CREATE TABLE IF NOT EXISTS snapshot LIKE source_data;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In fact, I thought so at first, but I checked MySQL's Create Table ... Like and it seems that it is not supported, so I chose to keep it unified. Of course, this is up to you to decide.

ref: https://dev.mysql.com/doc/refman/8.0/en/create-table-like.html

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. Let's leave it currently.

src/sql/src/statements/create.rs Outdated Show resolved Hide resolved
@v0y4g3r v0y4g3r self-requested a review February 25, 2024 06:59
@KKould
Copy link
Collaborator Author

KKould commented Feb 25, 2024

my grandmother passed away yesterday, and I will handle the review suggestions you provided in a few days

@killme2008
Copy link
Contributor

my grandmother passed away yesterday, and I will handle the review suggestions you provided in a few days

Sorry to hear that. May she rest in peace.

src/sql/src/parsers/create_parser.rs Outdated Show resolved Hide resolved
tests/cases/standalone/common/create/create.sql Outdated Show resolved Hide resolved
@KKould
Copy link
Collaborator Author

KKould commented Feb 28, 2024

It seems you didn’t notice the content in Tips. please take a look

Copy link
Contributor

@killme2008 killme2008 left a comment

Choose a reason for hiding this comment

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

LGTM

Signed-off-by: tison <[email protected]>
Copy link
Collaborator

@tisonkun tisonkun left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution @KKould! Excellent patch.

I suggest you try to check out a different branch (rather than main) the next time you submit a PR so that we can avoid some subtle issues like:

$ git push
fatal: The upstream branch of your current branch does not match
the name of your current branch.  To push to the upstream branch
on the remote, use

    git push https://github.com/KKould/greptimedb.git HEAD:main

To push to the branch of the same name on the remote, use

    git push https://github.com/KKould/greptimedb.git HEAD

To choose either option permanently, see push.default in 'git help config'.

To avoid automatically configuring an upstream branch when its name
won't match the local branch, see option 'simple' of branch.autoSetupMerge
in 'git help config'.

Although we can use git push https://github.com/KKould/greptimedb.git HEAD:main as suggested, it's easy to make mistake.

@tisonkun tisonkun enabled auto-merge March 2, 2024 06:20
@tisonkun tisonkun added this pull request to the merge queue Mar 2, 2024
Merged via the queue into GreptimeTeam:main with commit 00cbbc9 Mar 2, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-not-required This change does not impact docs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants