怎么把列数据按","split 之后单独成列

下面这种数据,想按","split 之后单独成列,表操作怎么写?

attachments-2021-08-nrLFNmWE610a4e4a78c8d.png

def splitColumns(x)
{
 a=split(x,",")
 return a
}
each(splitColumns,t[`bid_prices])


each(splitColumns, t["bid_prices"]) => Not allowed to create a matrix with type STRING

请先 登录 后评论

2 个回答

wale

each返回值是个矩阵,矩阵的列类型不能是字符串,可以改用loop函数:

t=table(1..3 as id,["a,b,c","d,e,f","g,h,i"] as val)
select id,loop(split{,","},val) as `col1`col2`col3  from t

显示t的值如下:

attachments-2021-08-3aCxY4RA610a4f2778b7c.png


若是这些列的增加到t,可以如下所示:

t[`col1`col2`col3]=loop(split{,","},t.val) 

attachments-2021-08-kdntK8x3610a4fc7abed3.png




请先 登录 后评论
Mkelar

@wale 的方法不错,不过写错了一点。

        t = table(1..3 as id,["a,b,c","d,e,f","g,h,i" ] as val)

        select id,transpose(loop(split{,","},val)) as `col1`col2`col3 from t

需要在 loop 之后 transpose 之后才是对的。

请先 登录 后评论