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 PARSE_LONG function. #7326

Merged
merged 2 commits into from
Mar 22, 2019
Merged

SQL: Add PARSE_LONG function. #7326

merged 2 commits into from
Mar 22, 2019

Conversation

gianm
Copy link
Contributor

@gianm gianm commented Mar 22, 2019

Motivation

We have a need to treat hex and octal strings as integers at both ingest time (transformSpec) and query time. Currently, we can do this with decimals, but not with hex/octal.

Proposed changes

  • Add a parse_long Druid expression function (see math-expr.md for docs)
  • Add a PARSE_LONG Druid SQL function (see sql.md for docs)

Both functions have a required argument (string) and an optional argument (radix, defaults to 10 - decimal). Both functions return a long. Both functions return null if the string is not parseable.

Rationale

PARSE_LONG(x) acts the same as CAST(x AS BIGINT). Both treat x as decimal and return null if the string is not parseable. But PARSE_LONG is more flexible, since it can accept different radixes and parse hex, octal, etc. So this design was really chosen for alignment with behavior of CAST.

There doesn't seem to be a great way to do this in standard SQL, at least that I can find (see some hilariousness in https://stackoverflow.com/questions/8316164/convert-hex-in-text-representation-to-decimal-number). So I made up my own syntax and semantics. I chose PARSE_LONG for the name since it would be familiar to Java users.

Operational impact

None.

Test plan

Unit tests.

@fjy fjy added this to the 0.15.0 milestone Mar 22, 2019
@fjy fjy merged commit 4ca5fe0 into apache:master Mar 22, 2019
justinborromeo pushed a commit to justinborromeo/incubator-druid that referenced this pull request Apr 1, 2019
* SQL: Add PARSE_LONG function.

* Fix test.
gianm added a commit to implydata/druid-public that referenced this pull request Apr 10, 2019
* SQL: Add PARSE_LONG function.

* Fix test.
@gianm gianm deleted the parse-long-fn branch September 23, 2022 19:26
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.

None yet

3 participants