[go: up one dir, main page]

跳到主要内容
跳到主要内容

输入和输出数据格式

ClickHouse 支持大多数已知的文本和二进制数据格式。这使得几乎可以轻松地集成到任何工作数据管道中,利用 ClickHouse 的优势。

输入格式

输入格式用于:

  • 解析提供给 INSERT 语句的数据
  • 从文件支持的表(如 FileURLHDFS)执行 SELECT 查询
  • 读取字典

选择正确的输入格式对于 ClickHouse 中高效的数据摄取至关重要。支持超过 70 种格式,选择性能最优的选项可以显著影响插入速度、CPU 和内存使用以及整体系统效率。为了帮助用户了解这些选择,我们对不同格式的摄取性能进行了基准测试,得出了关键结论:

  • Native 格式是最高效的输入格式,提供最佳压缩、最低资源使用和最小的服务器端处理开销。
  • 压缩是至关重要的 - LZ4 使用最小的 CPU 成本减少数据大小,而 ZSTD 提供更高的压缩比,但需额外的 CPU 使用。
  • 预排序的影响适中,因为 ClickHouse 本身已经高效地进行了排序。
  • 批处理显著提高了效率 - 较大的批次减少了插入开销并提高了吞吐量。

有关结果和最佳实践的详细研究,请阅读完整的 基准分析。要查看完整测试结果,请浏览 FastFormats 在线仪表板。

输出格式

支持的输出格式用于:

  • 安排 SELECT 查询的结果
  • 执行对文件支持的表的 INSERT 操作

格式概述

支持的格式如下:

格式输入输出
TabSeparated
TabSeparatedRaw
TabSeparatedWithNames
TabSeparatedWithNamesAndTypes
TabSeparatedRawWithNames
TabSeparatedRawWithNamesAndTypes
Template
TemplateIgnoreSpaces
CSV
CSVWithNames
CSVWithNamesAndTypes
CustomSeparated
CustomSeparatedWithNames
CustomSeparatedWithNamesAndTypes
SQLInsert
Values
Vertical
JSON
JSONAsString
JSONAsObject
JSONStrings
JSONColumns
JSONColumnsWithMetadata
JSONCompact
JSONCompactStrings
JSONCompactColumns
JSONEachRow
PrettyJSONEachRow
JSONEachRowWithProgress
JSONStringsEachRow
JSONStringsEachRowWithProgress
JSONCompactEachRow
JSONCompactEachRowWithNames
JSONCompactEachRowWithNamesAndTypes
JSONCompactEachRowWithProgress
JSONCompactStringsEachRow
JSONCompactStringsEachRowWithNames
JSONCompactStringsEachRowWithNamesAndTypes
JSONObjectEachRow
BSONEachRow
TSKV
Pretty
PrettyNoEscapes
PrettyMonoBlock
PrettyNoEscapesMonoBlock
PrettyCompact
PrettyCompactNoEscapes
PrettyCompactMonoBlock
PrettyCompactNoEscapesMonoBlock
PrettySpace
PrettySpaceNoEscapes
PrettySpaceMonoBlock
PrettySpaceNoEscapesMonoBlock
Prometheus
Protobuf
ProtobufSingle
ProtobufList
Avro
AvroConfluent
Parquet
ParquetMetadata
Arrow
ArrowStream
ORC
One
Npy
RowBinary
RowBinaryWithNames
RowBinaryWithNamesAndTypes
RowBinaryWithDefaults
Native
Null
Hash
XML
CapnProto
LineAsString
Regexp
RawBLOB
MsgPack
MySQLDump
DWARF
Markdown
Form

您可以通过 ClickHouse 设置控制一些格式处理参数。有关更多信息,请阅读 设置 部分。

TabSeparated

请参阅 TabSeparated

TabSeparatedRaw

请参阅 TabSeparatedRaw

TabSeparatedWithNames

请参阅 TabSeparatedWithNames

TabSeparatedWithNamesAndTypes

请参阅 TabSeparatedWithNamesAndTypes

TabSeparatedRawWithNames

请参阅 TabSeparatedRawWithNames

TabSeparatedRawWithNamesAndTypes

请参阅 TabSeparatedRawWithNamesAndTypes

Template

请参阅 Template

TemplateIgnoreSpaces

请参阅 TemplateIgnoreSpaces

TSKV

请参阅 TSKV

CSV

请参阅 CSV

CSVWithNames

请参阅 CSVWithNames

CSVWithNamesAndTypes

请参阅 CSVWithNamesAndTypes

CustomSeparated

请参阅 CustomSeparated

CustomSeparatedWithNames

请参阅 CustomSeparatedWithNames

CustomSeparatedWithNamesAndTypes

请参阅 CustomSeparatedWithNamesAndTypes

SQLInsert

请参阅 SQLInsert

JSON

请参阅 JSON

JSONStrings

请参阅 JSONStrings

JSONColumns

请参阅 JSONColumns

JSONColumnsWithMetadata

请参阅 JSONColumnsWithMetadata

JSONAsString

请参阅 JSONAsString

JSONAsObject

请参阅 JSONAsObject

JSONCompact

请参阅 JSONCompact

JSONCompactStrings

