Repository navigation
feat(dialect): add comparison coercion and boolean text hooks - #406
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (89.31%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #406 +/- ##
==========================================
- Coverage 92.99% 92.98% -0.02%
==========================================
Files 275 275
Lines 39243 39360 +117
==========================================
+ Hits 36495 36598 +103
- Misses 2748 2762 +14
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
cursor
Bot
force-pushed
the
upstream/dialect-coercion
branch
from
November 21, 2026 13:38
f479bf2 to
2e6fd91
Compare
This was referenced Nov 21, 2026
cursor
Bot
force-pushed
the
upstream/dialect-coercion
branch
3 times, most recently
from
November 21, 2026 19:08
0c24da3 to
9bcfbd1
Compare
KKould
force-pushed
the
upstream/dialect-coercion
branch
2 times, most recently
from
November 21, 2026 20:27
2f62018 to
79b264e
Compare
KKould
approved these changes
Nov 21, 2026
KKould
left a comment
Member
There was a problem hiding this comment.
I’ve simplified some of the implementation; the PR looks good
KKould
approved these changes
Nov 21, 2026
Add two SqlDialect hooks, both defaulting to the current behaviour: - comparison_type(left, right) picks the type both operands of a comparison (=, <>, <, <=, >, >=, IN lists, BETWEEN) are cast to. The binder applies it while binding the comparison; when the dialect returns None for every operand pair, nothing is cast and the built-in coercion applies as before. - boolean_text(value) picks the text of a boolean in CAST(.. AS CHAR) or CAST(.. AS VARCHAR). The binder reads it from the database's dialect when it binds the cast, so the text is fixed in the plan and cast evaluators stay dialect-free. GenericSqlDialect implements neither, so it is still a no-op, and DynDialect forwards both to its current dialect. A unit test in src/dialect/mod.rs checks both hooks against the generic results. Co-authored-by: Alex Skinner <alexskinner@users.noreply.github.com>
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.
Part of #403.
Depends on #404 (please review only the last commit; I'll rebase once #404 lands).
What
Two new
SqlDialecthooks. Both default to current behaviour, soGenericSqlDialectis still a no-op.comparison_type(left, right) -> Option<LogicalType>picks the type both operands of a comparison are cast to. The binder asks for it when it binds=,<>,<,<=,>,>=,INlists andBETWEEN. If the dialect returnsNonefor every operand pair, nothing is cast and the built-in coercion applies exactly as before.boolean_text(value) -> Option<&'static str>picks the text of a boolean inCAST(... AS CHAR)orCAST(... AS VARCHAR). The default keeps'true'/'false'.DynDialectforwards both hooks to its current dialect.docs/features.md.Why
Dialects differ on how mixed-type comparisons coerce. For example, some compare a number with a string numerically, and some render booleans as
'1'/'0'. These hooks let a dialect crate set those rules without branches in core. See #403.Testing
src/dialect/mod.rsruns the same query against the generic dialect and a test-only dialect that compares numbers with strings asDOUBLEand renders booleans as'1'/'0': the generic results are unchanged, the test dialect's follow both hooks.make test(650 passed, 2 ignored),make test-async(595 passed),make test-sltandmake test-slt-async(198 files each),make fmtand all fourmake clippyinvocations pass.make test-wasmpasses too.Notes for review
comparison_typeis applied in the binder, so it needs no new state: the casts it adds are ordinaryTypeCastexpressions, and constant folding and execution see them as usual.boolean_textis also resolved in the binder, from the database's dialect, with no thread-local. When the dialect overrides it, the binder bindsCAST(b AS VARCHAR)asCAST(CASE b WHEN TRUE THEN '1' WHEN FALSE THEN '0' END AS VARCHAR), so NULL stays NULL and the cast evaluators stay dialect-free. I didn't store the text in the cast evaluator itself because evaluators are looked up by their (from, to) type codes, which are serialized. With the generic dialect the cast binds exactly as before.CASTs. Implicit boolean-to-text conversions keep'true'/'false'. If a dialect needs those too, the binder is where to extend it.