gianm opened a new pull request #7326: SQL: Add PARSE_LONG function.
URL: https://github.com/apache/incubator-druid/pull/7326
 
 
   ### 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.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to