Is there a way to ungroup a table

I want to select some unique rows and then ungroup it to a table.

The input is shown in the following example

t = table(1 2 3 as id, `IBM`MSFT`GOOG as sym,(2 3,4,5 6 7) as value)    
id	sym	value
1	IBM	2,3
2	MSFT	4
3	GOOG	5,6,7

The required output is as follows:

id	sym	value
1	IBM	2
1	IBM	3
2	MSFT	4
3	GOOG	5
3	GOOG	6
3	GOOG	7


请先 登录 后评论

1 个回答

wale

The coming version would include the function ungroup. Now you can write a UDF to solve this problem.

def myungroup(t, listColName){
        expandIndex = loop(take, til(t.rows()), t[listColName].rowSize()).flatten()
        g = def(col, expandIndex){
                colType = col.type()
                if(colType == ANY || colType >= 64)        return col.flatten() else return col[expandIndex]
        }
        return each(g{,expandIndex}, t.flip()).flip()
}
t = table(1 2 3 as id, `IBM`MSFT`GOOG as sym,(2 3,4,5 6 7) as value)
myungroup(t, "value")
请先 登录 后评论
  • 1 关注
  • 0 收藏,687 浏览
  • Boye 提出于 2023-05-04 15:26

相似问题