cancel
Showing results for 
Search instead for 
Did you mean: 

Parsing a dictionary to form where clause in functional select

Success_aman
New Contributor
Hi, I have a dictionary with column names and corresponding values as key/value pair. How to parse it to create where clause for functional select? For now I have columns which accept "=" as operator. Thanks,
1 REPLY 1

jlaquaq
New Contributor
Hi,

You could use something like the following.

{(=;x;$[-11h=type y;enlist;]y)}'[key d;value d]

This takes the keys and values from the dictionary and passes them into a function as parameters. You also need to remember that symbols that are not column names need to be enlisted. Therefore a conditional is included to check if the value is an atom. One assumption we make here is that you will never give a column name as a value.
In a functional select this would look like...

q)t:([]c1:`x`x`x;c2:`a`a`b;c3:1 2 3)
q
)d:`c1`c2!(`x;`a)
q
)t
c1 c2 c3
--------
x  a  
1
x  a  
2
x  b  
3
q
)d
c1
| x
c2
| a
q
)?[`t;{(=;x;$[-11h=type y;enlist;]y)}'[key d;value d];0b;()]
c1 c2 c3
--------
x  a  1
x  a  2
q)d:`
c1`c2`c3!(`x;`a;1)
q
)?[`t;{(=;x;$[-11h=type y;enlist;]y)}'[key d;value d];0b;()]
c1 c2 c3
--------
x  a  1


Hope this works for you, let me know otherwise.

Regards,
Jordan Logan