user10165841
user10165841

Reputation:

Does ungroup works on a table with multiple columns to ungroup?

So I have the following table :

q)flip`col1`col2`col3!((enlist`na;(`na`emea);`na);`test1`test2`test3;(enlist`uat;enlist`prd;(`uat`prd`dr)))
col1     col2  col3
--------------------------
,`na     test1 ,`uat
`na`emea test2 ,`prd
`na      test3 `uat`prd`dr

can I use ungroup on this table ?

Upvotes: 2

Views: 824

Answers (2)

terrylynch
terrylynch

Reputation: 13657

Like my answer on your other related question (How can I prep this table for ungroup), you can ungroup one column at a time if you use a custom ungrouper:

q){@[x where count each x y;y;:;raze x y]}/[t;`col1`col3]
col1 col2  col3
---------------
na   test1 uat
na   test2 prd
emea test2 prd
na   test3 uat
na   test3 prd
na   test3 dr

Upvotes: 1

MurrMack
MurrMack

Reputation: 579

Short answer is no - the first line of the documentation for ungroup https://code.kx.com/q/ref/ungroup/ States that "Where x is a table, in which some cells are lists, but for any row, all lists are of the same length"

your second row in the table contains lists in col1 and col3 but these are of different lengths.

ungroup will work on the first and last rows of your table as these contain lists and the cells which are lists are of the same length.

q)ungroup 1#t
col1 col2  col3
---------------
na   test1 uat
q)ungroup -1#t
col1 col2  col3
---------------
na   test3 uat
na   test3 prd
na   test3 dr
q)(1#t),-1#t
col1 col2  col3
----------------------
,`na test1 ,`uat
`na  test3 `uat`prd`dr
q)ungroup (1#t),-1#t
col1 col2  col3
---------------
na   test1 uat
na   test3 uat
na   test3 prd
na   test3 dr

Upvotes: 1

Related Questions