Spark `xxhash64` hashes the raw bits of a NaN instead of the canonical NaN
维护者通常 1 天内回复
评估
调研方向
从 datafusion/spark/src/function/hash/utils.rs 中的 hash_array_primitive_float! 宏开始,将其现有的 -0.0 处理与 issue 中的 NaN 复现进行比较。添加一个使用具有不同符号位和 payload 的 NaNs 的回归用例;完成的标准是每个 NaN 都像 canonical NaN 一样进行哈希,同时 -0.0 保持与 Spark 兼容的行为。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
datafusion-spark's xxhash64 hashes a Float32 or Float64 NaN by its raw bits. Spark hashes floats through Float.floatToIntBits and Double.doubleToLongBits, which return the canonical NaN (0x7fc00000, 0x7ff8000000000000) for every NaN, so in Spark all NaNs hash alike. A NaN with the sign bit set, or with another payload, therefore gets a different hash from datafusion-spark than from Spark.
Such NaNs are common: negating a NaN sets its sign bit, and on x86-64 every NaN that arithmetic produces at run time, such as 0.0 / 0.0, has the sign bit set.
The float path is hash_array_primitive_float! in datafusion/spark/src/function/hash/utils.rs. It hashes 0 for -0.0, as Spark does, and otherwise the bytes of the value as they are.
To Reproduce
let values: ArrayRef = Arc::new(Float64Array::from(vec![
f64::NAN, // 0x7ff8000000000000, the canonical NaN
f64::from_bits(0xfff8_0000_0000_0000), // the same with the sign bit set, which -f64::NAN gives
f64::from_bits(0x7ff0_0000_0000_0001), // a NaN with another payload
]));
let args = ScalarFunctionArgs {
args: vec![ColumnarValue::Array(Arc::clone(&values))],
arg_fields: vec![Arc::new(Field::new("v", DataType::Float64, true))],
number_rows: values.len(),
return_field: Arc::new(Field::new("r", DataType::Int64, false)),
config_options: Arc::new(ConfigOptions::default()),
};
let hashes = SparkXxhash64::new()
.invoke_with_args(args)?
.into_array(values.len())?;
hashes is [-3127944061524951246, 9200374361256412029, 5729085064965309005]. Float32 behaves the same way: f32::NAN hashes to 2692338816207849720 and the NaN with the sign bit set (0xffc00000) to 4760557555880201639.
Expected behavior
Every NaN hashes like the canonical NaN. In Spark, when d is NaN, xxhash64(d) and xxhash64(-d) both return -3127944061524951246.
Canonicalizing NaN next to the existing -0.0 check in hash_array_primitive_float! would match Spark.
Additional context
Comet found this while fixing the same gap in its own kernel (apache/datafusion-comet#6413), which keeps float arguments off SparkXxhash64 until it is fixed.
- 主要语言
- Rust
- 星标
- 9.4k
- 派生
- 2.5k
- 平均合并
- 4 天 5 小时
- 30 天内合并 PR
- 331
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/datafusion 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
apache/datafusion#26259 ·
维护者通常 1 天内回复
-
`array_concat` with an untyped `NULL` argument fails with "does not support type Int64"可能已有人在做 @RishavTiwari25 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 80/100
apache/datafusion#26243 ·
维护者通常 1 天内回复
-
array_min / array_max fail on a zero-row batch for non-primitive element types可能已有人在做 @linuxpi 于 7 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
apache/datafusion#26072 ·
维护者通常 1 天内回复
-
BaselineMetrics output_bytes converts every column to ArrayData for every batch可能已有人在做 @minhh-nguyen 于 6 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
apache/datafusion#26071 · 1 条评论 ·
维护者通常 1 天内回复
-
Replace manual `RowSelection` bitmap conversion with `force_mask()` after arrow-rs release可能已有人在做 @isabellehuangg 于 8 天前认领。 未关闭enhancement
难度 2/5 1-3 小时 新手友好度 76/100
apache/datafusion#26030 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 apache/datafusion 的全部 Issue
相似的 Issue
-
state:triage-needed
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
docs(skills): issue-first should reference an existing Linear ticket instead of filing a duplicate未关闭documentation
难度 1/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
area: tui good first issue help wanted type: bug
难度 2/5 1-3 小时 新手友好度 72/100
srothgan/claude-code-rust#473 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
storytold/photocraft#5260 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复