Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 35 additions & 17 deletions tests/integration_tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest

from clickhouse_connect import create_client
from clickhouse_connect import datatypes
from clickhouse_connect.driver.client import Client
from clickhouse_connect.driver.exceptions import DatabaseError
from tests.integration_tests.conftest import TestConfig
Expand Down Expand Up @@ -105,9 +106,25 @@ def test_dsn_config(test_config: TestConfig):
client.close()


def test_no_columns_and_types_when_no_results(test_client: Client):
""" In case of no results, the column names and types are not returned when FORMAT Native is set.
This may cause a lot of confusion.

Read more: https://github.com/ClickHouse/clickhouse-connect/issues/257
"""
result = test_client.query('SELECT name, database, NOW() as dt FROM system.tables WHERE FALSE')
assert result.column_names == ()
assert result.column_types == ()
assert result.result_set == []


def test_get_columns_only(test_client: Client):
result = test_client.query('SELECT name, database FROM system.tables LIMIT 0')
assert result.column_names == ('name', 'database')
result = test_client.query('SELECT name, database, NOW() as dt FROM system.tables LIMIT 0')
assert result.column_names == ('name', 'database', 'dt')
assert len(result.column_types) == 3
assert isinstance(result.column_types[0], datatypes.string.String)
assert isinstance(result.column_types[1], datatypes.string.String)
assert isinstance(result.column_types[2], datatypes.temporal.DateTime)
assert len(result.result_set) == 0

test_client.query('CREATE TABLE IF NOT EXISTS test_zero_insert (v Int8) ENGINE MergeTree() ORDER BY tuple()')
Expand All @@ -124,29 +141,29 @@ def test_no_limit(test_client: Client):

def test_multiline_query(test_client: Client):
result = test_client.query("""
SELECT *
FROM system.tables
""")
SELECT *
FROM system.tables
""")
assert len(result.result_set) > 0


def test_query_with_inline_comment(test_client: Client):
result = test_client.query("""
SELECT *
-- This is just a comment
FROM system.tables LIMIT 77
-- A second comment
""")
SELECT *
-- This is just a comment
FROM system.tables LIMIT 77
-- A second comment
""")
assert len(result.result_set) > 0


def test_query_with_comment(test_client: Client):
result = test_client.query("""
SELECT *
/* This is:
a multiline comment */
FROM system.tables
""")
SELECT *
/* This is:
a multiline comment */
FROM system.tables
""")
assert len(result.result_set) > 0


Expand Down Expand Up @@ -200,13 +217,14 @@ def test_empty_result(test_client: Client):

def test_temporary_tables(test_client: Client):
test_client.command("""
CREATE TEMPORARY TABLE temp_test_table
CREATE
TEMPORARY TABLE temp_test_table
(
field1 String,
field2 String
)""")

test_client.command ("INSERT INTO temp_test_table (field1, field2) VALUES ('test1', 'test2'), ('test3', 'test4')")
test_client.command("INSERT INTO temp_test_table (field1, field2) VALUES ('test1', 'test2'), ('test3', 'test4')")
df = test_client.query_df('SELECT * FROM temp_test_table')
test_client.insert_df('temp_test_table', df)
df = test_client.query_df('SELECT * FROM temp_test_table')
Expand Down