Repository navigation
fix: a projected CompareTo against a null range returns 1, as in memory - #272
Merged
Merged
Conversation
Select(r => r.Seats.CompareTo(none)) with a null none translated to EF Core's CASE WHEN a = b ... END, which is NULL for a null operand, and reading that into an int threw "Nullable object must have a value" where memory answers 1. The interceptor's CompareTo rewriter now also rewrites a CompareTo that is not compared with a number (projected, ordered by) into the same split by nullness, as one conditional following Comparer<T>.Default: (null, null) 0, (null, x) -1, (x, null) 1, otherwise the call. Constants and non-nullable columns fold it away: a null operand is SELECT 1, a non-null one EF Core's own CASE. RangeOrderParityTests.ProjectedCompareTo_ReturnsTheNumberTheDefaultComparerReturns projects and orders by CompareTo over a nullable range and multirange column against a null and a non-null operand, row for row against Comparer<T>.Default; it throws with the rewrite removed (seed projected-compareto-null-reads-sql-null). The #256 seed is refreshed for the changed file. Closes #253 Found-By: CA Defect-Class: SQL Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Closes #253
Stacked on #268 (#256/#261), which rewrote the same rewriter: merge #268 first, and this PR's base then moves to
main.Problem
Select(r => r.Seats.CompareTo(none))withnone == nulltranslated to EF Core'sCASE WHEN r."Seats" = NULL … END, which yields SQLNULL. Reading that into anintthrewInvalidOperationException: Nullable object must have a value, where memory answers 1 (null sorts first). The comparison rewrite only coveredCompareTocompared with a number.Change
CompareTo. InNullOperandCompareToRewriter, aCompareTothat is not compared with a number, such as one projected or ordered by, becomes the same split by nullness as a comparison. It is one conditional followingComparer<T>.Default:(null, null)gives 0,(null, x)gives −1,(x, null)gives 1, and otherwise the call itself.SELECT 1. A non-null one gives EF Core's ownCASE, with noIS NULL, as the new translation test pins. Comparisons with a number still take fix: CompareTo with a null range on either side compares as Comparer<T>.Default, for any number #268's predicate form, so they keep the btree operator.docs/ranges.md#sort-ranges): one sentence on a projectedCompareTo. Claim R47 holds it.projected-compareto-null-reads-sql-null.patch.compareto-null-rewritten-only-against-zero.patchfrom fix: CompareTo with a null range on either side compares as Comparer<T>.Default, for any number #268 is regenerated, because this PR changes the file it patches.CompareTois new in this same 10.0.0.Tests
RangeOrderParityTests.ProjectedCompareTo_ReturnsTheNumberTheDefaultComparerReturns(live). It runs over a nullable range and a nullable multirange column holding NULL and four shapes, against a null and a non-null operand. It projectsCompareTorow for row againstComparer<T>.Default.Compare, and orders by it.src/back at fix: CompareTo with a null range on either side compares as Comparer<T>.Default, for any number #268, the test throwsNullable object must have a value, the issue's symptom.dotnet run tools/oracles.cs seeds comparetoreports all three CompareTo seeds asCAUGHT.QueryTranslationTests.ProjectedCompareTo_…checksSELECT 1for a null operand, and EF Core'sCASEwith no null test for a non-null one.🤖 Generated with Claude Code