ClickHouse- 在嵌套字段中搜索

ClickHouse- Search within nested fields

我有一个名为 items.productName 的嵌套字段,我想在其中检查产品名称是否包含特定字符串。

SELECT * FROM test WHERE hasAny(items.productName,['Samsung'])

仅当产品名称为 Samsung 时才有效。

我试过数组连接

SELECT 
    *
FROM test
ARRAY JOIN items
WHERE items.productName LIKE '%Samsung%' 

这可行,但速度很慢(500 万条记录大约需要 1 秒)

有没有办法像在 hasAny 中那样执行?

您可以使用 arrayFilter 函数实现此目的。 ClickHouse docs

查询

Select * from test where arrayFilter(x -> x LIKE '%Samsung%', items.productName) != []

如果你不使用!=[]那么你会得到一个错误"DB::Exception: Illegal type Array(String) of column for filter. Must be UInt8 or Nullable(UInt8) or Const variants of them."