0
votes

I'm using Docker for Windows:

  • Docker version 18.03.1-ce-win64
  • Docker Engine 18.03.1-ce
  • ClickHouse client version 1.1.54380
  • ClickHouse server version 1.1.54380

For exporting data from table into CSV format I am using the command:

  1. Now run clickhouse-client container for export

    $ docker run -it --rm --link clickhouse-server:clickhouse-client yandex/clickhouse-client -m --query="select * from default.table1 FORMAT CSV" > C:/Users/sony/Desktop/table1_data.csv --host clickhouse-server
    

    NOTE: The above command works perfectly.

  2. Now run clickhouse-client container for import

    $ docker run -it --rm --link clickhouse-server:clickhouse-client yandex/clickhouse-client -m -c "cat C:/Users/sony/Desktop/table1_data.csv | clickhouse-client --host clickhouse-server --query='INSERT INTO default.table1 FORMAT CSV' "
    

Could you please tell me what I am doing wrong when importing?

Thanks in advance.

1
you can use HTTP-interface of CH to upload data using curl - look at stackoverflow.com/a/52011930/303298 - vladimir

1 Answers

3
votes

I think you should mount the csv file inside the container first. To mount the file you should add -v C:/Users/sony/Desktop/table1_data.csv :~/table1_data.csv option on your docker command. So your docker run command should be like this:

$ docker run -it --rm --link clickhouse-server:clickhouse-client yandex/clickhouse-client -m -v C:/Users/sony/Desktop/table1_data.csv:~/table1_data.csv -c "cat ~/table1_data.csv | clickhouse-client --host clickhouse-server --query='INSERT INTO default.table1 FORMAT CSV'"

Edit

My bad. Mounting inside the file wont work. Try this instead:

cat path_to_file/table1_data.csv | docker run -i --rm --link clickhouse-server:clickhouse-client yandex/clickhouse-client -m --host clickhouse-server --query="INSERT INTO default.table1 FORMAT CSV"

Already tried on linux, and it works. Since cat not works on Windows, I found type has same functionality, honestly haven't try it:

`type C:/Users/sony/Desktop/table1_data.csv | docker run -i --rm --link clickhouse-server:clickhouse-client yandex/clickhouse-client -m --host clickhouse-server --query="INSERT INTO default.table1 FORMAT CSV"` 

Hope it works.