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 ALTER TABLE ... MODIFY COLUMN ... ... #3796

Merged
merged 17 commits into from
Apr 30, 2024

Conversation

KKould
Copy link
Collaborator

@KKould KKould commented Apr 24, 2024

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

#3517
GreptimeTeam/greptime-proto#149

What's changed and what's your intention?

Support: alter table xxx modify column xxx xxx
https://dev.mysql.com/doc/refman/8.0/en/alter-table.html

public=> CREATE TABLE test(id INTEGER PRIMARY KEY, i INTEGER NULL, j TIMESTAMP TIME INDEX, k BOOLEAN);
OK 0
public=> ALTER TABLE test MODIFY COLUMN I STRING;
OK 0
public=> DESCRIBE test;
 Column |         Type         | Key | Null | Default | Semantic Type 
--------+----------------------+-----+------+---------+---------------
 id     | Int32                | PRI | YES  |         | TAG
 i      | String               |     | YES  |         | FIELD
 j      | TimestampMillisecond | PRI | NO   |         | TIMESTAMP
 k      | Boolean              |     | YES  |         | FIELD
(4 rows)

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.

@KKould KKould requested review from v0y4g3r, MichaelScofield and a team as code owners April 24, 2024 10:27
@github-actions github-actions bot added the docs-not-required This change does not impact docs. label Apr 24, 2024
@KKould KKould changed the title feat: support ALTER TABLE xxx ALTER COLUMN xxx TYPE xxx feat: support ALTER TABLE ... ALTER COLUMN ... TYPE ... Apr 24, 2024
@KKould KKould force-pushed the feat/change_coumn_type_parse branch from b8fd671 to 6307c7c Compare April 24, 2024 11:06
Copy link

codecov bot commented Apr 24, 2024

Codecov Report

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

Project coverage is 85.29%. Comparing base (701aba9) to head (caac6d4).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3796      +/-   ##
==========================================
- Coverage   85.64%   85.29%   -0.35%     
==========================================
  Files         954      954              
  Lines      163037   163253     +216     
==========================================
- Hits       139625   139246     -379     
- Misses      23412    24007     +595     

Copy link
Contributor

@evenyag evenyag left a comment

Choose a reason for hiding this comment

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

Mostly looks good.

src/common/meta/src/ddl/alter_table/region_request.rs Outdated Show resolved Hide resolved
src/store-api/src/region_request.rs Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
@killme2008
Copy link
Contributor

Good job! But why not use the common SQL syntax?

ALTER TABLE table_name
MODIFY COLUMN column_name datatype;

It would be better that the user doesn't need to learn a new syntax.

@evenyag
Copy link
Contributor

evenyag commented Apr 25, 2024

But why not use the common SQL syntax?

This is the syntax PostgreSQL currently uses.
https://www.postgresql.org/docs/current/sql-altertable.html

ALTER TABLE distributors
    ALTER COLUMN address TYPE varchar(80),
    ALTER COLUMN name TYPE varchar(100);

@killme2008
Copy link
Contributor

But why not use the common SQL syntax?

This is the syntax PostgreSQL currently uses. https://www.postgresql.org/docs/current/sql-altertable.html

ALTER TABLE distributors
    ALTER COLUMN address TYPE varchar(80),
    ALTER COLUMN name TYPE varchar(100);

Yes, but MySQL, Oracle, and SQLServer are using modify column.

@KKould
Copy link
Collaborator Author

KKould commented Apr 25, 2024

tips: sqlparser-rs already supports modify column: sqlparser-rs/sqlparser-rs#1216

@MichaelScofield
Copy link
Collaborator

Create an issue here for reminding us the docs after this whole feature is done.

@WenyXu
Copy link
Member

WenyXu commented Apr 25, 2024

Hi @KKould There are some conflicts

@KKould KKould force-pushed the feat/change_coumn_type_parse branch from f1db676 to f7668c6 Compare April 25, 2024 15:22
@WenyXu
Copy link
Member

WenyXu commented Apr 25, 2024

tips: sqlparser-rs already supports modify column: sqlparser-rs/sqlparser-rs#1216

Is it possible to upgrade the SQL parser-rs to the latest?

@KKould
Copy link
Collaborator Author

KKould commented Apr 25, 2024

I created PR: GreptimeTeam/sqlparser-rs#11 to support modify column

src/common/meta/src/ddl/alter_table/region_request.rs Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
src/store-api/src/region_request.rs Outdated Show resolved Hide resolved
@KKould KKould force-pushed the feat/change_coumn_type_parse branch from ddd689f to 4bd503f Compare April 26, 2024 13:09
@evenyag
Copy link
Contributor

evenyag commented Apr 28, 2024

If the CI failure in GreptimeTeam/sqlparser-rs#11 is easy to fix. We could implement the final syntax in this PR. @KKould Could you please take a look?

@KKould
Copy link
Collaborator Author

KKould commented Apr 28, 2024

If the CI failure in GreptimeTeam/sqlparser-rs#11 is easy to fix. We could implement the final syntax in this PR. @KKould Could you please take a look?

I checked before and it seems that these errors are caused by other PRs, not this PR.

@Taylor-lagrange
Copy link
Contributor

The pr should be open on v0.44.x instead of the main branch, because the sqlparser code will be synchronized with datafusion' sqlparser code regularly. However, I still recommend not to change the keywords and use parser directly to identify the token to avoid conflict when sync upstream sqlparser later.

@KKould KKould force-pushed the feat/change_coumn_type_parse branch from 2af1e83 to 83efb1c Compare April 28, 2024 06:12
@KKould KKould changed the title feat: support ALTER TABLE ... ALTER COLUMN ... TYPE ... feat: support ALTER TABLE ... MODIFY COLUMN ... ... Apr 28, 2024
@KKould KKould requested a review from evenyag April 28, 2024 06:27
src/sql/src/parsers/alter_parser.rs Outdated Show resolved Hide resolved
src/sql/src/parsers/alter_parser.rs Show resolved Hide resolved
src/sql/src/parsers/alter_parser.rs Outdated Show resolved Hide resolved
src/sql/src/parser.rs Outdated Show resolved Hide resolved
src/sql/src/parser.rs Outdated Show resolved Hide resolved
src/sql/src/parser.rs Outdated Show resolved Hide resolved
@WenyXu WenyXu enabled auto-merge April 30, 2024 02:58
@WenyXu WenyXu added this pull request to the merge queue Apr 30, 2024
Merged via the queue into GreptimeTeam:main with commit aba5e41 Apr 30, 2024
21 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.

None yet

7 participants