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

(WIP) Adds support for generated columns in mysql (in create statements) #5867

Closed

Conversation

jspaezp
Copy link

@jspaezp jspaezp commented May 12, 2024

Brief summary of the change made

This PR attempts to add support for generated columns in the mysql dialect.
Related: #4960

Are there any other side effects of this change that we should be aware of?

Not that I know ...

Pull Request checklist

  • Please confirm you have completed any of the necessary steps below.

    • Added test file, will generate yml when I finish the implementation.
  • Included test cases to demonstrate any code changes, which may be one or more of the following:

    • .yml rule test cases in test/fixtures/rules/std_rule_cases.
    • .sql/.yml parser test cases in test/fixtures/dialects (note YML files can be auto generated with tox -e generate-fixture-yml).
    • Full autofix test cases in test/fixtures/linter/autofix.
    • Other.
  • Added appropriate documentation for the change.

  • Created GitHub issues for any relevant followup/future enhancements if appropriate.

@jspaezp
Copy link
Author

jspaezp commented May 12, 2024

Hello there! I am not 100% sure how to finish the implementation to get this past the finish line ...

What I have:
If I am understanding correctly... I want to implement a GeneratedColumnDefinitionSegment (in the PR)

BUT I am failing to understand how the copy -> insert/replace/add mechanism works. IF I AM UNDERSTANDING THIS CORRECTLY ... the mysql dialect uses ColumnDefinitionSegment (

class ColumnDefinitionSegment(BaseSegment):
) because it is used in the ansi dialect definition of CreateTableStatementSegment (https://github.com/jspaezp/sqlfluff/blob/1d4fd8d288e9d19aa544d3d92885b30788234470/src/sqlfluff/dialects/dialect_ansi.py#L3188) ... if I wanted to 'insert' into that definition

                    Delimited(
                        OneOf(
                            Ref("TableConstraintSegment"),
                            Ref("ColumnDefinitionSegment"),
                            # <------- HERE add `Ref("GeneratedColumnDefinitionSegment")`
                        ),
                    )

that could be done in ... here (mysql re-definition of CreateTableStatementSegment)

class CreateTableStatementSegment(ansi.CreateTableStatementSegment):
"""Create table segment.
https://dev.mysql.com/doc/refman/8.0/en/create-table.html
"""
match_grammar = ansi.CreateTableStatementSegment.match_grammar.copy(
insert=[
AnyNumberOf(
Sequence(
Ref.keyword("DEFAULT", optional=True),
Ref("ParameterNameSegment"),
Ref("EqualsSegment", optional=True),
OneOf(Ref("LiteralGrammar"), Ref("ParameterNameSegment")),
),
),
],
)
... but I do not 100% understand what the ansi.CreateTableStatementSegment.match_grammar.copy(insert= [...]) pattern does.
Any help would be appreciated! (edited)

@greg-finley
Copy link
Contributor

Thanks for the PR, but closing in favor of #5939

@greg-finley greg-finley closed this Jun 3, 2024
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.

None yet

2 participants