2024-10-03 13:09:19 +00:00
|
|
|
import pytest
|
2024-10-03 13:26:26 +00:00
|
|
|
|
2024-10-03 13:09:19 +00:00
|
|
|
from helpers.cluster import ClickHouseCluster
|
|
|
|
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
|
|
|
|
|
|
|
node = cluster.add_instance("node1", with_zookeeper=True)
|
2024-10-03 13:26:26 +00:00
|
|
|
node_with_compatibility = cluster.add_instance(
|
|
|
|
"node2", with_zookeeper=True, user_configs=["configs/compatibility.xml"]
|
|
|
|
)
|
2024-10-03 13:39:58 +00:00
|
|
|
node_with_compatibility_and_mt_setings = cluster.add_instance(
|
|
|
|
"node3",
|
|
|
|
with_zookeeper=True,
|
|
|
|
main_configs=["configs/mt_settings.xml"],
|
|
|
|
user_configs=["configs/compatibility.xml"],
|
|
|
|
)
|
2024-10-03 13:09:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def started_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
|
|
|
|
yield cluster
|
|
|
|
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
2024-10-03 13:26:26 +00:00
|
|
|
|
2024-10-03 13:09:19 +00:00
|
|
|
def test_check_projections_compatibility(started_cluster):
|
|
|
|
create_with_invalid_projection = """
|
|
|
|
CREATE TABLE tp (type Int32, eventcnt UInt64, PROJECTION p (select sum(eventcnt), type group by type))
|
|
|
|
engine = {} order by type;
|
|
|
|
"""
|
|
|
|
|
|
|
|
create_no_projection = """
|
|
|
|
CREATE TABLE tp (type Int32, eventcnt UInt64)
|
|
|
|
engine = {} order by type;
|
|
|
|
"""
|
|
|
|
|
|
|
|
alter_add_projection = """
|
|
|
|
ALTER TABLE tp ADD PROJECTION p (select sum(eventcnt), type group by type);
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Create with invalid projection is not supported by default
|
|
|
|
|
2024-10-03 13:26:26 +00:00
|
|
|
assert "Projection is fully supported" in node.query_and_get_error(
|
|
|
|
create_with_invalid_projection.format("ReplacingMergeTree")
|
|
|
|
)
|
|
|
|
assert "Projection is fully supported" in node.query_and_get_error(
|
|
|
|
create_with_invalid_projection.format(
|
|
|
|
"ReplicatedReplacingMergeTree('/tables/tp', '0')"
|
|
|
|
)
|
|
|
|
)
|
2024-10-03 13:09:19 +00:00
|
|
|
|
|
|
|
# Adding invalid projection is not supported by default
|
|
|
|
|
|
|
|
node.query(create_no_projection.format("ReplacingMergeTree"))
|
2024-10-03 13:26:26 +00:00
|
|
|
assert "Projection is fully supported" in node.query_and_get_error(
|
|
|
|
alter_add_projection
|
|
|
|
)
|
2024-10-03 13:09:19 +00:00
|
|
|
node.query("drop table tp;")
|
|
|
|
|
2024-10-03 13:26:26 +00:00
|
|
|
node.query(
|
|
|
|
create_no_projection.format("ReplicatedReplacingMergeTree('/tables/tp', '0')")
|
|
|
|
)
|
|
|
|
assert "Projection is fully supported" in node.query_and_get_error(
|
|
|
|
alter_add_projection
|
|
|
|
)
|
2024-10-03 13:09:19 +00:00
|
|
|
node.query("drop table tp;")
|
|
|
|
|
|
|
|
# Create with invalid projection is supported with compatibility
|
|
|
|
|
2024-10-03 13:26:26 +00:00
|
|
|
node_with_compatibility.query(
|
|
|
|
create_with_invalid_projection.format("ReplacingMergeTree")
|
|
|
|
)
|
2024-10-03 13:09:19 +00:00
|
|
|
node_with_compatibility.query("drop table tp;")
|
2024-10-03 13:26:26 +00:00
|
|
|
node_with_compatibility.query(
|
|
|
|
create_with_invalid_projection.format(
|
|
|
|
"ReplicatedReplacingMergeTree('/tables/tp2', '0')"
|
|
|
|
)
|
|
|
|
)
|
2024-10-03 13:09:19 +00:00
|
|
|
node_with_compatibility.query("drop table tp;")
|
|
|
|
|
|
|
|
# Adding invalid projection is supported with compatibility
|
|
|
|
|
|
|
|
node_with_compatibility.query(create_no_projection.format("ReplacingMergeTree"))
|
|
|
|
node_with_compatibility.query(alter_add_projection)
|
|
|
|
node_with_compatibility.query("drop table tp;")
|
|
|
|
|
2024-10-03 13:26:26 +00:00
|
|
|
node_with_compatibility.query(
|
|
|
|
create_no_projection.format("ReplicatedReplacingMergeTree('/tables/tp3', '0')")
|
|
|
|
)
|
2024-10-03 13:09:19 +00:00
|
|
|
node_with_compatibility.query(alter_add_projection)
|
|
|
|
node_with_compatibility.query("drop table tp;")
|
2024-10-03 13:32:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_config_overrides_compatibility(started_cluster):
|
|
|
|
create_with_invalid_projection = """
|
|
|
|
CREATE TABLE tp (type Int32, eventcnt UInt64, PROJECTION p (select sum(eventcnt), type group by type))
|
|
|
|
engine = {} order by type;
|
|
|
|
"""
|
|
|
|
|
2024-10-03 13:39:58 +00:00
|
|
|
assert (
|
|
|
|
"Projection is fully supported"
|
|
|
|
in node_with_compatibility_and_mt_setings.query_and_get_error(
|
|
|
|
create_with_invalid_projection.format("ReplacingMergeTree")
|
|
|
|
)
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
"Projection is fully supported"
|
|
|
|
in node_with_compatibility_and_mt_setings.query_and_get_error(
|
|
|
|
create_with_invalid_projection.format(
|
|
|
|
"ReplicatedReplacingMergeTree('/tables/tp', '0')"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|