2022.01.11 12:11 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
(see photo)
What are the implications in terms of converting to a functional statement
2022.01.11 08: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....
(btw, your example has a bug: size should not be a symbol in your q-sql statement as it's a column name)
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/
2022.01.11 08: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....
(btw, your example has a bug: size should not be a symbol in your q-sql statement as it's a column name)
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/
EMEA
Tel: +44 (0)28 3025 2242
AMERICAS
Tel: +1 (212) 447 6700
APAC
Tel: +61 (0)2 9236 5700
KX. All Rights Reserved.
KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.