database-performance - Snowflake: clustering on datetime key stored in variant field does not work / do partition pruning
问题描述
We are ingesting data into Snowflake via the kafka connector. To increase the data read performance / scan less partitions we decided to add a clustering key to a a key / combination of keys stored in the RECORD_CONTENT variant field.
The data in the RECORD_CONTENT field looks like this:
{
"jsonSrc": {
"Integerfield": 1,
"SourceDateTime": "2020-06-30 05:33:08:345",
*REST_OF_THE_KEY_VALUE_PAIRS*
}
Now, the issue is that clustering on a datetime col like SourceDateTime does NOT work:
CLUSTER BY (to_date(RECORD_CONTENT:jsonSrc:loadDts::datetime))
...while clustering on a field like Integerfield DOES work:
CLUSTER BY (RECORD_CONTENT:jsonSrc:Integerfield::int )
Not working means: when using a filter on RECORD_CONTENT:jsonSrc:loadDts::datetime, it has no effect on the partitions scanned, while filtering on RECORD_CONTENT:jsonSrc:Integerfield::int does perform partition pruning.
What is wrong here? Is this a bug?
Note that:
- There is enough data to do meaningful clustering on RECORD_CONTENT:jsonSrc:loadDts::datetime
- I validated clustering on RECORD_CONTENT:jsonSrc:loadDts::datetime working by making a copy of the raw table, with RECORD_CONTENT:jsonSrc:loadDts::datetime in a seperate column loadDtsCol and then adding a similar clustering key on that column: to_date(loadDtsCol).
解决方案
为了更好地修剪和减少存储消耗,如果您的半结构化数据包括:日期和时间戳,尤其是非 ISO 8601 日期和时间戳,我们建议将您的对象和关键数据扁平化到单独的关系列中,作为字符串值
字符串中的数字
数组
日期和时间戳等非本机值在加载到 VARIANT 列时存储为字符串,因此与存储在具有相应数据类型的关系列中相比,对这些值的操作可能会更慢并且消耗更多空间。
推荐阅读
- ios - 如何在一个简单的应用程序上调试大量内存问题
- django - 使用 Pycharm 和 Django 的本地设置
- html - VBA:从 HTMLTable 中抓取确切的元素
- python - 使用 Win10 任务调度器通过批处理调度 Scrapy Spider
- json - 处理(读取)逻辑应用程序中的 Base64 编码文件,并发布到端点
- jenkins - 由于在 /tmp/.jenkins/jenkins/ 目录下运行脚本的 cron 作业导致 CPU 利用率高
- c# - 将 1 更新为多个导航属性时出错
- php - HTML 标记
在聊天工具上发送消息时插入到 moodle ajax 响应中
- jenkins - 正确发送从我们不同的 Jenkins 工作发送的电子邮件的标准方法是什么?
- android - 使用 `xmpp` 和 `smack` 从 `vcard` 获取自定义元素