Skip to content

Instantly share code, notes, and snippets.

@hatarist
Last active June 16, 2024 09:18
Show Gist options
  • Save hatarist/4fc7af52ffb2b2013e961eab5307807b to your computer and use it in GitHub Desktop.
Save hatarist/4fc7af52ffb2b2013e961eab5307807b to your computer and use it in GitHub Desktop.

создаем таблицу

❯ curl -d "" "http://127.0.0.1:8123/?query=CREATE+TABLE+test+(x+UInt32,+y+String,+z+String)+ENGINE+=+TinyLog;"

смотрим формат входящих данных для VALUES

❯ cat example.values
(1, 'foo', 'bar'),
(2, 'foo', 'baz'),
(3, 'fxx', 'bxx')

отправляем POSTом содержимое файла

❯ cat example.values | curl --data-binary "@-" "http://127.0.0.1:8123/?query=INSERT+INTO+test+(x,+y,+z)+FORMAT+Values"

смотрим результат

❯ curl "http://127.0.0.1:8123/?query=SELECT+*+FROM+test+FORMAT+PrettyCompactNoEscapes;"
┌─x─┬─y───┬─z───┐
│ 1 │ foo │ bar │
│ 2 │ foo │ baz │
│ 3 │ fxx │ bxx │
└───┴─────┴─────┘

пересоздаем таблицу

❯ curl --data-binary "" "http://127.0.0.1:8123/?query=DROP+TABLE+test;"
❯ curl --data-binary "" "http://127.0.0.1:8123/?query=CREATE+TABLE+test+(x+UInt32,+y+String,+z+String)+ENGINE+=+TinyLog;"

смотрим формат входящих данных для TSV

❯ cat example.tsv
1	foo	bar
2	foo	baz
3	fxx	bxx

отправляем POSTом содержимое файла

❯ cat example.tsv | curl --data-binary "@-" "http://127.0.0.1:8123/?query=INSERT+INTO+test+(x,+y,+z)+FORMAT+TabSeparated"

смотрим результат

❯ curl "http://127.0.0.1:8123/?query=SELECT+*+FROM+test+FORMAT+PrettyCompactNoEscapes;"
┌─x─┬─y───┬─z───┐
│ 1 │ foo │ bar │
│ 2 │ foo │ baz │
│ 3 │ fxx │ bxx │
└───┴─────┴─────┘

с gzip компрессией как-то так:

❯ curl --data-binary "" "http://127.0.0.1:8123/?query=DROP+TABLE+test;"
❯ curl --data-binary "" "http://127.0.0.1:8123/?query=CREATE+TABLE+test+(x+UInt32,+y+String,+z+String)+ENGINE+=+TinyLog;"
❯ time cat example.values | gzip --to-stdout | curl --data-binary "@-" "http://127.0.0.1:8123/?query=INSERT+INTO+test+(x,+y,+z)+FORMAT+Values&enable_http_compression=1" -H 'Content-Encoding: gzip'


❯ curl --data-binary "" "http://127.0.0.1:8123/?query=DROP+TABLE+test;"
❯ curl --data-binary "" "http://127.0.0.1:8123/?query=CREATE+TABLE+test+(x+UInt32,+y+String,+z+String)+ENGINE+=+TinyLog;"
❯ time cat example.tsv | gzip --to-stdout | curl --data-binary "@-" "http://127.0.0.1:8123/?query=INSERT+INTO+test+(x,+y,+z)+FORMAT+TabSeparated&enable_http_compression=1" -H 'Content-Encoding: gzip'
@bsa7
Copy link

bsa7 commented May 16, 2022

How to attach a multiple colums csv file to read all columns in SELECT * FROM csv_rows query?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment