From 48a590551b2d7b9e07cd05e16e3a9ae4f38839f5 Mon Sep 17 00:00:00 2001 From: Vitaly Baranov Date: Sat, 30 Mar 2019 21:40:52 +0300 Subject: [PATCH] Add test checking using format schema via HTTP interface. --- dbms/tests/integration/helpers/cluster.py | 5 +++ .../test_format_schema_on_server/__init__.py | 0 .../format_schemas/simple.proto | 6 +++ .../test_format_schema_on_server/test.py | 40 +++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 dbms/tests/integration/test_format_schema_on_server/__init__.py create mode 100755 dbms/tests/integration/test_format_schema_on_server/clickhouse_path/format_schemas/simple.proto create mode 100644 dbms/tests/integration/test_format_schema_on_server/test.py diff --git a/dbms/tests/integration/helpers/cluster.py b/dbms/tests/integration/helpers/cluster.py index 240cc2c8695..8db5e59eb00 100644 --- a/dbms/tests/integration/helpers/cluster.py +++ b/dbms/tests/integration/helpers/cluster.py @@ -17,6 +17,7 @@ import psycopg2 import requests import base64 import pymongo +import urllib import docker from docker.errors import ContainerError @@ -482,6 +483,10 @@ class ClickHouseInstance: def get_query_request(self, *args, **kwargs): return self.client.get_query_request(*args, **kwargs) + # Connects to the instance via HTTP interface, sends a query and returns the answer + def http_query(self, sql, data=None): + return urllib.urlopen("http://"+self.ip_address+":8123/?query="+urllib.quote(sql,safe=''), data).read() + def restart_clickhouse(self, stop_start_wait_sec=5): if not self.stay_alive: raise Exception("clickhouse can be restarted only with stay_alive=True instance") diff --git a/dbms/tests/integration/test_format_schema_on_server/__init__.py b/dbms/tests/integration/test_format_schema_on_server/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/dbms/tests/integration/test_format_schema_on_server/clickhouse_path/format_schemas/simple.proto b/dbms/tests/integration/test_format_schema_on_server/clickhouse_path/format_schemas/simple.proto new file mode 100755 index 00000000000..96b24be4938 --- /dev/null +++ b/dbms/tests/integration/test_format_schema_on_server/clickhouse_path/format_schemas/simple.proto @@ -0,0 +1,6 @@ +syntax = "proto3"; + +message KeyValuePair { + uint64 key = 1; + string value = 2; +} \ No newline at end of file diff --git a/dbms/tests/integration/test_format_schema_on_server/test.py b/dbms/tests/integration/test_format_schema_on_server/test.py new file mode 100644 index 00000000000..9d0f6948aef --- /dev/null +++ b/dbms/tests/integration/test_format_schema_on_server/test.py @@ -0,0 +1,40 @@ +import pytest +from helpers.cluster import ClickHouseCluster + +cluster = ClickHouseCluster(__file__) +instance = cluster.add_instance('instance', + clickhouse_path_dir='clickhouse_path') + + +@pytest.fixture(scope="module") +def started_cluster(): + try: + cluster.start() + instance.query('CREATE DATABASE test') + yield cluster + + finally: + cluster.shutdown() + + +def create_simple_table(): + instance.query("DROP TABLE IF EXISTS test.simple") + instance.query(''' + CREATE TABLE test.simple (key UInt64, value String) + ENGINE = MergeTree ORDER BY tuple(); + ''') + + +def test_protobuf_format_input(started_cluster): + create_simple_table() + instance.http_query( + "INSERT INTO test.simple FORMAT Protobuf SETTINGS format_schema='simple:KeyValuePair'", + "\x07\x08\x01\x12\x03abc\x07\x08\x02\x12\x03def") + assert instance.query("SELECT * from test.simple") == "1\tabc\n2\tdef\n" + + +def test_protobuf_format_output(started_cluster): + create_simple_table() + instance.query("INSERT INTO test.simple VALUES (1, 'abc'), (2, 'def')"); + assert instance.http_query("SELECT * FROM test.simple FORMAT Protobuf SETTINGS format_schema='simple:KeyValuePair'") == \ + "\x07\x08\x01\x12\x03abc\x07\x08\x02\x12\x03def"