Skip to content
New issue

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

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

Already on GitHub? # to your account

Remove unwrap() in ManifestListWriter.close() #177

Closed
zeodtr opened this issue Jan 30, 2024 · 10 comments · Fixed by #183
Closed

Remove unwrap() in ManifestListWriter.close() #177

zeodtr opened this issue Jan 30, 2024 · 10 comments · Fixed by #183
Labels
good first issue Good for newcomers

Comments

@zeodtr
Copy link

zeodtr commented Jan 30, 2024

unwrap() should not be used in normal code, but ManifestListWriter.close() uses it.
It should be removed and the error should be properly handled like ManifestWriter.write().

@zeodtr zeodtr changed the title Remove unwrap in ManifestListWriter.close() Remove unwrap() in ManifestListWriter.close() Jan 30, 2024
@liurenjie1024
Copy link
Collaborator

Thanks for reporting!

@liurenjie1024 liurenjie1024 added the good first issue Good for newcomers label Jan 30, 2024
@Fokko Fokko closed this as completed in #183 Feb 2, 2024
@zeodtr
Copy link
Author

zeodtr commented Feb 2, 2024

@Fokko @liurenjie1024 I think this issue has not been resolved, since I'm kind of disagree with the pull request.
What I'm concerned about are as follows:

  • expect() also should not be used since it ends the program with panic just like unwrap(). In a production program that's unacceptable, especially for a server program.
  • It might not be enough to just replace unwrap() with ? in ManifestListWriter's write-related codes. In ManifestWriter, it also adds an appropriate error message. Please see:
    writer.write_all(&content).await.map_err(|err| {

Could you please reopen this issue?

@liurenjie1024
Copy link
Collaborator

@zeodtr Sorry for the mistake, yes you are right, expect still may cause panic. Let's reopen it. cc @odysa We may need to modify the From to TryFrom.

@liurenjie1024 liurenjie1024 reopened this Feb 3, 2024
@odysa
Copy link
Contributor

odysa commented Feb 3, 2024

We may need to modify the From to TryFrom.

serde does not support the attribute try_into. serde-rs/serde#1524 The into attribute requires From. Converting to TryFrom requires us to manually implement a serializer.

#[serde(try_from = "TableMetadataEnum", into = "TableMetadataEnum")]

@liurenjie1024
Copy link
Collaborator

I remember why we use expect for TableMetadata serialization, see this comment. But I still agree that it would be best not to panic in a serious lib which may crash programs.

serde does not support the attribute try_into. serde-rs/serde#1524 The into attribute requires From. Converting to TryFrom requires us to manually implement a serializer.

Yes, it seems we still need to implement Serialization/Deserialization manually, but it's still a wrapper of the conversion from TableMetadataEnum.

@zeodtr
Copy link
Author

zeodtr commented Feb 3, 2024

In the following code, from:

impl From<TableMetadata> for TableMetadataV1 {

    impl From<TableMetadata> for TableMetadataV1 {
        fn from(v: TableMetadata) -> Self {
            TableMetadataV1 {
                format_version: VersionNumber::<1>,
                table_uuid: Some(v.table_uuid),
                location: v.location,
                last_updated_ms: v.last_updated_ms,
                last_column_id: v.last_column_id,
                schema: v
                    .schemas
                    .get(&v.current_schema_id)
                    .expect("current_schema_id not found in schemas")
                    .as_ref()
                    .clone()
                    .into(),

The code expect()s current_schema_id should not be None. But it is valid to be None in TableMetadataV1, although such usage is deprecated. (See Iceberg spec https://iceberg.apache.org/spec/#table-metadata-fields) I think that using expect() is unacceptable in such a case. Actually, in this case, I think that the code should instead use the schema field of TableMetadataV1 when the current_schema_id field is None.

@odysa
Copy link
Contributor

odysa commented Feb 3, 2024

The code expect()s current_schema_id should not be None

current_schema_id is impossible to be None in TableMetadata

But it is valid to be None in TableMetadataV1

It's handled here.

.unwrap_or_else(|| schemas.keys().copied().max().unwrap_or_default()),

code should instead use the schema field of TableMetadataV1 when the current_schema_id field is None

When we convert TableMetadata to TableMetadataV1, we have to look up schemas since there is no schema field in TableMetadata

expect() is unacceptable in such a case

I agree. It panics only when schemas does not contain current_schema_id, which means TableMetadataV1 may be invalid.

@zeodtr
Copy link
Author

zeodtr commented Feb 3, 2024

@odysa Apologies, I have totally misinterpreted the code. I regret any inconvenience caused by my misunderstanding. Please ignore my previous comment.

@tabmatfournier
Copy link

Is this issue still valid given #185 ? This seems addressed. Apologies for the noise, surfing good first issues for something to get started on.

@liurenjie1024
Copy link
Collaborator

Is this issue still valid given #185 ? This seems addressed. Apologies for the noise, surfing good first issues for something to get started on.

@tabmatfournier Yeah, I think it's closed, thanks for reporting this.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants