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
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
parse_long
Druid expression function (see math-expr.md for docs)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 asCAST(x AS BIGINT)
. Both treatx
as decimal and returnnull
if the string is not parseable. ButPARSE_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 ofCAST
.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.