Skip to content

Commit

Permalink
refactor: remove unwraps (#196)
Browse files Browse the repository at this point in the history
* remove avro unwraps

* rm unwrap in schema manifest

* rm some expects

* rm types

* fix clippy

* fix string format

* refine some unwrap

* undo schema.rs
  • Loading branch information
odysa authored Feb 19, 2024
1 parent e2ba1a4 commit 69a5f14
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
6 changes: 3 additions & 3 deletions crates/iceberg/src/avro/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ mod tests {
"field-id": 100
}
]
}
}
"#,
)
.unwrap()
Expand Down Expand Up @@ -768,7 +768,7 @@ mod tests {
"field-id": 100
}
]
}
}
"#,
)
.unwrap()
Expand Down Expand Up @@ -915,7 +915,7 @@ mod tests {
"type": "string"
}
]
}
}
"#,
)
.unwrap()
Expand Down
2 changes: 1 addition & 1 deletion crates/iceberg/src/spec/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
18 changes: 9 additions & 9 deletions crates/iceberg/src/spec/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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>,
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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));
}
Expand Down
5 changes: 4 additions & 1 deletion crates/iceberg/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
];
Expand Down

0 comments on commit 69a5f14

Please sign in to comment.