KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums kdb+ Double comma when converting qsql statements to functional statements

  • Double comma when converting qsql statements to functional statements

    Posted by mmcalister on January 11, 2022 at 12:00 am

    What does the presence of the double comma, (,,) before the where phrase part of a parsed select statement.

    I know a single comma means it is enlisted

    What are the implications in terms of converting to a functional statement

    mmcalister replied 7 months, 2 weeks ago 2 Members · 1 Reply
  • 1 Reply
  • jason_fealy

    Member
    January 11, 2022 at 12:00 am

    The list of constraints (index 2) is itself a parse tree which means value cannot be applied to the output of parse. For a simple example like this, it’s just a matter of removing a level of nesting but just to illustrate….

    q)show t:([]a:1 2;b:10 20); 
    a b 
    ---- 
    1 10 2 20 
    
    q)show pt:parse"select from t where a>1"; // parse tree at index 2 ? `t ,,(>;`a;1) 0b ()
    q)value pt // value cannot be applied 'type [0] value pt // value cannot be applied ^
    q)@[pt;2;eval] // evalute the parse tree at index 2 which removes a level of nesting ? `t ,(>;`a;1) 0b ()
    q)
    q)value @[pt;2;eval] // value can be applied to output a b ---- 2 20
    q)
    q)?[t;enlist(>;`a;1);0b;()] ~ value @[pt;2;eval] // matches manually typed functional form 1b

     

    Some further reading which includes more complex examples https://code.kx.com/q/wp/parse-trees/

     

Log in to reply.