Fix #2607: SortByColumns order-table overload fails with Float/Decimal type mixing#3061
Open
anderson-joyle wants to merge 2 commits into
Open
Fix #2607: SortByColumns order-table overload fails with Float/Decimal type mixing#3061anderson-joyle wants to merge 2 commits into
anderson-joyle wants to merge 2 commits into
Conversation
…l type mixing Two bugs in the SortByColumns order-table overload when a Float (Number/double) column is used with a Decimal order table: Bug 1 (compile-time): CheckTypesOrderTableOverload used DType.Accepts with exact:true, which rejects Number/Decimal mixing under V1 rules. Fix: skip the Accepts check when both the column type and order-table value type are numeric (IsNumeric). Bug 2 (runtime): TryGetPrimitiveValue returns System.Double for NumberValue and System.Decimal for DecimalValue. List<object>.IndexOf uses object.Equals, which returns false for double vs decimal, so every Float row was placed at the end. Fix: add NormalizeNumericPrimitive() that converts decimal to double, applied when building the order-table lookup list and when extracting column values during the sort. Also bumps .Net7.0 test project TFMs to net8.0 (net7.0 EOL on this machine). Fixes #2607
Contributor
|
✅ No public API change. |
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.
Summary
Fixes #2607 —
SortByColumns([{A:Float(1)}, ...], "A", [3,2,1])produced a compile-time type error in V1 mode and, when it did compile, an incorrect sort order at runtime.Root cause — two independent bugs
Bug 1 (compile-time,
SortByColumns.cs):CheckTypesOrderTableOverloadcalledDType.Accepts(exact: true), which rejectsNumber/Decimalmixing under V1 rules. Float columns with a Decimal order table produced a binding error.Bug 2 (runtime,
LibraryTable.cs):TryGetPrimitiveValuereturnsSystem.DoubleforNumberValueandSystem.DecimalforDecimalValue.List<object>.IndexOfusesobject.Equals, which always returnsfalsefordoublevsdecimal. Every Float row was placed at the end of the sort output.Fix
isNumericCoercionAllowedguard — when both the column type and order-table value type satisfyIsNumeric, theAccepts()check is skipped.NormalizeNumericPrimitive()that convertsdecimal→double, applied both when building the order-table lookup list and when extracting column values during sort.Files changed:
SortByColumns.cs— numeric coercion guard inCheckTypesOrderTableOverloadLibraryTable.cs—NormalizeNumericPrimitive()helper + two call sites inSortByColumnsOrderTable.Net7.0TFMs bumped tonet8.0(net7.0 EOL; may need reverting for CI)Confidence: 9 / 10
Targeted
SortByColumnsOrderTable_ColumnNamesAsIdentifiersEnabledtests (212 cases including 3 new) and fullFileExpressionEvaluationTestssuite (63,240 passed, 0 failed, 318 skipped). Minor known gap: reverse case (Decimal source + Float order table) not explicitly tested, but normalization is symmetric.Test plan
SortByColumnsOrderTable_ColumnNamesAsIdentifiersEnabled*.txtpassSortByColumns/SortByColumnsOrderTabletests🤖 Generated with Claude Code