moomindani commented on code in PR #2790:
URL: https://github.com/apache/iceberg-rust/pull/2790#discussion_r4697933071
##########
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:
Went with rejecting the write, and kept `Unknown(String)` for #2789 since it
would drop `Copy` from `Transform`. The check is in `TableMetadata::write_to`
rather than in `Serialize for Transform`: `FileScanTask` serializes its
`partition_spec` and `sort_order`, so failing there would break shipping scan
tasks for these tables. Every non-REST catalog writes metadata through
`write_to`; a REST commit sends only `TableUpdate`s, so the server keeps the
original name. `test_write_rejects_unknown_partition_transform` and
`test_write_rejects_unknown_sort_transform` load `zorder` / `bucketv2[4]`,
apply `set_properties`, and pin that the write fails and no file is written.
##########
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:
Made it case-insensitive to match `equalsIgnoreCase`; `Bucket[16]` now
parses as `Bucket(16)`. Covered by
`test_parse_known_transforms_case_insensitively`.
--
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]