KX Community

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

Home Forums kdb+ how to read this two symbols Re: how to read this two symbols

  • Laura

    Administrator
    April 9, 2022 at 12:00 am
    1. count each field2 implies each item of field2 is a list its length to be counted
    2. Similarly, the lambda {x 1 0} specifies the second and first items of a list, implying field1 is also nested

     

    q)show t:([]field1:(2+5?3)?:`$string[til 10],'"m";field2:(1+5?5)?:5?`3) 
    field1 field2 
    ------------------------------ 
    `9m`1m `dmp`gce`gdp 
    `4m`3m`9m `gce`dmp`dmp`nmo`gdp 
    `8m`9m ,`icg 
    `9m`5m`4m `icg`gce`nmo`nmo`gce 
    `0m`4m`3m `dmp`icg`icg`gce 
    q)select {x 1 0}each field1, #[;1b] each count each field2 from t 
    field1 field2 
    ------------- 
    1m 9m 111b 
    3m 4m 11111b 
    9m 8m ,1b 
    5m 9m 11111b 
    4m 0m 1111b

     

    Above:

    1. the second and first items from each list in field1
    2. a boolean true for each symbol in the field2 lists

    Alternative expression:

     

    q)select reverse each 2#'field1, not null field2 from t 
    field1 field2 
    ------------- 
    1m 9m 111b 
    3m 4m 11111b 
    9m 8m ,1b 
    5m 9m 11111b 
    4m 0m 1111b