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

Allow format specification in cast #4169

Merged
merged 3 commits into from
May 9, 2023
Merged

Conversation

parthchandra
Copy link
Contributor

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 to CastOption. 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 a const. Instead it implements the Default trait in keeping with the implementation of FormatOptions

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.

@parthchandra parthchandra added the api-change Changes to the arrow API label May 5, 2023
@github-actions github-actions bot added the arrow Changes to the arrow crate label May 5, 2023
Copy link
Contributor

@tustvold tustvold left a 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

@@ -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),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why None here?

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

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.

@tustvold tustvold merged commit 6295822 into apache:master May 9, 2023
@tustvold
Copy link
Contributor

tustvold commented May 9, 2023

Thank you

@parthchandra
Copy link
Contributor Author

Thank you @tustvold for the review and merging!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
api-change Changes to the arrow API arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow cast to take in a format specification
2 participants