fivetran-MichaelLee commented on code in PR #3819:
URL: https://github.com/apache/iceberg-rust/pull/3819#discussion_r4803814086


##########
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!(

Review Comment:
   Agreed. Since `referenced_data_file` falls back to these bounds, dropping 
one moves the delete file from the path index to the partition index, where the 
spec-id check can skip it. In 6613c9c23 an undecodable 
`RESERVED_FIELD_ID_DELETE_FILE_PATH` bound still fails the read, as before this 
PR; other bounds are still skipped. Covered by 
`test_read_data_files_fails_on_undecodable_delete_file_path_bound`.



##########
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:
   Done in 6613c9c23: a static `AtomicBool` like `WARNED_REPEATED_DEFINITIONS`. 
The first undecodable bound is logged at `warn` (field id, name, error, and 
that later ones go to `debug`), the rest at `debug`.



##########
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:
   Added in 6613c9c23 as suggested: a 3-byte upper bound for the `int` field 
`v1`, removed from the expected value.



-- 
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]

Reply via email to