首页 > 解决方案 > ClickHouse - 在嵌套字段中搜索

问题描述

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

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

这仅适用于产品名称为三星的情况。

我试过数组加入

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

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

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

标签: nestedclickhouse

解决方案


您可以使用 arrayFilter 函数来实现这一点。ClickHouse 文档

询问

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 variant of them.”


推荐阅读