メインコンテンツまでスキップ
メインコンテンツまでスキップ

入力と出力データのフォーマット

ClickHouseは、既知のほとんどのテキストおよびバイナリデータフォーマットをサポートしています。これにより、ClickHouseの利点を活かすためにほぼすべての作業データパイプラインへの簡単な統合が可能になります。

入力フォーマット

入力フォーマットは次の用途に使用されます:

  • INSERTステートメントに提供されたデータを解析するため
  • FileURL、またはHDFSのようなファイルバックテーブルからのSELECTクエリを実行するため
  • 辞書を読み取るため

適切な入力フォーマットを選択することは、ClickHouseにおける効率的なデータイングestionにとって非常に重要です。70を超えるサポートフォーマットの中から、最もパフォーマンスの高いオプションを選ぶことで、挿入速度、CPUとメモリの使用量、全体的なシステムの効率に大きな影響を与えることができます。これらの選択肢をナビゲートするために、私たちはフォーマット間でのイングestionパフォーマンスをベンチマークし、重要な知見を明らかにしました:

  • 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
JSONCompactStringsEachRowWithProgress
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

See TabSeparated

TabSeparatedRaw

See TabSeparatedRaw

TabSeparatedWithNames

See TabSeparatedWithNames

TabSeparatedWithNamesAndTypes

See TabSeparatedWithNamesAndTypes

TabSeparatedRawWithNames

See TabSeparatedRawWithNames

TabSeparatedRawWithNamesAndTypes

See TabSeparatedRawWithNamesAndTypes

Template

See Template

TemplateIgnoreSpaces

See TemplateIgnoreSpaces

TSKV

See TSKV

CSV

See CSV

CSVWithNames

See CSVWithNames

CSVWithNamesAndTypes

See CSVWithNamesAndTypes

CustomSeparated

See CustomSeparated

CustomSeparatedWithNames

See CustomSeparatedWithNames

CustomSeparatedWithNamesAndTypes

See CustomSeparatedWithNamesAndTypes

SQLInsert

See SQLInsert

JSON

See JSON

JSONStrings

See JSONStrings

JSONColumns

See JSONColumns

JSONColumnsWithMetadata

See JSONColumnsWithMetadata

JSONAsString

See JSONAsString

JSONAsObject

See JSONAsObject

JSONCompact

See JSONCompact

JSONCompactStrings

See JSONCompactStrings

JSONCompactColumns

See JSONCompactColumns

JSONEachRow

See JSONEachRow

PrettyJSONEachRow

See PrettyJSONEachRow

JSONStringsEachRow

See JSONStringsEachRow

JSONCompactEachRow

See JSONCompactEachRow

JSONCompactStringsEachRow

See JSONCompactStringsEachRow

JSONEachRowWithProgress

See JSONEachRowWithProgress

JSONStringsEachRowWithProgress

See JSONStringsEachRowWithProgress

JSONCompactEachRowWithNames

See JSONCompactEachRowWithNames

JSONCompactEachRowWithNamesAndTypes

See JSONCompactEachRowWithNamesAndTypes

JSONCompactEachRowWithProgress

JSONEachRowWithProgressと似ていますが、JSONCompactEachRowフォーマットのように、rowイベントをコンパクトな形式で出力します。

JSONCompactStringsEachRowWithNames

See JSONCompactStringsEachRowWithNames

JSONCompactStringsEachRowWithNamesAndTypes

See JSONCompactStringsEachRowWithNamesAndTypes

JSONObjectEachRow

See JSONObjectEachRow

JSONフォーマットの設定

See JSON Format Settings

BSONEachRow

See BSONEachRow

Native

See Native

Null

See Null

Hash

See Hash

Pretty

See Pretty

PrettyNoEscapes

See PrettyNoEscapes

PrettyMonoBlock

See PrettyMonoBlock

PrettyNoEscapesMonoBlock

See PrettyNoEscapesMonoBlock

PrettyCompact

See PrettyCompact

PrettyCompactNoEscapes

See PrettyCompactNoEscapes

PrettyCompactMonoBlock

See PrettyCompactMonoBlock

PrettyCompactNoEscapesMonoBlock

See PrettyCompactNoEscapesMonoBlock

PrettySpace

See PrettySpace

PrettySpaceNoEscapes

See PrettySpaceNoEscapes

PrettySpaceMonoBlock

See PrettySpaceMonoBlock

PrettySpaceNoEscapesMonoBlock

See PrettySpaceNoEscapesMonoBlock

RowBinary

See RowBinary

RowBinaryWithNames

See RowBinaryWithNames

RowBinaryWithNamesAndTypes

See RowBinaryWithNamesAndTypes

RowBinaryWithDefaults

See RowBinaryWithDefaults

Values

See Values

Vertical

See Vertical

XML

See XML

CapnProto

See CapnProto

Prometheus

See Prometheus

Protobuf

See Protobuf

ProtobufSingle

See ProtobufSingle

ProtobufList

See ProtobufList

Avro

See Avro

AvroConfluent

See AvroConfluent

Parquet

See Parquet

ParquetMetadata

See ParquetMetadata

Arrow

See Arrow

ArrowStream

See ArrowStream

ORC

See ORC

One

See One

Npy

See Npy

LineAsString

See:

Regexp

See Regexp

RawBLOB

See RawBLOB

Markdown

See Markdown

MsgPack

See MsgPack

MySQLDump

See MySQLDump

DWARF

See Dwarf

Form

See Form

フォーマットスキーマ

フォーマットスキーマを含むファイル名は、format_schema設定によって設定されます。 これは、Cap'n ProtoおよびProtobufのいずれかのフォーマットが使用される場合には、この設定を設定することが必須です。 フォーマットスキーマは、ファイル名とそのファイル内のメッセージタイプの名前の組み合わせで、コロンで区切られています。 例えば、schemafile.proto:MessageTypeのようにします。 ファイルがフォーマットの標準拡張子を持っている場合(例えば、Protobufの場合は.proto)、省略することができ、 この場合、フォーマットスキーマはschemafile:MessageTypeのようになります。

クライアントを介してインタラクティブモードでデータを入力または出力する場合、フォーマットスキーマで指定されたファイル名には絶対パスまたはクライアントの現在のディレクトリに対する相対パスを含めることができます。 バッチモードでクライアントを使用する場合、セキュリティ上の理由から、スキーマへのパスは相対である必要があります。

HTTPインターフェースを介してデータを入力または出力する場合、フォーマットスキーマで指定されたファイル名は、 サーバー設定のformat_schema_pathで指定されたディレクトリにある必要があります。

エラーをスキップする

CSVTabSeparatedTSKVJSONEachRowTemplateCustomSeparatedProtobufなどのいくつかのフォーマットは、解析エラーが発生した場合に壊れた行をスキップし、次の行の最初から解析を続行できます。 input_format_allow_errors_numおよびinput_format_allow_errors_ratio設定を参照してください。 制限:

  • 解析エラーの場合、JSONEachRowは新しい行(またはEOF)までの全データをスキップするため、行はエラーを正しくカウントするために\nで区切られている必要があります。
  • TemplateおよびCustomSeparatedは、次の行の開始を見つけるために最後の列の後の区切り記号と行の間の区切り記号を使用するため、いずれかが空でない場合にのみエラーをスキップできます。