Hi there, happy new year Druid community. I am goi...
# general
m
Hi there, happy new year Druid community. I am going strong in my learning path with Druid. I have a question about
COMPLEXTYPE<serializablePairLongString>
I have a table definition in Apache Druid with a column as a complex type
COMPLEX<serializablePairLongString>
created by an ingestion aggregation. So the column data result is displayed like:
Pair{lhs= 1735467541688,rhs=90989.034}
Which is correct as it displays the timestamp and the value as Long/String pairs. When querying such data I would like to have Druid parse the value and return only the rhs value which is, in this case: 90989.034 , so I don't have to extract it on the application side which is inefficient. I managed to get that using a REGEX from druid on query time like:
REGEXP_EXTRACT(earliest("open"), '(?<=rhs=)([\d.]+)') as op,
which is ok but I wonder if there's a better way since I see operators for JSON for example. Is there an official operator to get this done without using the REGEX? I am assuming if such operator exists that it would be more efficient than using a regex pattern match. Please let me know.
j
Try setting your query context
finalizeAggregations: true
to see if that does it. If not, then I don't know of a specific function to extract the rhs value from an lhs/rhs pair ... however you could try something like this:
Copy code
with tmp as (select 'Pair{lhs= 1735467541688,rhs=90989.034}' val)
select val, rtrim(substring(val, strpos(val,'rhs=')+4),'}')
from tmp
It's not pretty ... but it doesn't use Regex so I imagine should process much faster.
l
finalize should definitely help. You shouldn’t need to manipulate the results via regex
m
Hi @John Kowtko and @Laksh Singla thanks for the input I will try that out. We're using Polaris but I assume is also possible to pass it as a context for the query. Will try out and provide feedback here.
Hum, whenever I try to use { "finalize": "true" } on Polaris on query timeI get a 403. I think it's not supported on Polaris?
j
Hi Marcos -- Polaris has a whitelist for query context parameters that it allows. Please log a Polaris Support ticket to further inquire about this. Thanks. John
m
Hi @John Kowtko thanks for the insight, gr8 to know. I will test it with local druid and if it works as expected I will reach out and request to whitelist this one.