Reputation: 644
We are trying to build functional queries using qPython. Strating with simple examples to build where conditions at the run time. we defined a q function on out KDB server like
fn:{[c]
t: (select from tbl);
:?[t;c;0b;()];
}
in Python we open a connection and send the condition
c = [['=', numpy.string_('TradeId'), 123456]]
result = conn.sendSync('fn', c)
when I do this, in q console I see that = operator as "=". the question is how to pass operators
Upvotes: 0
Views: 525
Reputation: 644
@terrylynch answer works for specifically qPython
from python sending works
c = [[ qtype.QLambda( '{x in y}'), numpy.string_('TradeId'), [123, 456,789]]]
Upvotes: 1
Reputation: 13657
You could value
the string/char on the kdb side to convert it from a string/char to the underlying kdb operator. This works in your example but you might need some extra work/testing to generalise it to all possible operators that you might send:
q)tbl:([]TradeId:0 123456 123456 123456;col2:1 2 3 4)
q)fn:{[c] c:.[c;(::;0);value];t:(select from tbl); :?[t;c;0b;()];}
q)0(`fn;enlist("=";`TradeId;123456))
TradeId col2
------------
123456 2
123456 3
123456 4
q)0(`fn;(("=";`TradeId;123456);("in";`col2;2 4)))
TradeId col2
------------
123456 2
123456 4
Note - Im using 0()
to send requests within kdb itself but this should be the equivalent of sending from qPython. The bit you need to change is the c:.[c;(::;0);value];
in your kdb function
Upvotes: 0