DataValue: derived PartialEq with manual Hash on Float64 breaks the Eq/Hash contract for -0.0
Maintainers usually reply within 1 day
@SkyFan2002 is already working on this.
Since Nov 21, 2026.
Assessment
This issue has not been assessed yet.
Description
Search before asking
- I have searched for existing issues (searched "DataValue Hash" and "to_bits") and found none about this.
Version
Linux x86_64 (GitHub Actions runner), main (77137bc2ad), crate databend-common-datavalues.
What's Wrong?
DataValue derives PartialEq and implements Eq, but Hash is handwritten and hashes the float variant by raw bits:
#[derive(..., PartialEq, EnumAsInner)]
pub enum DataValue { ... Float64(f64), ... }
impl Eq for DataValue {}
impl std::hash::Hash for DataValue {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
std::mem::discriminant(self).hash(state);
match self {
DataValue::Float64(v) => v.to_bits().hash(state),
...
}
}
}
0.0 and -0.0 compare equal under the derived PartialEq but produce different bits, so they hash differently. Any HashMap<DataValue, _> / HashSet<DataValue> — group-by keys, distinct sets, hash joins — can hold both as separate entries.
How to Reproduce?
Add to src/query/datavalues/src/data_value.rs and run cargo test -p databend-common-datavalues --lib kern_eq_hash_minus_zero:
#[cfg(test)]
mod kern_eq_hash_test {
use super::*;
use std::collections::HashSet;
#[test]
fn kern_eq_hash_minus_zero() {
let a = DataValue::Float64(0.0);
let b = DataValue::Float64(-0.0);
assert_eq!(a, b);
let mut set = HashSet::new();
set.insert(a);
assert!(set.contains(&b));
}
}
Result on stock main:
thread 'data_value::kern_eq_hash_test::kern_eq_hash_minus_zero' panicked at src/query/datavalues/src/data_value.rs:74:9:
Eq/Hash contract broken on -0.0
test result: FAILED. 0 passed; 1 failed
assert_eq! passes; only the lookup fails.
Context: databend-common-datavalues is still in the live build graph — src/query/expression/Cargo.toml and storages/common/table_meta depend on it, so this is not dead legacy code.
Suggested fix
Canonicalise the sign of zero before hashing (keeps numeric equality and makes the hash agree with it):
DataValue::Float64(v) => {
let v = if *v == 0.0 { 0.0 } else { *v };
v.to_bits().hash(state)
}
Are you willing to submit PR?
- Yes I am willing to submit a PR!
- Dominant language
- Rust
- Stars
- 9.5k
- Forks
- 903
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 204
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from databendlabs/databend
-
bug: segment pruning skips rows when only some blocks have statistics of an added columnPossibly taken @zhyass claimed this today. OpenC-bug
databendlabs/databend#21244 · 1 assignee ·
Maintainers usually reply within 1 day
-
bug: ORDER BY ... NULLS LAST LIMIT returns wrong rows when an inverted index answers the filter and the sort column has NULLsPossibly taken @b41sh claimed this today. OpenC-bug
databendlabs/databend#21243 · 1 assignee ·
Maintainers usually reply within 1 day
-
Feature: Reduce role-graph work for explicit secondary rolesPossibly taken @TCeason claimed this 1 day ago. OpenC-feature
databendlabs/databend#21226 · 1 assignee ·
Maintainers usually reply within 1 day
-
Feature: Key role-dependent query results by authorization contextPossibly taken @TCeason claimed this 1 day ago. OpenC-feature
databendlabs/databend#21225 · 1 assignee ·
Maintainers usually reply within 1 day
-
bug: filters folded to false on block statistics drop matching rows: cast-eliminated equality under NOT, float arithmetic over NaN and infinities, variant IS DISTINCT FROMPossibly taken @forsaken628 claimed this 1 day ago. OpenC-bug
databendlabs/databend#21216 · 1 assignee ·
Maintainers usually reply within 1 day
All issues in databendlabs/databend
Similar issues
-
marketing
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
eliasstravik/herdr-projects#1605 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
jlcodes99/cockpit-tools#3332 ·
Maintainers usually reply within 3 days
-
Cognito: the email MFA code (EMAIL_OTP challenge after a password flow) has 8 digits; AWS delivers 6Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
aws/aws-emulator#692 ·
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 82/100
pamburus/hl#1779 · 1 comment ·
Maintainers usually reply within 1 day