请参阅 JSONCompactStrings

JSONCompactColumns

请参阅 JSONCompactColumns

JSONEachRow

请参阅 JSONEachRow

PrettyJSONEachRow

请参阅 PrettyJSONEachRow

JSONStringsEachRow

请参阅 JSONStringsEachRow

JSONCompactEachRow

请参阅 JSONCompactEachRow

JSONCompactStringsEachRow

请参阅 JSONCompactStringsEachRow

JSONEachRowWithProgress

请参阅 JSONEachRowWithProgress

JSONStringsEachRowWithProgress

请参阅 JSONStringsEachRowWithProgress

JSONCompactEachRowWithNames

请参阅 JSONCompactEachRowWithNames

JSONCompactEachRowWithNamesAndTypes

请参阅 JSONCompactEachRowWithNamesAndTypes

JSONCompactEachRowWithProgress

类似于 JSONEachRowWithProgress,但以紧凑形式输出 row 事件,如同在 JSONCompactEachRow 格式中。

JSONCompactStringsEachRowWithNames

请参阅 JSONCompactStringsEachRowWithNames

JSONCompactStringsEachRowWithNamesAndTypes

请参阅 JSONCompactStringsEachRowWithNamesAndTypes

JSONObjectEachRow

请参阅 JSONObjectEachRow

JSON 格式设置

请参阅 JSON 格式设置

BSONEachRow

请参阅 BSONEachRow

Native

请参阅 Native

Null

请参阅 Null

Hash

请参阅 Hash

Pretty

请参阅 Pretty

PrettyNoEscapes

请参阅 PrettyNoEscapes

PrettyMonoBlock

请参阅 PrettyMonoBlock

PrettyNoEscapesMonoBlock

请参阅 PrettyNoEscapesMonoBlock

PrettyCompact

请参阅 PrettyCompact

PrettyCompactNoEscapes

请参阅 PrettyCompactNoEscapes

PrettyCompactMonoBlock

请参阅 PrettyCompactMonoBlock

PrettyCompactNoEscapesMonoBlock

请参阅 PrettyCompactNoEscapesMonoBlock

PrettySpace

请参阅 PrettySpace

PrettySpaceNoEscapes

请参阅 PrettySpaceNoEscapes

PrettySpaceMonoBlock

请参阅 PrettySpaceMonoBlock

PrettySpaceNoEscapesMonoBlock

请参阅 PrettySpaceNoEscapesMonoBlock

RowBinary

请参阅 RowBinary

RowBinaryWithNames

请参阅 RowBinaryWithNames

RowBinaryWithNamesAndTypes

请参阅 RowBinaryWithNamesAndTypes

RowBinaryWithDefaults

请参阅 RowBinaryWithDefaults

Values

请参阅 Values

Vertical

请参阅 Vertical

XML

请参阅 XML

CapnProto

请参阅 CapnProto

Prometheus

请参阅 Prometheus

Protobuf

请参阅 Protobuf

ProtobufSingle

请参阅 ProtobufSingle

ProtobufList

请参阅 ProtobufList

Avro

请参阅 Avro

AvroConfluent

请参阅 AvroConfluent

Parquet

请参阅 Parquet

ParquetMetadata

请参阅 ParquetMetadata

Arrow

请参阅 Arrow

ArrowStream

请参阅 ArrowStream

ORC

请参阅 ORC

One

请参阅 One

Npy

请参阅 Npy

LineAsString

请参阅:

Regexp

请参阅 Regexp

RawBLOB

请参阅 RawBLOB

Markdown

请参阅 Markdown

MsgPack

请参阅 MsgPack

MySQLDump

请参阅 MySQLDump

DWARF

请参阅 Dwarf

Form

请参阅 Form

格式模式

包含格式模式的文件名由设置 format_schema 设置。 在使用 Cap'n ProtoProtobuf 格式之一时,必须设置此选项。 格式模式是文件名和该文件中消息类型名称的组合,以冒号分隔,例如 schemafile.proto:MessageType。 如果文件具有格式的标准扩展名(例如,.proto 用于 Protobuf),则可以省略,在这种情况下,格式模式看起来像 schemafile:MessageType

如果您通过 客户端 在交互模式下输入或输出数据,则在格式模式中指定的文件名可以包含绝对路径或客户端当前目录的相对路径。 如果您在 批处理模式 下使用客户端,出于安全原因,模式的路径必须是相对的。

如果您通过 HTTP 接口 输入或输出数据,则格式模式中指定的文件名应位于 format_schema_path 中指定的目录下。

跳过错误

某些格式,如 CSVTabSeparatedTSKVJSONEachRowTemplateCustomSeparatedProtobuf,如果发生解析错误,则可以跳过损坏的行,并继续从下一行的开头解析。请参见 input_format_allow_errors_numinput_format_allow_errors_ratio 设置。 限制:

  • 在发生解析错误时,JSONEachRow 跳过所有数据,直到新行(或 EOF),因此行之间必须用 \n 分隔,以便正确计算错误。
  • TemplateCustomSeparated 使用最后一列之后的分隔符和行之间的分隔符来查找下一行的开头,因此只有在至少其中一个不为空的情况下,才会跳过错误。