ClickHouse/docs/ja/engines/table_engines/special/external_data.md
2020-04-04 12:15:31 +03:00

4.1 KiB
Raw Blame History

machine_translated machine_translated_rev toc_priority toc_title
true d734a8e46d 34 外部データ

クエリ処理のための外部データ

ClickHouseでは、クエリの処理に必要なデータとSELECTクエリをサーバーに送信できます。 このデータは一時テーブルに格納されます(セクションを参照 “Temporary tables” また、クエリで使用することもできます(たとえば、IN演算子など)。

たとえば、重要なユーザー識別子を持つテキストファイルがある場合は、このリストのフィルタリングを使用するクエリと一緒にサーバーにアップロードで

大量の外部データを含む複数のクエリを実行する必要がある場合は、この機能を使用しないでください。 事前にデータをdbにアップロードする方が良いです。

外部データは、コマンドラインクライアント(非対話モード)またはhttpインターフェイスを使用してアップロードできます。

コマンドラインクライアントでは、次の形式でparametersセクションを指定できます

--external --file=... [--name=...] [--format=...] [--types=...|--structure=...]

送信されるテーブルの数については、このような複数のセクションがあります。

external Marks the beginning of a clause. file Path to the file with the table dump, or -, which refers to stdin. Stdinから取得できるのは、単一のテーブルだけです。

次のパラメーターは省略可能です: name Name of the table. If omitted, _data is used. format Data format in the file. If omitted, TabSeparated is used.

次のパラメーターのいずれかが必要です:types A list of comma-separated column types. For example: UInt64,String. The columns will be named _1, _2, … structure The table structure in the formatUserID UInt64, URL String. 列の名前と型を定義します。

で指定されたファイル file で指定された形式によって解析されます。 format で指定されたデータ型を使用する。 types または structure. テーブルはサーバーにアップロードされ、そこにアクセスできるようになります。 name.

例:

$ echo -ne "1\n2\n3\n" | clickhouse-client --query="SELECT count() FROM test.visits WHERE TraficSourceID IN _data" --external --file=- --types=Int8
849897
$ cat /etc/passwd | sed 's/:/\t/g' | clickhouse-client --query="SELECT shell, count() AS c FROM passwd GROUP BY shell ORDER BY c DESC" --external --file=- --name=passwd --structure='login String, unused String, uid UInt16, gid UInt16, comment String, home String, shell String'
/bin/sh 20
/bin/false      5
/bin/bash       4
/usr/sbin/nologin       1
/bin/sync       1

HTTPインターフェイスを使用する場合、外部データはmultipart/form-data形式で渡されます。 各テーブルは別のファイルとして送信されます。 テーブル名はファイル名から取得されます。 その query_string パラメータが渡されます name_format, name_types、と name_structure、どこ name これらのパラメーターが対応するテーブルの名前です。 パラメータの意味は、コマンドラインクライアントを使用する場合と同じです。

例えば:

$ cat /etc/passwd | sed 's/:/\t/g' > passwd.tsv

$ curl -F 'passwd=@passwd.tsv;' 'http://localhost:8123/?query=SELECT+shell,+count()+AS+c+FROM+passwd+GROUP+BY+shell+ORDER+BY+c+DESC&passwd_structure=login+String,+unused+String,+uid+UInt16,+gid+UInt16,+comment+String,+home+String,+shell+String'
/bin/sh 20
/bin/false      5
/bin/bash       4
/usr/sbin/nologin       1
/bin/sync       1

分散クエリ処理の場合、一時テーブルはすべてのリモートサーバーに送信されます。

元の記事