Repository navigation
fix: correct Unpivot's null tests for int and int? members - #188
Open
Peter Shrosbree (pcshrosbree) wants to merge 1 commit into
Open
Peter Shrosbree (pcshrosbree) wants to merge 1 commit into
Peter Shrosbree (pcshrosbree) wants to merge 1 commit into
Conversation
Unpivot builds a null test for each input member and skips the member when the test is true. Two of those tests were wrong. When the value field's type is not a class, such as int, a member that is not Nullable<T> got the test o => true. So an int field or property was always skipped, although an int? field was emitted. For an input member that is not Nullable<T>, the test now returns true only if the member has a reference type and its value is null. It compares the reference with null, so a user-defined == operator on the member's type cannot make a value look null. The same null test handles reference-type input members when the value field has an interface type. For example, if the value field's type is IComparable and the input member is a string, a null string is still skipped. For an int? property, the test was IsTrue(HasValue), where the field branch uses IsFalse(HasValue). A property with a value was skipped, and a null one threw InvalidOperationException from Value. It now uses IsFalse, as the field branch does. UnpivotNullTests runs eight tests, in row mode and with the default settings. Before this change seven of them fail in both; the int? fields case already worked. After it, all pass.
This was referenced Nov 2, 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.
Fixes #185.
Unpivotbuilds a null test for each input member and skips the member when the test is true. Two of those tests were wrong, both in theUnpivotEnumerableconstructor inPivotExtensions.cs:int, a member that is notNullable<T>got the testo => true(line 327 and line 363). So anintfield or property was never emitted, although anint?field was.int?property, the test wasIsTrue(HasValue)(line 313), where the field branch hasIsFalse(HasValue). A property with a value was skipped, and a null one threwInvalidOperationExceptionfromValue.Line 313 now uses
IsFalse. When the value field's type is not a class, lines 327 and 363 now call a helper that chooses the null test by the input member's type. A non-nullable value-type member is never null. This branch also handles reference-type input members when the output value field has an interface type. For example, astringinput member can supply anIComparablevalue field. Reference-type input members in this branch are compared with null by reference (Expression.ReferenceEqual). This skips null values and prevents a user-defined==operator from making a non-null value look null. Applyingo => falseto every member in this branch would instead emit a nullstringas a value. The branch used when the value field's type is a class is unchanged.The new
UnpivotNullTestshas eight tests, each run in two test classes: one uses row mode, and the other uses the default settings. They coverintfields and properties,int?fields with values,int?properties with values and with nulls, and anIComparablevalue field withstringmembers and with members of a type that defines its own==. On this branch's base, with only the test file added, seven tests fail in each class; theint?fields case already worked. With the fix, all 16 runs pass. I ran them onnetcoreapp3.1, rolled forward to .NET 10.0.13 on Linux x64, because only .NET 10 runtimes are installed here.The second test class uses the default settings rather than columnar mode with fallback disabled.
Unpivotpasses a captured delegate toSelectMany, which columnar code generation cannot compile, so a columnar query withUnpivotfalls back to row execution.This PR and #187 both edit
PivotExtensions.cs, in different methods. They merge without conflicts, and the tests of both pass on the merged tree.Note
Prepared with AI assistance (Anthropic Claude, OpenAI Codex). I reviewed it before posting.