2021-08-07 08:11:40 +00:00
|
|
|
|
import pytest
|
|
|
|
|
from helpers.cluster import ClickHouseCluster
|
|
|
|
|
|
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
|
node1 = cluster.add_instance(
|
|
|
|
|
"node1", user_configs=["configs/users.xml"], with_zookeeper=True
|
|
|
|
|
)
|
|
|
|
|
|
2021-08-07 08:11:40 +00:00
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
|
def started_cluster():
|
|
|
|
|
try:
|
|
|
|
|
cluster.start()
|
|
|
|
|
yield cluster
|
|
|
|
|
finally:
|
|
|
|
|
cluster.shutdown()
|
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
|
|
2021-08-07 08:11:40 +00:00
|
|
|
|
def test_cast_keep_nullable(started_cluster):
|
2022-03-22 16:39:58 +00:00
|
|
|
|
setting = node1.query(
|
|
|
|
|
"SELECT value FROM system.settings WHERE name='cast_keep_nullable'"
|
|
|
|
|
)
|
|
|
|
|
assert setting.strip() == "1"
|
2021-08-07 08:11:40 +00:00
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
|
result = node1.query(
|
|
|
|
|
"""
|
2021-08-07 08:11:40 +00:00
|
|
|
|
DROP TABLE IF EXISTS t;
|
|
|
|
|
CREATE TABLE t (x UInt64) ENGINE = MergeTree ORDER BY tuple();
|
|
|
|
|
INSERT INTO t SELECT number FROM numbers(10);
|
|
|
|
|
SELECT * FROM t;
|
2022-03-22 16:39:58 +00:00
|
|
|
|
"""
|
|
|
|
|
)
|
|
|
|
|
assert result.strip() == "0\n1\n2\n3\n4\n5\n6\n7\n8\n9"
|
2021-08-07 08:11:40 +00:00
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
|
error = node1.query_and_get_error(
|
|
|
|
|
"""
|
2021-08-07 08:11:40 +00:00
|
|
|
|
SET mutations_sync = 1;
|
|
|
|
|
ALTER TABLE t UPDATE x = x % 3 = 0 ? NULL : x WHERE x % 2 = 1;
|
2022-03-22 16:39:58 +00:00
|
|
|
|
"""
|
|
|
|
|
)
|
|
|
|
|
assert "DB::Exception: Cannot convert NULL value to non-Nullable type" in error
|
2021-08-07 08:11:40 +00:00
|
|
|
|
|
|
|
|
|
result = node1.query("SELECT * FROM t;")
|
2022-03-22 16:39:58 +00:00
|
|
|
|
assert result.strip() == "0\n1\n2\n3\n4\n5\n6\n7\n8\n9"
|