Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove unwraps #196

Merged
merged 8 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/iceberg/src/avro/schema.rs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the misinformation, in fact I mean all changes of unwrap in this file seems unnecessary to me, since they are all generated by internal code and they are expected to be safe.

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()?;
odysa marked this conversation as resolved.
Show resolved Hide resolved
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)
odysa marked this conversation as resolved.
Show resolved Hide resolved
}

#[derive(Default)]
Expand Down Expand Up @@ -971,13 +971,13 @@ mod tests {

#[test]
fn test_schema_display() {
let expected_str = r#"
let expected_str = "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to change this? I believe raw string is easier to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, it's clearer if we make whitespaces explicit. Also, my code formatter keeps removing the trailing whitespace. 🥲

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable, not a big problem to me.

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
Loading