parser: parse IS [NOT] DISTINCT FROM (null-safe comparison)#47
Merged
Conversation
`x IS [NOT] DISTINCT FROM y` is a null-safe comparison and valid SQL, but the IS handler only recognized IS [NOT] NULL / TRUE / FALSE / UNKNOWN and silently dropped the DISTINCT FROM tail, leaving the predicate as its bare left operand - a silent wrong result (the WHERE effectively vanished). Parse it into a BinaryExpr whose operator text is "IS DISTINCT FROM" / "IS NOT DISTINCT FROM" (the same text-carried-operator convention the binder already maps for other comparisons). Two new ast::BinaryOp enum values, IsDistinctFrom / IsNotDistinctFrom, are appended (preserving existing values) for the analyzer/binder legs that follow. A malformed `IS DISTINCT` with no FROM now errors instead of dropping the predicate. This is the parser leg of full IS [NOT] DISTINCT FROM support; the analyzer (type Boolean, never NULL) and binder (map + lower) legs follow in their repos. Tests (test_parser_expr_hardening): IS DISTINCT FROM and IS NOT DISTINCT FROM build the binary comparison over both operands; IS DISTINCT without FROM is rejected; IS NULL / IS TRUE regressions intact. Full suite 37/37 green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FyKDAbMWGwiZq4iJx3imsg
This was referenced Jul 27, 2026
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.
What
x IS [NOT] DISTINCT FROM yis valid, null-safe-comparison SQL, but theIShandler only recognizedIS [NOT] NULL / TRUE / FALSE / UNKNOWNand silently dropped theDISTINCT FROMtail — leaving the predicate as its bare left operandx, so theWHEREeffectively vanished (a silent wrong result).The parser leg of full
IS [NOT] DISTINCT FROMsupport (the user asked for end-to-end support; analyzer and binder legs follow in their repos).How
BinaryExprwhose operator text is"IS DISTINCT FROM"/"IS NOT DISTINCT FROM"— the same text-carried-operator convention the binder'smap_binary_opalready uses for every other comparison.ast::BinaryOpenum values,IsDistinctFrom/IsNotDistinctFrom(existing values preserved), for the downstream legs.IS DISTINCTwith noFROMnow errors instead of dropping the predicate.Before / after
WHERE x IS DISTINCT FROM y— before:WhereClause → ColumnRef('x')(3 trailing tokens,DISTINCT FROM ygone); after:WhereClause → BinaryExpr('IS DISTINCT FROM') → [x, y].Tests
test_parser_expr_hardening:IS DISTINCT FROM/IS NOT DISTINCT FROMbuild the binary comparison over both operands;IS DISTINCTwithoutFROMis rejected;IS NULL/IS TRUEregressions intact. Full suite 37/37 green.Downstream
The analyzer will type
IS [NOT] DISTINCT FROMasBoolean, never-NULL; the binder'smap_binary_opwill map the operator text to the new enum values and lower it. Those PRs bump their parser pin to this commit.Part of the parser-layer robustness pass (CASE fixes are in #46;
IN-without-parens and the set-operation drops follow).