This is an automated email from the ASF dual-hosted git repository.
fokko pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-rust.git
The following commit(s) were added to refs/heads/main by this push:
new d9d6cfc fix: Ignore negative statistics value (#173)
d9d6cfc is described below
commit d9d6cfcb0e0dc4a3db0a8c63ec496272303035bc
Author: Renjie Liu <[email protected]>
AuthorDate: Fri Jan 26 21:07:24 2024 +0800
fix: Ignore negative statistics value (#173)
---
crates/iceberg/src/spec/manifest.rs | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/crates/iceberg/src/spec/manifest.rs
b/crates/iceberg/src/spec/manifest.rs
index 76e6e76..d943a55 100644
--- a/crates/iceberg/src/spec/manifest.rs
+++ b/crates/iceberg/src/spec/manifest.rs
@@ -1356,7 +1356,11 @@ mod _serde {
fn parse_i64_entry(v: Vec<I64Entry>) -> Result<HashMap<i32, u64>, Error> {
let mut m = HashMap::with_capacity(v.len());
for entry in v {
- m.insert(entry.key, entry.value.try_into()?);
+ // We ignore the entry if it's value is negative since these
entries are supposed to be used for
+ // counting, which should never be negative.
+ if let Ok(v) = entry.value.try_into() {
+ m.insert(entry.key, v);
+ }
}
Ok(m)
}
@@ -1372,6 +1376,25 @@ mod _serde {
})
.collect()
}
+
+ #[cfg(test)]
+ mod tests {
+ use crate::spec::manifest::_serde::{parse_i64_entry, I64Entry};
+ use std::collections::HashMap;
+
+ #[test]
+ fn test_parse_negative_manifest_entry() {
+ let entries = vec![
+ I64Entry { key: 1, value: -1 },
+ I64Entry { key: 2, value: 3 },
+ ];
+
+ let ret = parse_i64_entry(entries).unwrap();
+
+ let expected_ret = HashMap::from([(2, 3)]);
+ assert_eq!(ret, expected_ret, "Negative i64 entry should be
ignored!");
+ }
+ }
}
#[cfg(test)]