nested - 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 中一样执行?
解决方案
您可以使用 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.”
推荐阅读
- java - 使用 Swing 工作线程更新 Swing 组件
- sql - 多列设置空值
- python - 线程在 Python 中无法正常处理 SQL 请求
- javascript - 通过 App-Script 将 HTML 模板正文传递给 gmail 正文时遇到问题
- json - Elasticsearch 查询以获取链接到键名的多个属性的所有值
- javascript - 如何自动创建客户端机密 json 文件
- chromecast - 有没有办法将 Google Data Studios 不断流式传输到 Chromecast 上。希望为办公室创建一个数据监视器
- android-studio - 需要停止 Startapp Splash Ad
- c# - 除非完成垂直滚动,否则不会显示 WPF ListView 水平滚动条
- angular - 错误:断言错误:传入的类型不是 NgModuleType,它没有 'ɵmod' 属性