Streamlined derivation of new Dialect objects#2174
Merged
iffyio merged 3 commits intoapache:mainfrom Feb 3, 2026
Merged
Conversation
0e2f3c7 to
ee3378e
Compare
ee3378e to
500c6fa
Compare
iffyio
approved these changes
Feb 3, 2026
Contributor
iffyio
left a comment
There was a problem hiding this comment.
LGTM! Thanks @alexander-beedie!
Contributor
Author
Great, thanks :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
derive_dialect!(new, base, preserve_type_id = …, overrides = { … })Preamble
There have been a number of requests #1430 to make
Dialectderivation easier but there have remained some practical issues around implementation.This PR represents an attempt at a streamlined option that covers the majority of what people want to do with no impact on existing code, while also remaining largely future-proofed. It is complementary to, and compatible with, longer-term efforts to move away from internal calls to
dialect_of!(such as #2171).Implementation
Introduces a
derive_dialect!proc macro insqlparser_derive, gated behind the new"derive-dialect"feature. If you don't enable the feature, nothing changes - the sole impact on the rest of the codebase would be that each definedDialectis marked with#[derive(Debug, Default)]instead of just#[derive(Debug)], which should be zero-cost for unit/empty structs.In use, the macro discovers all the boolean traits of the base
Dialectat compile time (plus theidentifier_quote_stylechar definition) and allows them to be selectively overridden; new boolean traits added in future releases would be automatically discovered/included, with non-overridden traits deferring to the base.The code in
sqlparser_derivewas split into "visit.rs" (existing visitor macros) and "dialect.rs" (the new dialect derivation macro/helpers) for clarity.In use
As well as the desired boolean overrides, you can set
preserve_type_id=trueto have the derived dialect be recognised as equivalent to the base, allowing the derived dialect to pass equivalence-checks for the remaining internaldialect_of!calls. This makes it easy to support use-cases like that of @samuelcolvin in #1430, which was "I want to use 'from first' syntax with otherwise postgres syntax" (example below).If/when internal use of
dialect_of!is phased out, this macro would remain a nice streamlined way of deriving newDialectobjects (so if "preserve_type_id" loses meaning, the utility of the macro remains, and we could either phase out that param or leave as-is).Example:
The derived dialect has the requested trait values...
...but still identifies internally as a valid
PostgreSqlDialect:References
There are a few others (closed/open), but these cover the key points:
dialect_ofmacro #1448dialect_ofand referring to specific dialects in parser #1430dialect_of!checks withDialecttrait methods #2171