-
-
Notifications
You must be signed in to change notification settings - Fork 873
Trino: support ALTER TABLE #6996
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
Conversation
Coverage Results ✅
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
Added comprehensive support for Trino dialect's ALTER TABLE statements and NOT NULL constraints in CREATE TABLE statements, with complete test coverage.
- Extended
src/sqlfluff/dialects/dialect_trino.py
to implement ALTER TABLE operations (rename, add/drop columns, set properties) - Added new lexer and parser support for execute arrow ('=>') operator in dialect_trino.py
- Created
test/fixtures/dialects/trino/alter_table.sql
with extensive test cases for all ALTER TABLE variations - Enhanced
test/fixtures/dialects/trino/create_table.sql
to include NOT NULL constraint testing - Added comprehensive test coverage in corresponding YAML files for all new syntax features
5 files reviewed, 5 comments
Edit PR Review Bot Settings | Greptile
- column_definition: | ||
- naked_identifier: shipmentstatus | ||
- data_type: | ||
keyword: varchar | ||
- keyword: not | ||
- keyword: 'null' | ||
- comma: ',' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Inconsistent indentation in column definition compared to other similar blocks in this file. Other column definitions use double indentation.
- keyword: not | ||
- keyword: 'null' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Keep NOT NULL case consistent with other keywords in file (uppercase).
ALTER TABLE t1 SET PROPERTIES x = 'y'; | ||
ALTER TABLE t1 SET PROPERTIES foo = 123, bar = 456; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Add test for setting property to DEFAULT value, which is a documented feature for reverting properties to default values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have addressed it in these commits.
ec39758...992ab05
OneOf( | ||
Sequence( | ||
"SET", | ||
"DATA", | ||
"TYPE", | ||
Ref("DatatypeSegment"), | ||
), | ||
Sequence( | ||
"DROP", | ||
"NOT", | ||
"NULL", | ||
), | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: missing support for 'SET NOT NULL' in ALTER COLUMN
OneOf( | |
Sequence( | |
"SET", | |
"DATA", | |
"TYPE", | |
Ref("DatatypeSegment"), | |
), | |
Sequence( | |
"DROP", | |
"NOT", | |
"NULL", | |
), | |
), | |
OneOf( | |
Sequence( | |
"SET", | |
"DATA", | |
"TYPE", | |
Ref("DatatypeSegment"), | |
), | |
Sequence( | |
"SET", | |
"NOT", | |
"NULL" | |
), | |
Sequence( | |
"DROP", | |
"NOT", | |
"NULL", | |
), | |
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trino's ALTER TABLE
statement does not support the SET NOT NULL
syntax.
https://trino.io/docs/current/sql/alter-table.html
match_grammar = Sequence( | ||
"ALTER", | ||
"TABLE", | ||
Ref("IfExistsGrammar", optional=True), | ||
Ref("TableReferenceSegment"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: no support for 'ALTER TABLE ... COMMENT ON COLUMN' operation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trino's ALTER TABLE
statement does not support the COMMENT ON COLUMN
syntax.
https://trino.io/docs/current/sql/alter-table.html
"SET", | ||
"DATA", | ||
"TYPE", | ||
Ref("DatatypeSegment"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to support datatypes with brackets like in ColumnDefinitionSegment
?
Bracketed(Anything(), optional=True), # For types like VARCHAR(100)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@keraion
Thank you for your feedback!
DatatypeSegment
already supports syntax like VARCHAR(100)
.
sqlfluff/src/sqlfluff/dialects/dialect_trino.py
Lines 309 to 313 in 74aaf39
# String | |
Sequence( | |
OneOf("CHAR", "VARCHAR"), | |
Ref("BracketedArguments", optional=True), | |
), |
I fixed ColumnDefinitionSegment
and added the test.
df6bbc4
… for ALTER COLUMN
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
Brief summary of the change made
Added support for
ALTER TABLE
statementNOT NULL
inCREATE TABLE
statement.Are there any other side effects of this change that we should be aware of?
No
Pull Request checklist
Please confirm you have completed any of the necessary steps below.
Included test cases to demonstrate any code changes, which may be one or more of the following:
.yml
rule test cases intest/fixtures/rules/std_rule_cases
..sql
/.yml
parser test cases intest/fixtures/dialects
(note YML files can be auto generated withtox -e generate-fixture-yml
).test/fixtures/linter/autofix
.Added appropriate documentation for the change.
Created GitHub issues for any relevant followup/future enhancements if appropriate.