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

Support trailing commas in FROM clause #1645

Merged
merged 8 commits into from
Jan 14, 2025

Conversation

barsela1
Copy link
Contributor

@barsela1 barsela1 commented Jan 6, 2025

support trailing commas in FROM clause.

  • add a const global list of keyworads that are allowed to appear after FROM, called "ALLOWED_KEYWORD_AFTER_FROM"
  • Every dialict implement:
    --get_reserved_keyword_after_from function that returns ALLOWED_KEYWORD_AFTER_FROM as default. each dialect can customize the list if needed.
    -- supports_from_trailing_commas function that returns false as default but for each dialect that supports trailing commas in the FROM clause can customize the return value to true (e.g., Snowflake).
  • add a function "parse_from" to handle the FROM keyword. parse_from set and pass trailing_commas according to the return value of self.dialect.supports_from_trailing_commas().
  • change signature of parse_comma_separated_with_trailing_commas and is_parse_comma_separated_end_with_trailing_commas by adding parameter "reserved_keywords" (&[Keyword])
    -at is_parse_comma_separated_end_with_trailing_commas: keywords::RESERVED_FOR_COLUMN_ALIAS.contains(&kw.keyword) replaced by reserved_keywords so that the reserved_keywords can be determined by the current parsing state.
  • In other cases where is_parse_comma_separated_end_with_trailing_commas is used, keywords::RESERVED_FOR_COLUMN_ALIAS can be obtained by calling the default_reserved_keywords function and passing it through the reserved_keywords parameter.

tests:
-added new tests.
-all tests passed.

Copy link
Contributor

@iffyio iffyio left a comment

Choose a reason for hiding this comment

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

Thanks @barsela1! The changes look reasonable to me overall, left some comments

src/parser/mod.rs Outdated Show resolved Hide resolved
tests/sqlparser_snowflake.rs Outdated Show resolved Hide resolved
tests/sqlparser_snowflake.rs Outdated Show resolved Hide resolved
src/parser/mod.rs Outdated Show resolved Hide resolved
tests/sqlparser_snowflake.rs Outdated Show resolved Hide resolved
src/keywords.rs Outdated Show resolved Hide resolved
src/dialect/mod.rs Outdated Show resolved Hide resolved
src/dialect/mod.rs Outdated Show resolved Hide resolved
@barsela1 barsela1 requested a review from iffyio January 13, 2025 12:52
src/parser/mod.rs Outdated Show resolved Hide resolved
tests/sqlparser_snowflake.rs Outdated Show resolved Hide resolved
@barsela1 barsela1 requested a review from iffyio January 14, 2025 08:37
Copy link
Contributor

@iffyio iffyio left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks @barsela1!
cc @alamb

@iffyio iffyio changed the title From trailing commas Support trailing commas in FROM clause Jan 14, 2025
@iffyio
Copy link
Contributor

iffyio commented Jan 14, 2025

@barsela1 could you take a look to resolve the conflicts on the branch?

@alamb
Copy link
Contributor

alamb commented Jan 14, 2025

I also restarted the checks

@alamb alamb merged commit 36db176 into apache:main Jan 14, 2025
9 checks passed
@alamb
Copy link
Contributor

alamb commented Jan 14, 2025

Thanks @barsela1 and @iffyio ❤️

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.

3 participants