Skip to content

Commit 1fd49b3

Browse files
liurenjie1024shaeqahmed
authored andcommitted
fix: Ignore negative statistics value (apache#173)
1 parent ed88d8f commit 1fd49b3

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

crates/iceberg/src/spec/manifest.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,11 @@ mod _serde {
13561356
fn parse_i64_entry(v: Vec<I64Entry>) -> Result<HashMap<i32, u64>, Error> {
13571357
let mut m = HashMap::with_capacity(v.len());
13581358
for entry in v {
1359-
m.insert(entry.key, entry.value.try_into()?);
1359+
// We ignore the entry if it's value is negative since these entries are supposed to be used for
1360+
// counting, which should never be negative.
1361+
if let Ok(v) = entry.value.try_into() {
1362+
m.insert(entry.key, v);
1363+
}
13601364
}
13611365
Ok(m)
13621366
}
@@ -1372,6 +1376,25 @@ mod _serde {
13721376
})
13731377
.collect()
13741378
}
1379+
1380+
#[cfg(test)]
1381+
mod tests {
1382+
use crate::spec::manifest::_serde::{parse_i64_entry, I64Entry};
1383+
use std::collections::HashMap;
1384+
1385+
#[test]
1386+
fn test_parse_negative_manifest_entry() {
1387+
let entries = vec![
1388+
I64Entry { key: 1, value: -1 },
1389+
I64Entry { key: 2, value: 3 },
1390+
];
1391+
1392+
let ret = parse_i64_entry(entries).unwrap();
1393+
1394+
let expected_ret = HashMap::from([(2, 3)]);
1395+
assert_eq!(ret, expected_ret, "Negative i64 entry should be ignored!");
1396+
}
1397+
}
13751398
}
13761399

13771400
#[cfg(test)]

0 commit comments

Comments
 (0)