Skip to content

feat: support ALTER TABLE ... MODIFY COLUMN ... ...#3796

Merged
WenyXu merged 17 commits intoGreptimeTeam:mainfrom
KKould:feat/change_coumn_type_parse
Apr 30, 2024
Merged

feat: support ALTER TABLE ... MODIFY COLUMN ... ...#3796
WenyXu merged 17 commits intoGreptimeTeam:mainfrom
KKould:feat/change_coumn_type_parse

Conversation

@KKould
Copy link
Copy Markdown
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 a team, MichaelScofield and v0y4g3r 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
@codecov
Copy link
Copy Markdown

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
Copy Markdown
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.

Comment thread src/common/meta/src/ddl/alter_table/region_request.rs Outdated
Comment thread src/store-api/src/region_request.rs Outdated
Comment thread Cargo.toml Outdated
@killme2008
Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
Member

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
Copy Markdown
Collaborator Author

KKould commented Apr 25, 2024

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

Comment thread src/common/meta/src/ddl/alter_table/region_request.rs Outdated
@MichaelScofield
Copy link
Copy Markdown
Collaborator

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

Comment thread src/sql/src/parsers/alter_parser.rs Outdated
@WenyXu
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Collaborator Author

KKould commented Apr 25, 2024

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

Comment thread src/common/meta/src/ddl/alter_table/region_request.rs Outdated
Comment thread Cargo.toml Outdated
Comment thread src/store-api/src/region_request.rs Outdated
@KKould KKould force-pushed the feat/change_coumn_type_parse branch from ddd689f to 4bd503f Compare April 26, 2024 13:09
@evenyag evenyag requested a review from MichaelScofield April 28, 2024 03:00
@evenyag
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Comment thread src/sql/src/parsers/alter_parser.rs Outdated
Comment thread src/sql/src/parsers/alter_parser.rs
Comment thread src/sql/src/parsers/alter_parser.rs Outdated
Comment thread src/sql/src/parser.rs Outdated
Comment thread src/sql/src/parser.rs Outdated
Comment thread src/sql/src/parser.rs Outdated
Comment thread src/operator/src/expr_factory.rs Outdated
@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
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.

7 participants