blackmwk commented on code in PR #2589:
URL: https://github.com/apache/iceberg-rust/pull/2589#discussion_r3361603818


##########
crates/iceberg/src/spec/snapshot_summary.rs:
##########
@@ -483,27 +483,37 @@ fn update_totals(
     added_property: &str,
     removed_property: &str,
 ) {
-    let previous_total = previous_summary.map_or(0, |previous_summary| {
-        previous_summary
-            .additional_properties
-            .get(total_property)
-            .map_or(0, |value| value.parse::<u64>().unwrap())
-    });
+    let previous_total = match previous_summary {
+        Some(previous_summary) => {
+            match previous_summary.additional_properties.get(total_property) {
+                Some(value) => match value.parse::<u64>() {
+                    Ok(v) => v,
+                    Err(e) => {
+                        tracing::warn!(
+                            "Failed to parse previous summary property 
'{total_property}' value '{value}': {e}. \
+                                Skipping total computation.",
+                        );
+                        return;
+                    }
+                },
+                None => return,

Review Comment:
   We should return 0 here?



##########
crates/iceberg/src/spec/snapshot_summary.rs:
##########
@@ -483,27 +483,37 @@ fn update_totals(
     added_property: &str,
     removed_property: &str,
 ) {
-    let previous_total = previous_summary.map_or(0, |previous_summary| {
-        previous_summary
-            .additional_properties
-            .get(total_property)
-            .map_or(0, |value| value.parse::<u64>().unwrap())
-    });
+    let previous_total = match previous_summary {
+        Some(previous_summary) => {

Review Comment:
   This is actually more  tedious than the original one, if we want to avoid 
unwrap, `Result` has a `inspect` method.



##########
crates/iceberg/src/spec/snapshot_summary.rs:
##########
@@ -483,27 +483,37 @@ fn update_totals(
     added_property: &str,
     removed_property: &str,
 ) {
-    let previous_total = previous_summary.map_or(0, |previous_summary| {
-        previous_summary
-            .additional_properties
-            .get(total_property)
-            .map_or(0, |value| value.parse::<u64>().unwrap())
-    });
+    let previous_total = match previous_summary {
+        Some(previous_summary) => {
+            match previous_summary.additional_properties.get(total_property) {
+                Some(value) => match value.parse::<u64>() {
+                    Ok(v) => v,
+                    Err(e) => {
+                        tracing::warn!(
+                            "Failed to parse previous summary property 
'{total_property}' value '{value}': {e}. \
+                                Skipping total computation.",
+                        );
+                        return;
+                    }
+                },
+                None => return,
+            }
+        }
+        None => 0,
+    };
 
     let mut new_total = previous_total;
-    if let Some(value) = summary
-        .additional_properties
-        .get(added_property)
-        .map(|value| value.parse::<u64>().unwrap())
-    {
-        new_total += value;
+    if let Some(value) = summary.additional_properties.get(added_property) {
+        match value.parse::<u64>() {
+            Ok(v) => new_total += v,
+            Err(_) => return,

Review Comment:
   This is incorret, we should either return error, or prints a warning and 
uses a default value.



##########
crates/iceberg/src/spec/snapshot_summary.rs:
##########
@@ -483,27 +483,37 @@ fn update_totals(
     added_property: &str,
     removed_property: &str,
 ) {
-    let previous_total = previous_summary.map_or(0, |previous_summary| {
-        previous_summary
-            .additional_properties
-            .get(total_property)
-            .map_or(0, |value| value.parse::<u64>().unwrap())
-    });
+    let previous_total = match previous_summary {
+        Some(previous_summary) => {
+            match previous_summary.additional_properties.get(total_property) {
+                Some(value) => match value.parse::<u64>() {
+                    Ok(v) => v,
+                    Err(e) => {
+                        tracing::warn!(
+                            "Failed to parse previous summary property 
'{total_property}' value '{value}': {e}. \
+                                Skipping total computation.",
+                        );
+                        return;
+                    }
+                },
+                None => return,
+            }
+        }
+        None => 0,
+    };
 
     let mut new_total = previous_total;
-    if let Some(value) = summary
-        .additional_properties
-        .get(added_property)
-        .map(|value| value.parse::<u64>().unwrap())
-    {
-        new_total += value;
+    if let Some(value) = summary.additional_properties.get(added_property) {
+        match value.parse::<u64>() {
+            Ok(v) => new_total += v,
+            Err(_) => return,
+        }
     }
-    if let Some(value) = summary
-        .additional_properties
-        .get(removed_property)
-        .map(|value| value.parse::<u64>().unwrap())
-    {
-        new_total -= value;
+    if let Some(value) = summary.additional_properties.get(removed_property) {

Review Comment:
   Ditto.



##########
crates/iceberg/src/spec/snapshot_summary.rs:
##########
@@ -483,27 +484,40 @@ fn update_totals(
     added_property: &str,
     removed_property: &str,
 ) {
-    let previous_total = previous_summary.map_or(0, |previous_summary| {
-        previous_summary
-            .additional_properties
-            .get(total_property)
-            .map_or(0, |value| value.parse::<u64>().unwrap())
-    });
+    let previous_total = match previous_summary {
+        Some(previous_summary) => {
+            match previous_summary.additional_properties.get(total_property) {
+                Some(value) => match value.parse::<u64>() {
+                    Ok(v) => v,
+                    Err(e) => {
+                        tracing::warn!(
+                            "Failed to parse previous summary property '{}' 
value '{}': {}. \
+                                Skipping total computation.",
+                            property_name,
+                            property_value,
+                            parse_error,
+                        );

Review Comment:
   What's your point?



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