Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
String formatting is a useful function in general. This also provides the reverse of #7326 ability to parse hexadecimal strings, since
%x
can be used to convert back in the other direction.Proposed changes
format
Druid expression function (see math-expr.md for docs)STRING_FORMAT
Druid SQL function (see sql.md for docs)Both functions have a required argument (pattern) and a variable number of optional arguments (format parameters). Both return
null
if the pattern is null. Both suppress errors in the manner ofStringUtils.nonStrictFormat
(since they use this under the hood).Rationale
I think the function is self evidently useful, but there are some different ways it could have been implemented. I could have used strict formatting rather than non-strict formatting, but decided to go with non-strict to avoid failing the entire query if the format is bad or if some input data is bad.
I could have added an option to specify the locale, but decided not to, mostly because I don't need it right now. This could be added in a future patch if anyone needs it.
Operational impact
None.
Test plan
Unit tests.
Future work
Add support for formatting in different locales.