clickhouse 相关

290 阅读1分钟

背景

为什么写下这篇文章?
因为最近做clickhouse 从21 升级到23的大版本升级,所以随缘记录

查询版本

select version()

目前用的是23.8.12.13

image.png

为什么不用最新的clickhouse LTS版本(24),dba是这样说:
image.png

clickhouse 白嫖

目前clickhouse有两个方式可以不需要本地部署

clickhouse playground

clickhouse playground可以免安装执行相关代码

ClickHouse Playground 是一个由 ClickHouse 提供的在线服务,允许用户在没有安装或配置任何软件的情况下尝试 ClickHouse 数据库。ClickHouse 是一个用于在线分析处理(OLAP)的列式数据库管理系统(DBMS),它特别优化了大数据量的实时分析查询。ClickHouse 的设计目标是实现高速数据插入和实时查询性能,支持包括 SQL 在内的复杂查询。

clickhouse cloud

clickhouse cloud 可以提供3个月的免费实例,实例是部署在aws/google cloud上,还是很不错的

反正我的google账号已经用过了,还是自己搭吧,反正有很多测试机

clickhouse从21升级23遇到的问题

问题1 clickhouse导出不支持lz4

之前的定时任务是导出成lz4的

    INSERT INTO FUNCTION
        s3(
   'https://xxxx.s3.us-west-2.amazonaws.com/bbb/csv/aaa_${dateUrl}.csv.lz4',
   'CSVWithNames',
   'notification_id String , vendor  String , message_type String ,user_id  Nullable(String) ,external_user_id Nullable(String) ,recipient_identifier  Nullable(String) ,event_type String ,campaign_id Int64 ,adlink_ids Nullable(String) ,event_time DateTime64(3) ,created_at DateTime '
)
    select * from  push.mdp_vendor_message_event_all
    where event_time > '${begin}' and event_time  <=   '${end}'  ;

报错LZ4 failed to encode stream. LZ4F version: 100

LZ4 failed to encode stream. LZ4F version: 100. (LZ4_ENCODER_FAILED) (version 23.8.12.13 (official build))

搜索stackoverflow : stackoverflow尝试了一下,发现没什么效果

最后在官网文档找到了方案,不压缩成lz4,而是压缩成gzip链接

  • compression — Parameter is optional. Supported values: nonegzip/gzbrotli/brxz/LZMAzstd/zst. By default, it will autodetect compression by file extension.

改成gzip即可正常导出 最终修改方式: lz4 -> gzip , clickhouse 会自动根据s3后缀识别压缩方式

    INSERT INTO FUNCTION
        s3(
   'https://xxxx.s3.us-west-2.amazonaws.com/bbb/csv/aaa_${dateUrl}.csv.gzip',
   'CSVWithNames',
   'notification_id String , vendor  String , message_type String ,user_id  Nullable(String) ,external_user_id Nullable(String) ,recipient_identifier  Nullable(String) ,event_type String ,campaign_id Int64 ,adlink_ids Nullable(String) ,event_time DateTime64(3) ,created_at DateTime '
)
    select * from  push.mdp_vendor_message_event_all
    where event_time > '${begin}' and event_time  <=   '${end}'  ;