根据逗号分隔的字符串列将一行拆分为多行

Split one row into multiple rows based on comma-separated string column

我有一个像下面这样的 table 列 A(int)B(string):

A   B
1   a,b,c
2   d,e
3   f,g,h

我想创建如下输出:

A    B
1    a
1    b
1    c
2    d
2    e
3    f
3    g
3    h

如果有帮助,我正在 Amazon Athena(基于 presto)中执行此操作。我知道 presto 提供了一个将字符串拆分为数组的函数。从转瞬 docs:

split(string, delimiter) → array
Splits string on delimiter and returns an array.

虽然不确定如何从这里继续。

split 返回的数组使用 unnest

SELECT a,split_b 
FROM tbl
CROSS JOIN UNNEST(SPLIT(b,',')) AS t (split_b)