Search code examples
kdb

how does q combine dictionary outputs to create table when each is used?


time_snap_temp:((1 2 3 4);(4 5 6 7);(7 8 9 10))
col_names:`AA`AB`AC`AD
f_try: {y!x}[;col_names]
agg:f_try each time_snap_temp
one_dict: f_try time_snap_temp[0]  

one_dict is a dictionary as expected but agg is a table. How does q combine dictionaries to create a table in agg?

Thanks and appreciate your help.


Solution

  • A table is actually a list of dictionaries, when using f_try with each it will output a list of dictionaries which get promoted to a table. When just using f_try with the first entry in time_snap_temp, just one dictionary is outputted so remains a dictionary.

    // see how using 1# and each here will output list of dictionaries of length 1 and also get promoted to a table
    q)f_try each 1#time_snap_temp
    AA AB AC AD
    -----------
    1  2  3  4