You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Shahar Cizer Kobrinsky <sh...@gmail.com> on 2019/03/20 18:43:51 UTC

Conditionally Adding Item to a Map

Hey All,

New to Calcite, trying to express a select statement in SQL where i build a
map.
The thing is i want to conditionally add items to it, so for example have
key 'c' with value from column 'c' only if the value is not null

SELECT a,b, map['c',c, 'd', d] as my_map  FROM...

Is there a way to conditionally have key/values in the map?

Thanks!
Shahar

Re: Conditionally Adding Item to a Map

Posted by Yuzhao Chen <yu...@gmail.com>.
Or you can right a UDF by yourself, if you encouter an null value you can just return null and in outer you can filter out the null values.

Best,
Danny Chan
在 2019年3月21日 +0800 AM2:45,Shahar Cizer Kobrinsky <sh...@gmail.com>,写道:
> Hey All,
>
> New to Calcite, trying to express a select statement in SQL where i build a
> map.
> The thing is i want to conditionally add items to it, so for example have
> key 'c' with value from column 'c' only if the value is not null
>
> SELECT a,b, map['c',c, 'd', d] as my_map FROM...
>
> Is there a way to conditionally have key/values in the map?
>
> Thanks!
> Shahar

Re: Conditionally Adding Item to a Map

Posted by Michael Mior <mm...@apache.org>.
The only way I can think of the top of my head is to use a CASE
statement and construct the map differently based on the value of c.
--
Michael Mior
mmior@apache.org

Le mer. 20 mars 2019 à 14:45, Shahar Cizer Kobrinsky
<sh...@gmail.com> a écrit :
>
> Hey All,
>
> New to Calcite, trying to express a select statement in SQL where i build a
> map.
> The thing is i want to conditionally add items to it, so for example have
> key 'c' with value from column 'c' only if the value is not null
>
> SELECT a,b, map['c',c, 'd', d] as my_map  FROM...
>
> Is there a way to conditionally have key/values in the map?
>
> Thanks!
> Shahar

Re: Conditionally Adding Item to a Map

Posted by YuZhao Chen <yu...@gmail.com>.
 Or you can right a UDF by yourself, if you encouter

Best,
Danny Chan
在 2019年3月21日 +0800 AM2:45,Shahar Cizer Kobrinsky <shahar.kobrinsky@gmail.com
>,写道:

Hey All,

New to Calcite, trying to express a select statement in SQL where i build a
map.
The thing is i want to conditionally add items to it, so for example have
key 'c' with value from column 'c' only if the value is not null

SELECT a,b, map['c',c, 'd', d] as my_map FROM...

Is there a way to conditionally have key/values in the map?

Thanks!
Shahar