Is there a function for checking set membership?


Here is an example of how I would use such a function (assuming it is called IN):

filter(foo, id IN (2, 4, 5, 8))


Hey Rares!

Unfortunately, right now you have to use a compound boolean expression:

$ iquery -aq "filter(build(<val:double> [x=1:10,10,0], x), val=4 or val=7 or val=11)"
{x} val
{4} 4
{7} 7

For a large set, we could convert the set to an array and then use index_lookup:

$ iquery -aq "
     build(<val:double> [x=1:10,10,0], x) as A,
     build(<a:double>[i=0:3,4,0], '[(2),(4),(5),(8)]', true), 
     A.val, idx
   idx is not null
{x} val,idx
{2} 2,0
{4} 4,1
{5} 5,2
{8} 8,3

You might wonder if we could write a UDF for this. One problem is, the function API right now does not support a variable number of arguments. But we do support variable-sized user-defined types. So a plugin could add:

Datatype "set" 
Function "set(string) -> set"    (function name same as type name is OK)
Function "in(int64, set) -> bool"

Then you could do:

filter(foo, in(id, set('1,2,3,4'))

But this does take us down the path of potentially creating arrays of sets, which is a bit odd.