参考文档
https://clickhouse.tech/docs/en/engines/table-engines/integrations/hdfs/
前言
在hdfs格式ck能解析的情况下,比如CSV,TSV等,可以在ck中建立一个映射表。读取hdfs中的数据,使用ck来分析。需要注意的是如果uri路径中包括了Globs模糊匹配符号,那么说明ck只是映射hdfs中的文件,是只读的。如果写入会报DB::Exception: URI 'hdfs:xxxxxx/some_file_?' contains globs, so the table is in readonly mode错误。如果不包括Globs模糊匹配符号,也就是表名固定的情况下,hdfs只能写一次,否则会报DB::Exception: File: xxxx is already exists.的错误。
试一试
Globs
![](https://img.haomeiwen.com/i25495922/46d440488833d1b6.png)
使用准备
先在hdfs中建立文件夹并授权clickhouse用户权限
hdfs dfs -mkdir -p /clickhouse/table
hdfs dfs -chmod 777 /clickhouse/table 或者 hdfs dfs -chown -R clickhouse:clickhouse /clickhouse/table
URI 无 Globs
1,建表
CREATE TABLE table_with_range(name String, value UInt32) ENGINE=HDFS('hdfs://xxxxx/clickhouse/table/ckhdfs_file_1', 'TSV')
2,insert数据
INSERT INTO table_with_range_v2 VALUES ('1aaaa', 1), ('1bbbb', 2), ('2cccc', 3), ('2dddd', 3), ('3eeee', 3), ('3fff', 3), ('4ggg', 3), ('4kkk', 3)
3,再次insert
![](https://img.haomeiwen.com/i25495922/b0efa7036f3bc43e.png)
可见固定表名,uri无globs模式,数据也insert只能一次。
4,查询结果
![](https://img.haomeiwen.com/i25495922/3fa120da45d5ca2f.png)
查询结果正常。
URI 有 Globs
1,新建表
CREATE TABLE table_with_range_vs(name String, value UInt32) ENGINE=HDFS('hdfs://xxxx/clickhouse/table/ckhdfs_file_*', 'TSV')
2,insert数据
![](https://img.haomeiwen.com/i25495922/65342c9389ebf31a.png)
可见 Globs只能映射已经存在的数据,表只读。
3,查询数据
![](https://img.haomeiwen.com/i25495922/1ec1763981a009b7.png)
查询数据正常,映射生效。
Tips
1,clickhouse 对接有kerberos验证的hdfs
文档:https://clickhouse.com/docs/en/engines/table-engines/integrations/hdfs/#clickhouse-extras
![](https://img.haomeiwen.com/i25495922/394f1a6f770b4a6a.png)
网友评论