This is an automated email from the ASF dual-hosted git repository.
fokko pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-rust.git
The following commit(s) were added to refs/heads/main by this push:
new 69a5f14 refactor: remove unwraps (#196)
69a5f14 is described below
commit 69a5f142a3edf9d1f8df981f868b8eae84625726
Author: Chengxu Bian <[email protected]>
AuthorDate: Mon Feb 19 04:28:52 2024 -0500
refactor: remove unwraps (#196)
* remove avro unwraps
* rm unwrap in schema manifest
* rm some expects
* rm types
* fix clippy
* fix string format
* refine some unwrap
* undo schema.rs
---
crates/iceberg/src/avro/schema.rs | 6 +++---
crates/iceberg/src/spec/manifest.rs | 2 +-
crates/iceberg/src/spec/schema.rs | 18 +++++++++---------
crates/iceberg/src/transaction.rs | 5 ++++-
4 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/crates/iceberg/src/avro/schema.rs
b/crates/iceberg/src/avro/schema.rs
index f8420d4..636f128 100644
--- a/crates/iceberg/src/avro/schema.rs
+++ b/crates/iceberg/src/avro/schema.rs
@@ -705,7 +705,7 @@ mod tests {
"field-id": 100
}
]
-}
+}
"#,
)
.unwrap()
@@ -768,7 +768,7 @@ mod tests {
"field-id": 100
}
]
-}
+}
"#,
)
.unwrap()
@@ -915,7 +915,7 @@ mod tests {
"type": "string"
}
]
-}
+}
"#,
)
.unwrap()
diff --git a/crates/iceberg/src/spec/manifest.rs
b/crates/iceberg/src/spec/manifest.rs
index 818f9c6..e3c989f 100644
--- a/crates/iceberg/src/spec/manifest.rs
+++ b/crates/iceberg/src/spec/manifest.rs
@@ -695,7 +695,7 @@ mod _const_schema {
])),
)),
];
- let schema = Schema::builder().with_fields(fields).build().unwrap();
+ let schema = Schema::builder().with_fields(fields).build()?;
schema_to_avro_schema("manifest_entry", &schema)
}
}
diff --git a/crates/iceberg/src/spec/schema.rs
b/crates/iceberg/src/spec/schema.rs
index 6991d52..34e383f 100644
--- a/crates/iceberg/src/spec/schema.rs
+++ b/crates/iceberg/src/spec/schema.rs
@@ -136,7 +136,7 @@ impl SchemaBuilder {
id_to_field: &HashMap<i32, NestedFieldRef>,
identifier_field_ids: impl Iterator<Item = i32>,
) -> Result<()> {
- let id_to_parent = index_parents(r#struct);
+ let id_to_parent = index_parents(r#struct)?;
for identifier_field_id in identifier_field_ids {
let field = id_to_field.get(&identifier_field_id).ok_or_else(|| {
Error::new(
@@ -406,7 +406,7 @@ pub fn index_by_id(r#struct: &StructType) ->
Result<HashMap<i32, NestedFieldRef>
}
/// Creates a field id to parent field id map.
-pub fn index_parents(r#struct: &StructType) -> HashMap<i32, i32> {
+pub fn index_parents(r#struct: &StructType) -> Result<HashMap<i32, i32>> {
struct IndexByParent {
parents: Vec<i32>,
result: HashMap<i32, i32>,
@@ -487,8 +487,8 @@ pub fn index_parents(r#struct: &StructType) -> HashMap<i32,
i32> {
parents: vec![],
result: HashMap::new(),
};
- visit_struct(r#struct, &mut index).unwrap();
- index.result
+ visit_struct(r#struct, &mut index)?;
+ Ok(index.result)
}
#[derive(Default)]
@@ -971,13 +971,13 @@ mod tests {
#[test]
fn test_schema_display() {
- let expected_str = r#"
+ let expected_str = "
table {
- 1: foo: optional string
- 2: bar: required int
- 3: baz: optional boolean
+ 1: foo: optional string\x20
+ 2: bar: required int\x20
+ 3: baz: optional boolean\x20
}
-"#;
+";
assert_eq!(expected_str, format!("\n{}", table_schema_simple().0));
}
diff --git a/crates/iceberg/src/transaction.rs
b/crates/iceberg/src/transaction.rs
index 5de0ea6..b265813 100644
--- a/crates/iceberg/src/transaction.rs
+++ b/crates/iceberg/src/transaction.rs
@@ -160,7 +160,10 @@ impl<'a> ReplaceSortOrderAction<'a> {
.table
.metadata()
.default_sort_order()
- .expect("default sort order impossible to be None")
+ .ok_or(Error::new(
+ ErrorKind::Unexpected,
+ "default sort order impossible to be none",
+ ))?
.order_id,
},
];