2020-04-07 15:28:29 +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", with_zookeeper=True)
|
2020-04-07 15:28:29 +00:00
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
|
2020-04-07 15:28:29 +00:00
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def start_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
|
|
|
|
yield cluster
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
def test_table_start_without_metadata(start_cluster):
|
2022-03-22 16:39:58 +00:00
|
|
|
node1.query(
|
|
|
|
"""
|
2020-04-07 15:28:29 +00:00
|
|
|
CREATE TABLE test (date Date)
|
|
|
|
ENGINE = ReplicatedMergeTree('/clickhouse/table/test_table', '1')
|
|
|
|
ORDER BY tuple()
|
2022-03-22 16:39:58 +00:00
|
|
|
"""
|
|
|
|
)
|
2020-04-07 15:28:29 +00:00
|
|
|
|
|
|
|
node1.query("INSERT INTO test VALUES(toDate('2019-12-01'))")
|
|
|
|
|
|
|
|
assert node1.query("SELECT date FROM test") == "2019-12-01\n"
|
|
|
|
|
|
|
|
# some fake alter
|
|
|
|
node1.query("ALTER TABLE test MODIFY COLUMN date Date DEFAULT toDate('2019-10-01')")
|
|
|
|
|
|
|
|
assert node1.query("SELECT date FROM test") == "2019-12-01\n"
|
|
|
|
|
|
|
|
node1.query("DETACH TABLE test")
|
2022-03-22 16:39:58 +00:00
|
|
|
zk_cli = cluster.get_kazoo_client("zoo1")
|
2020-04-07 15:28:29 +00:00
|
|
|
|
|
|
|
# simulate update from old version
|
|
|
|
zk_cli.delete("/clickhouse/table/test_table/replicas/1/metadata")
|
|
|
|
zk_cli.delete("/clickhouse/table/test_table/replicas/1/metadata_version")
|
|
|
|
|
|
|
|
node1.query("ATTACH TABLE test")
|
|
|
|
|
|
|
|
assert node1.query("SELECT date FROM test") == "2019-12-01\n"
|
|
|
|
|
|
|
|
node1.query("ALTER TABLE test MODIFY COLUMN date Date DEFAULT toDate('2019-09-01')")
|
|
|
|
|
|
|
|
node1.query("DETACH TABLE test")
|
|
|
|
|
2020-10-02 16:54:07 +00:00
|
|
|
zk_cli.set("/clickhouse/table/test_table/replicas/1/metadata", b"")
|
2020-04-07 15:28:29 +00:00
|
|
|
|
|
|
|
node1.query("ATTACH TABLE test")
|
|
|
|
|
|
|
|
assert node1.query("SELECT date FROM test") == "2019-12-01\n"
|