Repository navigation
Conversation
This branch has not been deployed
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
ClickHouseDecimalmantissa and scale before calculating the hash code.Problem
ClickHouseDecimal.Equalscompares numeric values after aligning their scales, butGetHashCodepreviously included the raw scale. As a result, values such as1.5and
1.5000were equal but produced different hash codes.This caused incorrect behavior in
HashSet<ClickHouseDecimal>,Dictionary<ClickHouseDecimal, TValue>, and LINQ operations such asDistinctand
GroupBy.Fix
GetHashCodenow hashes the canonical representation produced by removing trailingfractional zeros while preserving the original
MantissaandScalestored by theinstance.
Tests
HashSet<ClickHouseDecimal>.Contains.GetHashCode()does not change the stored representation.ClickHouse.Driver.Teststest suite.Fixes #639
Note
Low Risk
Localized change to hash computation with tests; behavior change only for previously inconsistent equal values in hash-based collections.
Overview
Fixes
ClickHouseDecimalviolating theEquals/GetHashCodecontract when the same numeric value is stored with different mantissa/scale pairs (e.g.1.5vs15000at scale 4), which brokeHashSet,Dictionary, and LINQ deduplication.GetHashCodenow hashes a normalized mantissa and scale (trailing fractional zeros stripped, same idea as equality), using local copies so the instance’s storedMantissaandScaleare unchanged.Adds regression tests for equal values across scales (matching hash codes and
HashSet.Contains) and a changelog note for #639.Reviewed by Cursor Bugbot for commit 7acf498. Bugbot is set up for automated code reviews on this repo. Configure here.