Clickhouse匯入CSV檔案
阿新 • • 發佈:2021-08-11
一、背景
平常開發會員一次性的需求,列入將一個大檔案匯入到CK中進行資料分析,以下記錄一下CSV匯入到CK的過程:
二、建立表結構
CREATE TABLE default.test_table (
`index` String,
`uuid` String,
`variables` String,
`title` String,
`title_explain` String,
`title_meaning` String
) ENGINE = MergeTree() PARTITION BY sipHash64(uuid)%20 ORDER BY sipHash64(uuid)%20 SETTINGS index_granularity = 8192
注:由於此表沒有年月日,所以按照sipHash64(uuid)%20分成20個分割槽,若這裡直接用uuid分割槽會產生太多的分割槽,有可能導致分割槽過多報錯,我剛開始沒注意的時候,就是因為產生了太多的分割槽匯入失敗,報錯資訊為:
Too many partitions for single INSERT block (more than 100),所以需要注意一下。
三.匯入資料
方式一:登入伺服器使用客戶端
clickhouse-client -h xxx.x.x.x --database="default" --query="select * from default.test_table FORMAT CSV" > test.csv
方式二:直接連線資料庫,例如用dbserver客戶到,建立表之後,直接匯入資料即可