Skip to content

Conversation

@andygrove
Copy link
Member

Summary

This PR replaces 6 dialect_of! macro invocations in the parser with dedicated Dialect trait methods. This improves the separation between generic parsing logic and dialect-specific behavior, making it easier for custom dialects to override behavior without modifying the parser.

Motivation

The codebase currently has ~134 dialect_of! macro calls scattered throughout the parser. The dialect module documentation already recommends using trait methods instead:

Note: when possible please the new style, adding a method to the Dialect trait rather than using this macro.

The benefits of adding a method on Dialect over this macro are:

  1. user defined Dialects can customize the parsing behavior
  2. The differences between dialects can be clearly documented in the trait

This PR is a proof-of-concept to gauge community interest before doing more of these refactorings.

Changes

New trait methods added to Dialect:

Method Dialects Description
supports_extract_comma_syntax() Snowflake, Generic EXTRACT(YEAR, d) comma syntax
supports_subquery_as_function_arg() Snowflake FLATTEN(SELECT ...) without extra parens
supports_create_view_comment_syntax() Snowflake, Generic CREATE VIEW ... COMMENT = '...'
supports_array_typedef_without_element_type() Snowflake ARRAY type without element specification
supports_parens_around_table_factor() Snowflake, Generic FROM (mytable) extra parens
supports_values_as_table_factor() Snowflake, Databricks, Generic FROM VALUES (1,'a') without parens

Each method includes documentation with examples and links to dialect documentation.

Test plan

  • All existing tests pass
  • cargo fmt and cargo clippy pass
  • No new tests needed as this is a refactoring of existing behavior

🤖 Generated with Claude Code

Replace 6 `dialect_of!` macro invocations in the parser with dedicated
Dialect trait methods. This improves the separation between generic
parsing logic and dialect-specific behavior, making it easier for
custom dialects to override behavior without modifying the parser.

New trait methods added:
- `supports_extract_comma_syntax()` - EXTRACT(YEAR, d) syntax
- `supports_subquery_as_function_arg()` - FLATTEN(SELECT ...) without parens
- `supports_create_view_comment_syntax()` - CREATE VIEW ... COMMENT = '...'
- `supports_array_typedef_without_element_type()` - ARRAY without element type
- `supports_parens_around_table_factor()` - FROM (mytable) extra parens
- `supports_values_as_table_factor()` - FROM VALUES (1,'a') without parens

This follows the guidance in the codebase: "when possible please use the
new style, adding a method to the Dialect trait rather than using this
macro."

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@andygrove andygrove requested a review from iffyio January 23, 2026 00:08
@andygrove
Copy link
Member Author

@alamb @iffyio could you let me know if you are open to me creating more PRs like this, using AI to fix up some tech debt? Thanks.

@andygrove andygrove changed the title Refactor: replace dialect_of! checks with Dialect trait methods Refactor: replace some dialect_of! checks with Dialect trait methods Jan 23, 2026
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.

1 participant