laskoviymishka commented on code in PR #2790:
URL: https://github.com/apache/iceberg-rust/pull/2790#discussion_r4693726007


##########
crates/iceberg/src/spec/transform.rs:
##########
@@ -1134,34 +1134,16 @@ impl FromStr for Transform {
             "hour" => Transform::Hour,
             "void" => Transform::Void,
             "unknown" => Transform::Unknown,
-            v if v.starts_with("bucket") => {
-                let length = v
-                    .strip_prefix("bucket")
-                    .expect("transform must starts with `bucket`")
-                    .trim_start_matches('[')
-                    .trim_end_matches(']')
-                    .parse()
-                    .map_err(|err| {
-                        invalid_data!("transform bucket type {v:?} is 
invalid").with_source(err)
-                    })?;
-
-                Transform::Bucket(length)
-            }
-            v if v.starts_with("truncate") => {
-                let width = v
-                    .strip_prefix("truncate")
-                    .expect("transform must starts with `truncate`")
-                    .trim_start_matches('[')
-                    .trim_end_matches(']')
-                    .parse()
-                    .map_err(|err| {
-                        invalid_data!("transform truncate type {v:?} is 
invalid").with_source(err)
-                    })?;
-
-                Transform::Truncate(width)
-            }
             v => {
-                return Err(invalid_data!("transform {v:?} is invalid"));
+                if let Some(length) = parse_bracketed_param(v, "bucket") {
+                    Transform::Bucket(length?)
+                } else if let Some(width) = parse_bracketed_param(v, 
"truncate") {
+                    Transform::Truncate(width?)
+                } else {
+                    // Per the spec, v3 readers are required to read tables 
with
+                    // unknown transforms, ignoring them
+                    Transform::Unknown

Review Comment:
   Should we stop the write path from persisting a fallback `Unknown` before 
this lands? With this branch, metadata using `zorder` or `bucketv2[4]` in a 
spec or sort order loads, and a 
`TableMetadataBuilder::new_from_metadata(..).set_properties(..).build()` commit 
then writes `"unknown"`, since `Serialize` goes through 
[`Display`](https://github.com/apache/iceberg-rust/blob/47398ef0d249a0d480211fd3ed55e78a34297507/crates/iceberg/src/spec/transform.rs#L1093-L1107).
 On `main` that metadata fails to load, and Java's 
[`UnknownTransform`](https://github.com/apache/iceberg/blob/95aac2f4b100db7f8f37563d58d09daf01196d47/api/src/main/java/org/apache/iceberg/transforms/UnknownTransform.java#L28-L99)
 keeps the name.
   
   Carrying the name (`Unknown(String)`, the #2789 change) or rejecting 
serialization of a parsed-fallback `Unknown` would both close it; which do you 
prefer? A test that loads such a spec and pins what gets written back would 
hold either fix.



##########
crates/iceberg/src/spec/transform.rs:
##########
@@ -1340,4 +1322,53 @@ mod tests {
             );
         }
     }
+
+    #[test]
+    fn test_parse_known_transforms() {
+        assert_eq!(
+            "identity".parse::<Transform>().unwrap(),
+            Transform::Identity
+        );
+        assert_eq!(
+            "bucket[16]".parse::<Transform>().unwrap(),
+            Transform::Bucket(16)
+        );
+        assert_eq!(
+            "truncate[4]".parse::<Transform>().unwrap(),
+            Transform::Truncate(4)
+        );
+        assert_eq!("unknown".parse::<Transform>().unwrap(), 
Transform::Unknown);
+    }
+
+    #[test]
+    fn test_parse_unrecognized_transform_as_unknown() {
+        // Per the spec, v3 readers are required to read tables with unknown
+        // transforms, ignoring them. This matches Java's 
Transforms.fromString,

Review Comment:
   Should the name match be case-insensitive, or this comment (and the 
description) say it matches Java for lowercase names only? Java compares every 
name with 
[`equalsIgnoreCase`](https://github.com/apache/iceberg/blob/95aac2f4b100db7f8f37563d58d09daf01196d47/api/src/main/java/org/apache/iceberg/transforms/Transforms.java#L39-L81),
 so `Bucket[4]` or `Identity` parse as known there and become `Unknown` here.



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