如何按包含 Presto 列表的列过滤数据框?
How to filter dataframe by column which contains lists in Presto?
有查询:
SELECT
value,
type
FROM dt
我得到:
value type
12 [increase, upload]
12 [increase, download]
12 [decrease, delete]
我想获取列类型为 'upload' 的值。然而这个:
SELECT
value,
type
FROM dt
WHERE type LIKE 'upload'
不起作用。怎么做?
假设 type
是一个 ARRAY
的 varchars 你可以简单地使用 contains
:
WITH dataset (value, type) AS (
VALUES (12, array [ 'increase', 'upload' ]),
(12, array [ 'increase', 'download' ]),
(12, array [ 'decrease', 'delete' ])
)
SELECT value,
type
FROM dataset
WHERE contains(type, 'upload')
输出:
value
type
12
[increase, upload]
有查询:
SELECT
value,
type
FROM dt
我得到:
value type
12 [increase, upload]
12 [increase, download]
12 [decrease, delete]
我想获取列类型为 'upload' 的值。然而这个:
SELECT
value,
type
FROM dt
WHERE type LIKE 'upload'
不起作用。怎么做?
假设 type
是一个 ARRAY
的 varchars 你可以简单地使用 contains
:
WITH dataset (value, type) AS (
VALUES (12, array [ 'increase', 'upload' ]),
(12, array [ 'increase', 'download' ]),
(12, array [ 'decrease', 'delete' ])
)
SELECT value,
type
FROM dataset
WHERE contains(type, 'upload')
输出:
value | type |
---|---|
12 | [increase, upload] |