trino
trino copied to clipboard
[Pinot connector] Support for the Pinot `map_value` function
Trino version: 389
Description:
Let's assume that we have a Pinot table tab
and in this table, we have the following columns:
-
array_col_keys
- array-type column, representing keys of a map -
array_col_values
- array-type column, representing values of a map
Pinot, for the specified version, does not implement a map type, thus a workaround has been implemented to allow some map-type functionality via the map_value
function. This workaround assumes that we have two array columns in a Pinot table - a keys column and a values column.
If we want to fetch the values for a given key some_key
via Pinot, we can do it in the following way via the map_value
function:
SELECT
map_value(array_col_keys, 'some_key', array_col_values) AS vals
FROM
tab
The following is the same Pinot query as a passthrough query in Trino:
SELECT
*
FROM
pinot.default."
SELECT
map_value(array_col_keys, 'some_key', array_col_values) AS vals
FROM
tab
"
The first query runs currently in Pinot, while the second query throws the following error:
Caught exception while initializing transform function: mapvalue
In trino, there is a map_values
function which returns the values of the map. I think you're looking for element_at
in trino, something like
select element_at(map(array_col_keys, array_col_values), 'some_key') from ...
I see the issue with map_value
- the key column has to be dictionary encoded, the connector needs to get this information from Pinot. Will update w fix.
@elonazoulay Thank you for your help!