![d0ca27465134fbcf1b62952faed999c3.png](https://img-blog.csdnimg.cn/img_convert/d0ca27465134fbcf1b62952faed999c3.png)
ClickHouse最佳实战之Clickhouse的输入输出数据格式详解
官网:
Distinctive Features | ClickHouse Documentationclickhouse.tech![47390b316e3a5f84656650861896cd12.png](https://img-blog.csdnimg.cn/img_convert/47390b316e3a5f84656650861896cd12.png)
CLickHouse拥有丰富的输入输出格式,对不同的输入输出格式特性的理解有利于对数据的导入,查询的展示,CLickHouse主要分为7种类型系列的输入输出格式,分别是
1、tabseparated系列格式
2、tskv格式
3、csv系列格式
4、json系列格式
5、parquet格式
6、orc格式
7、其他常用的数据格式
一、TabSeparated、TabSeparatedRaw、TabSeparatedWithNames和TabSeparatedWithNamesAndTypes
1. TabSeparated
数据按行写入,tab制表符分隔。使用严格Unix命令行。
注意:最后一行必须包含换行符。
默认格式。
简写:TSV
数据插入和数据查询时,均可使用。
创建表
CREATE TABLE tsv_demo(srcip String, destip String, time String) ENGINE = TinyLog;
数据导入
clickhouse-client --query "INSERT INTO tsv_demo FORMAT TabSeparated" --max_insert_block_size=100000 < tsv_demo.tsv
Code: 117. DB::Exception:
You have carriage return (r, 0x0D, ASCII 13) at end of first row.
It's like your input data has DOS/Windows style line separators, that are illegal in TabSeparated format. You must transform your file to Unix format.
But if you really need carriage return at end of string value of last column, you need to escape it as r.
这是由于windows使用rn表示回车换行, 在linux中使用n表示换行。 因此,需要将r给去掉。
转换为UNIX格式:
dos2unix tsv_demo.tsv
输出格式:
select * from tsv_demo FORMAT TSV;
2. TabSeparatedRaw
简称:TSVRaw
TabSeparatedRaw格式不会对行数据进行转义, 即不会将换行、制表符等转换为转义字符。
只能在数据查询的时候使用。
zhangsan nanjingtjiangsu 23 From nanjing
lisi hangzhoutzhejiang 32 x41 amazing place
xiaoming hefeitanhui 25 notepad
建表语句:
create table escape_demo(name String, addr String, age UInt8, desc String) ENGINE=TinyLog;
select