mbutrovich commented on code in PR #3819:
URL: https://github.com/apache/iceberg-rust/pull/3819#discussion_r4801553347
##########
crates/iceberg/src/spec/manifest/_serde.rs:
##########
@@ -317,7 +317,20 @@ fn parse_bytes_entry(v: Vec<BytesEntry>, schema: &Schema)
-> Result<HashMap<i32,
.as_primitive_type()
.ok_or_else(|| invalid_data!("field {} is not a primitive
type", field.name))?
.clone();
- m.insert(entry.key, Datum::try_from_bytes(&entry.value,
data_type)?);
+ // A bound that does not decode (e.g. a string bound truncated
inside a multi-byte
+ // UTF-8 character) is skipped: bounds are optional, and a missing
bound only means
+ // the column's values in this file are not used for pruning.
+ match Datum::try_from_bytes(&entry.value, data_type) {
+ Ok(datum) => {
+ m.insert(entry.key, datum);
+ }
+ Err(err) => tracing::warn!(
+ field_id = entry.key,
+ field = %field.name,
+ error = %err,
+ "Skipping a column bound that cannot be decoded"
+ ),
Review Comment:
Could we log this at `warn` once per process and at `debug` after that?
`Manifest::parse_avro` does this for repeated Avro names with a static
`AtomicBool`
([mod.rs#L86-L97](https://github.com/apache/iceberg-rust/blob/9ab19d58da02fb49656707750ba99f034dcc6fb7/crates/iceberg/src/spec/manifest/mod.rs#L86-L97)).
A table written before the DuckDB fix can carry a truncated bound on many data
files, and this logs one line per bound each time a manifest is parsed.
`parse_bytes_entry` doesn't know the manifest's location, so the repeated lines
also don't help anyone find the file.
##########
crates/iceberg/src/spec/manifest/_serde.rs:
##########
@@ -480,6 +493,41 @@ mod tests {
assert_eq!(data_files, actual_data_file);
}
+ /// A bound whose bytes do not decode as the field's type is dropped, so
the rest of the
+ /// manifest still loads. Writers that truncate string bounds by bytes can
leave a lower bound
+ /// that ends inside a multi-byte UTF-8 character.
+ #[test]
+ fn test_read_data_files_skips_undecodable_bounds() {
+ let schema = schema();
+ let mut data_files = data_files();
+ // 14 ASCII bytes and the first 2 of the 3 bytes of '\u{20ac}': not
valid UTF-8.
+ data_files[0]
+ .lower_bounds
+ .insert(2, Datum::binary(b"bound-cut-here\xE2\x82".to_vec()));
Review Comment:
This change also skips bounds that fail for reasons other than UTF-8. For
example, a fixed-width bound of the wrong length used to fail the read at
[`datum.rs#L402`](https://github.com/apache/iceberg-rust/blob/9ab19d58da02fb49656707750ba99f034dcc6fb7/crates/iceberg/src/spec/values/datum.rs#L402)
and is now dropped. Could we cover that case in this test too? A 3-byte bound
for the `int` field `v1` works with the same assertions:
```rust
// 3 bytes for an `int` bound, which needs 4.
data_files[0]
.upper_bounds
.insert(1, Datum::binary(vec![1, 2, 3]));
```
and in the expected value:
```rust
expected[0].upper_bounds.remove(&1);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]