2020-04-20 11:15:06 +00:00
|
|
|
import pytest
|
2024-09-27 10:19:39 +00:00
|
|
|
|
2020-04-20 11:15:06 +00:00
|
|
|
from helpers.client import QueryRuntimeException
|
|
|
|
from helpers.cluster import ClickHouseCluster
|
|
|
|
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
node1 = cluster.add_instance("node1", main_configs=["configs/logs_config.xml"])
|
2020-04-20 11:15:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def started_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
yield cluster
|
|
|
|
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
def test_alter_codec_pk(started_cluster):
|
|
|
|
try:
|
|
|
|
name = "test_alter_codec_pk"
|
|
|
|
node1.query(
|
|
|
|
"""
|
2020-06-22 11:03:01 +00:00
|
|
|
CREATE TABLE {name} (id UInt64, value UInt64) Engine=MergeTree() ORDER BY id
|
2020-04-20 11:15:06 +00:00
|
|
|
""".format(
|
|
|
|
name=name
|
|
|
|
)
|
2020-06-22 11:03:01 +00:00
|
|
|
)
|
2022-03-22 16:39:58 +00:00
|
|
|
|
2020-06-22 11:03:01 +00:00
|
|
|
node1.query(
|
|
|
|
"INSERT INTO {name} SELECT number, number * number from numbers(100)".format(
|
|
|
|
name=name
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2020-04-20 11:15:06 +00:00
|
|
|
node1.query(
|
|
|
|
"ALTER TABLE {name} MODIFY COLUMN id UInt64 CODEC(NONE)".format(name=name)
|
|
|
|
)
|
|
|
|
node1.query(
|
|
|
|
"ALTER TABLE {name} MODIFY COLUMN id UInt64 CODEC(Delta, LZ4)".format(
|
|
|
|
name=name
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
|
|
|
)
|
2020-04-20 11:15:06 +00:00
|
|
|
|
2020-06-22 11:03:01 +00:00
|
|
|
assert node1.query("SELECT sum(id) FROM {name}".format(name=name)) == "4950\n"
|
|
|
|
|
2020-04-20 11:15:06 +00:00
|
|
|
with pytest.raises(QueryRuntimeException):
|
|
|
|
node1.query(
|
|
|
|
"ALTER TABLE {name} MODIFY COLUMN id UInt32 CODEC(Delta, LZ4)".format(
|
|
|
|
name=name
|
|
|
|
)
|
|
|
|
)
|
2022-03-22 16:39:58 +00:00
|
|
|
|
2020-04-20 11:15:06 +00:00
|
|
|
node1.query(
|
|
|
|
"ALTER TABLE {name} MODIFY COLUMN id UInt64 DEFAULT 3 CODEC(Delta, LZ4)".format(
|
|
|
|
name=name
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
|
|
|
)
|
2020-04-20 11:15:06 +00:00
|
|
|
|
2020-06-22 11:03:01 +00:00
|
|
|
node1.query("INSERT INTO {name} (value) VALUES (1)".format(name=name))
|
|
|
|
|
|
|
|
assert node1.query("SELECT sum(id) FROM {name}".format(name=name)) == "4953\n"
|
|
|
|
|
2020-04-20 11:15:06 +00:00
|
|
|
with pytest.raises(QueryRuntimeException):
|
|
|
|
node1.query(
|
|
|
|
"ALTER TABLE {name} MODIFY COLUMN id UInt64 ALIAS 3 CODEC(Delta, LZ4)".format(
|
|
|
|
name=name
|
|
|
|
)
|
2020-06-19 10:53:20 +00:00
|
|
|
)
|
2022-03-22 16:39:58 +00:00
|
|
|
|
2020-06-19 10:53:20 +00:00
|
|
|
node1.query(
|
|
|
|
"ALTER TABLE {name} MODIFY COLUMN id UInt64 MATERIALIZED 3 CODEC(Delta, LZ4)".format(
|
|
|
|
name=name
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
|
|
|
)
|
2020-04-20 11:15:06 +00:00
|
|
|
|
2020-06-22 11:03:01 +00:00
|
|
|
node1.query("INSERT INTO {name} (value) VALUES (1)".format(name=name))
|
|
|
|
|
|
|
|
assert node1.query("SELECT sum(id) FROM {name}".format(name=name)) == "4956\n"
|
2020-04-20 11:15:06 +00:00
|
|
|
node1.query("ALTER TABLE {name} MODIFY COLUMN id UInt64".format(name=name))
|
|
|
|
|
|
|
|
with pytest.raises(QueryRuntimeException):
|
|
|
|
node1.query("ALTER TABLE {name} MODIFY COLUMN id Int64".format(name=name))
|
|
|
|
|
|
|
|
finally:
|
|
|
|
node1.query("DROP TABLE IF EXISTS {name}".format(name=name))
|
|
|
|
|
|
|
|
|
|
|
|
def test_alter_codec_index(started_cluster):
|
|
|
|
try:
|
|
|
|
name = "test_alter_codec_index"
|
|
|
|
node1.query(
|
|
|
|
"""
|
2020-06-22 11:03:01 +00:00
|
|
|
CREATE TABLE {name} (`id` UInt64, value UInt64, INDEX id_index id TYPE minmax GRANULARITY 1) Engine=MergeTree() ORDER BY tuple()
|
2020-04-20 11:15:06 +00:00
|
|
|
""".format(
|
|
|
|
name=name
|
|
|
|
)
|
2020-06-22 11:03:01 +00:00
|
|
|
)
|
2022-03-22 16:39:58 +00:00
|
|
|
|
2020-06-22 11:03:01 +00:00
|
|
|
node1.query(
|
|
|
|
"INSERT INTO {name} SELECT number, number * number from numbers(100)".format(
|
|
|
|
name=name
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2020-04-20 11:15:06 +00:00
|
|
|
node1.query(
|
|
|
|
"ALTER TABLE {name} MODIFY COLUMN id UInt64 CODEC(NONE)".format(name=name)
|
|
|
|
)
|
|
|
|
node1.query(
|
|
|
|
"ALTER TABLE {name} MODIFY COLUMN id UInt64 CODEC(Delta, LZ4)".format(
|
|
|
|
name=name
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
|
|
|
)
|
2020-04-20 11:15:06 +00:00
|
|
|
|
|
|
|
with pytest.raises(QueryRuntimeException):
|
|
|
|
node1.query(
|
|
|
|
"ALTER TABLE {name} MODIFY COLUMN id UInt32 CODEC(Delta, LZ4)".format(
|
|
|
|
name=name
|
|
|
|
)
|
|
|
|
)
|
2022-03-22 16:39:58 +00:00
|
|
|
|
2020-04-20 11:15:06 +00:00
|
|
|
node1.query(
|
|
|
|
"ALTER TABLE {name} MODIFY COLUMN id UInt64 DEFAULT 3 CODEC(Delta, LZ4)".format(
|
|
|
|
name=name
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
|
|
|
)
|
2020-04-20 11:15:06 +00:00
|
|
|
|
2020-06-22 11:03:01 +00:00
|
|
|
node1.query("INSERT INTO {name} (value) VALUES (1)".format(name=name))
|
|
|
|
|
|
|
|
assert node1.query("SELECT sum(id) FROM {name}".format(name=name)) == "4953\n"
|
|
|
|
|
2020-04-20 11:15:06 +00:00
|
|
|
with pytest.raises(QueryRuntimeException):
|
|
|
|
node1.query(
|
|
|
|
"ALTER TABLE {name} MODIFY COLUMN id UInt64 ALIAS 3 CODEC(Delta, LZ4)".format(
|
|
|
|
name=name
|
|
|
|
)
|
2020-06-19 10:53:20 +00:00
|
|
|
)
|
2022-03-22 16:39:58 +00:00
|
|
|
|
2020-06-19 10:53:20 +00:00
|
|
|
node1.query(
|
|
|
|
"ALTER TABLE {name} MODIFY COLUMN id UInt64 MATERIALIZED 3 CODEC(Delta, LZ4)".format(
|
|
|
|
name=name
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
|
|
|
)
|
2020-04-20 11:15:06 +00:00
|
|
|
|
2020-06-22 11:03:01 +00:00
|
|
|
node1.query("INSERT INTO {name} (value) VALUES (1)".format(name=name))
|
|
|
|
|
|
|
|
assert node1.query("SELECT sum(id) FROM {name}".format(name=name)) == "4956\n"
|
|
|
|
|
2020-04-20 11:15:06 +00:00
|
|
|
node1.query("ALTER TABLE {name} MODIFY COLUMN id UInt64".format(name=name))
|
|
|
|
|
|
|
|
with pytest.raises(QueryRuntimeException):
|
|
|
|
node1.query("ALTER TABLE {name} MODIFY COLUMN id Int64".format(name=name))
|
|
|
|
|
|
|
|
finally:
|
|
|
|
node1.query("DROP TABLE IF EXISTS {name}".format(name=name))
|