Presto 相当于 StringTokenizerDelim (Vertica) / Explode(Python)

Presto equivalent to StringTokenizerDelim (Vertica) / Explode(Python)

我正在将查询从 Vertica 迁移到 Presto(0.246)。该查询包含一个 Vertica 函数 StringTokenizerDelim,它基本上将(市场列)分解并排列成行。

这是table的模型:

+----+---------+-------------+
| id | product |   market    |
+----+---------+-------------+
|  1 | Cabinet | AU,GB,FR    |
|  2 | Chair   | US,GB       |
|  3 | Desk    | BE,GB,FR,US |
+----+---------+-------------+

输出应该是:

+----+---------+--------+
| id | product | market |
+----+---------+--------+
|  1 | Cabinet | AU     |
|  1 | Cabinet | GB     |
|  1 | Cabinet | FR     |
|  2 | Chair   | US     |
|  2 | Chair   | GB     |
|  3 | Desk    | BE     |
|  3 | Desk    | GB     |
|  3 | Desk    | FR     |
|  3 | Desk    | US     |
+----+---------+--------+

Presto 中那个函数的等价物是什么(如果有的话?在文档中找不到)?

干杯,

split with UNNEST 应该可以解决问题:

-- sample data
WITH dataset (id, product,   market ) AS (
    values (1, 'Cabinet', 'AU,GB,FR'),
    (2, 'Chair', 'US,GB'),
    (3, 'Desk', 'BE,GB,FR,US')
) 

--query
SELECT id, product, m as market
FROM dataset
CROSS JOIN UNNEST (split(market, ',')) as t(m)

输出:

id product market
1 Cabinet AU
1 Cabinet GB
1 Cabinet FR
2 Chair US
2 Chair GB
3 Desk BE
3 Desk GB
3 Desk FR
3 Desk US