kdb+qpython

qPython QProjection Issues instead of queried data


I tried writing a Q Code which will allow me to pass parameters however I am getting a results as Qprojection. I tried using

qpython.sync() is returning a QProjection instead of the queried data

but solution isn't working(new to Q/kdb world) Any ideas on what exactly I should change?

q.sync(
'''{[x;y;z]select from quotestackevent where date within(x;y),sym=z}''', 
[np.datetime64('2018-04-14','D'), #start date
np.datetime64('2018-04-14','D'), #end date
np.string_('GBPUSD')])

Solution

  • In Q/KDB the functional format is {......}[x;y;z], with x y z being the arguments. If you have left a blank argument then the function becomes a projection.

    qpython allows you to pass python arguments to a q function, with the format being q.sync('{......}',x,y,z).

    In your example the square brackets is causing the inputs to be passed as a single array to the function, resulting in a projection. This can be fixed by removing the square bracket.

    q.sync('{[x;y;z]select from quotestackevent where date within(x;y),sym=z}', np.datetime64('2018-04-14','D'), np.datetime64('2018-04-14','D'), np.string_('GBPUSD'))

    Hope this helps!