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

SQL: Add STRING_FORMAT function. #7327

Merged
merged 2 commits into from
Apr 3, 2019
Merged

Conversation

gianm
Copy link
Contributor

@gianm gianm commented Mar 22, 2019

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

  • Add a format Druid expression function (see math-expr.md for docs)
  • Add a 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 of StringUtils.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.

@fjy fjy modified the milestones: 0.14.0, 0.15.0 Mar 22, 2019
@fjy
Copy link
Contributor

fjy commented Mar 22, 2019

@gianm can you fix the conflicts?

Copy link
Member

@clintropolis clintropolis left a comment

Choose a reason for hiding this comment

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

lgtm 👍

@gianm gianm merged commit 8c104a1 into apache:master Apr 3, 2019
gianm added a commit to implydata/druid-public that referenced this pull request Apr 10, 2019
@gianm gianm deleted the string-format-function branch September 23, 2022 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants