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

feat: support convert arrow value and type to AnyValue, Any #141

Merged
merged 2 commits into from
Aug 14, 2023

Conversation

ZENOTME
Copy link
Contributor

@ZENOTME ZENOTME commented Aug 10, 2023

This PR design the sketch to convert arrow value to AnyValue, arrow type to Any.

I'm not sure whether this design and abstraction is clear enogh, I will modify it if there is better way. PTAL. @Xuanwo @liurenjie1024

Copy link
Contributor

@Xuanwo Xuanwo left a comment

Choose a reason for hiding this comment

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

Mostly LGTM, would you like to add some test?

@ZENOTME
Copy link
Contributor Author

ZENOTME commented Aug 10, 2023

Mostly LGTM, would you like to add some test?

Yes. If this sketch looks well, I complete it more later.

Copy link
Contributor

@liurenjie1024 liurenjie1024 left a comment

Choose a reason for hiding this comment

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

Generally LGTM

/// Arrow data type is not supported.
///
/// This error is returned when fail to convert from or convert to arrow data or type.
ArrowUnsupported,
Copy link
Contributor

Choose a reason for hiding this comment

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

How about rename it to DataTypeUnspported to be more clear?

@@ -7,6 +7,7 @@ pub use in_memory::*;
mod on_disk;
pub use on_disk::*;

mod from_arrow;
Copy link
Contributor

Choose a reason for hiding this comment

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

How about put all arrow related conversion in one mod called arrow?

@ZENOTME ZENOTME marked this pull request as ready for review August 14, 2023 05:44
@ZENOTME
Copy link
Contributor Author

ZENOTME commented Aug 14, 2023

Have integrate the arrow and add more test.

@@ -48,6 +52,7 @@ impl From<ErrorKind> for &'static str {
ErrorKind::Unexpected => "Unexpected",
ErrorKind::IcebergDataInvalid => "IcebergDataInvalid",
ErrorKind::IcebergFeatureUnsupported => "IcebergFeatureUnsupported",
ErrorKind::DataTypeUnsupported => "ArrowUnsupported",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ErrorKind::DataTypeUnsupported => "ArrowUnsupported",
ErrorKind::DataTypeUnsupported => "DataTypeUnsupported",


/// This interface is used to convert the struct array. We pass he target type instead of
/// converting it internally is to save the extra cost.
fn to_anyvalue_array_with_type(&self, target_type: Any) -> Result<Vec<Option<AnyValue>>>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we don't need this trait? We can implement TryFrom<PrimitiveArray> and TryFrom<BoolArray> for Vec<Option<AnyValue>>, and have two methods to convert ArrayRef and StructArray for type safety.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can't directly implement TryFrom becase it don't define in our crate, we will get the error like:

only traits defined in the current crate can be implemented for types defined outside of the crate
   define and implement a trait or new type instead 

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I see. I still want to remove to_anyvalue_array_with_type to keep type safety. We can implement standalone method for StructArray and ArrayRef

ZENOTME added 2 commits August 14, 2023 15:26
@liurenjie1024 liurenjie1024 merged commit 8db42eb into main Aug 14, 2023
3 checks passed
@liurenjie1024 liurenjie1024 deleted the from_arrow_value branch August 14, 2023 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants