-
Notifications
You must be signed in to change notification settings - Fork 876
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
Allow format specification in cast #4169
Conversation
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.
This looks good to me, I just had a question about why the options are only sometimes propogated
arrow-cast/src/cast.rs
Outdated
@@ -947,8 +956,8 @@ pub fn cast_with_options( | |||
x as f64 / 10_f64.powi(*scale as i32) | |||
}) | |||
} | |||
Utf8 => value_to_string::<i32>(array), | |||
LargeUtf8 => value_to_string::<i64>(array), | |||
Utf8 => value_to_string::<i32>(array, None), |
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.
Why None here?
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.
This is a decimal to string and FormatOptions
only has format specifiers for temporal types. I don't see a need to specify format for decimal since the display is precisely determined by the precision and scale.
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 think for consistency and avoiding surprises in the future it would be better to pass it through consistently
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've added the format option for decimal types as well, but decimal_display will drop this option.
I don't know if there is a standard or common way to specify a format string for decimals used by other engines, but I'll take a look at it sometime.
Thank you |
Thank you @tustvold for the review and merging! |
Which issue does this PR close?
Closes #4168
Rationale for this change
See issue #4168
What changes are included in this PR?
Adds a
FormatOption
field toCastOption
. If specified, the format is passed in to the formatter which will then output in the required format.One change was to modify
DEFAULT_CAST_OPTIONS
so that it is no longer aconst
. Instead it implements theDefault
trait in keeping with the implementation ofFormatOptions
Are there any user-facing changes?
The cast API is not changed but the cast options are. This should be documented.
Not sure if this is a breaking change, but adding the api-change label to be on the safe side.