-
Notifications
You must be signed in to change notification settings - Fork 853
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
[arrow-cast] Support cast from Numeric (Int
, UInt
, etc) to Utf8View
#6719
Changes from 2 commits
205e40d
2a937fe
2f8f9c3
74de9bc
cdc16c9
d65e228
2ea0b51
b907827
92732ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,22 @@ pub(crate) fn value_to_string<O: OffsetSizeTrait>( | |
Ok(Arc::new(builder.finish())) | ||
} | ||
|
||
pub(crate) fn value_to_string_view( | ||
array: &dyn Array, | ||
options: &CastOptions, | ||
) -> Result<ArrayRef, ArrowError> { | ||
let mut builder = StringViewBuilder::with_capacity(array.len()); | ||
let formatter = ArrayFormatter::try_new(array, &options.format_options)?; | ||
let nulls = array.nulls(); | ||
for i in 0..array.len() { | ||
match nulls.map(|x| x.is_null(i)).unwrap_or_default() { | ||
false => builder.append_value(formatter.value(i).try_to_string()?), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be more optimal to use the std::fmt::write support as for StringArray above. As written this will allocate for every value which will be very expensive There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tustvold Thanks so much for reviewing.
I get it now. Will try to implement it. TYSM ❤️ |
||
true => builder.append_null(), | ||
} | ||
} | ||
Ok(Arc::new(builder.finish())) | ||
} | ||
|
||
/// Parse UTF-8 | ||
pub(crate) fn parse_string<P: Parser, O: OffsetSizeTrait>( | ||
array: &dyn Array, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this also fixes the Timestamp -> Utf8View issue. It would be good to have tests for temporal -> Utf8View added to cover this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After reviewing the code, I realized that the Timestamp -> Utf8View cast is not supported yet.
The main issue comes from the current implementation of
formatter.format.write
(source) which currently only applies toDisplayIndex
derives (source), but the Temporal datatype is implemented based onDisplayIndexState
(source).I think this issue deserves a separate PR to handle the temporal -> string view casting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll file another PR today to cover the temporal -> Utf8View case unless someone beats me to it.