diff --git a/astacus/coordinator/plugins/clickhouse/steps.py b/astacus/coordinator/plugins/clickhouse/steps.py index 8a233b71..0d2d414e 100644 --- a/astacus/coordinator/plugins/clickhouse/steps.py +++ b/astacus/coordinator/plugins/clickhouse/steps.py @@ -516,6 +516,7 @@ def _create_dbs(client: ClickHouseClient) -> Iterator[Awaitable[None]]: b"SET allow_experimental_object_type=true", b"SET allow_suspicious_codecs=true", b"SET allow_suspicious_low_cardinality_types=true", + b"SET merge_tree_allow_nullable_key=true", # If a table was created with flatten_nested=0, we must be careful to not re-create the # table with flatten_nested=1, since this would recreate the table with a different schema. # If a table was created with flatten_nested=1, the query in system.tables.create_table_query diff --git a/tests/integration/coordinator/plugins/clickhouse/test_plugin.py b/tests/integration/coordinator/plugins/clickhouse/test_plugin.py index 2119098f..6f8d4bce 100644 --- a/tests/integration/coordinator/plugins/clickhouse/test_plugin.py +++ b/tests/integration/coordinator/plugins/clickhouse/test_plugin.py @@ -146,6 +146,12 @@ async def setup_cluster_content(clients: List[HttpClickHouseClient], use_named_c b"SETTINGS index_granularity=8192 " b"SETTINGS allow_experimental_object_type=1" ) + # test that we can re-create a table requiring custom merge tree settings. + await clients[0].execute( + b"CREATE TABLE default.with_nullable_key (thekey Nullable(UInt32), thedata String) " + b"ENGINE = ReplicatedMergeTree ORDER BY (thekey) " + b"SETTINGS allow_nullable_key=true" + ) # test that we correctly restore nested fields await clients[0].execute( b"CREATE TABLE default.nested_not_flatten (thekey UInt32, thedata Nested(a UInt32, b UInt32)) " @@ -267,6 +273,13 @@ async def test_restores_table_with_experimental_types(restored_cluster: List[Cli assert response == expected_data +@pytest.mark.asyncio +async def test_restores_table_with_nullable_key(restored_cluster: List[ClickHouseClient]) -> None: + for client in restored_cluster: + response = await client.execute(b"SELECT thekey, thedata FROM default.with_nullable_key ORDER BY thekey") + assert response == [] + + @pytest.mark.asyncio async def test_restores_table_with_nested_fields(restored_cluster: List[ClickHouseClient]) -> None: client = restored_cluster[0] diff --git a/tests/unit/coordinator/plugins/clickhouse/test_steps.py b/tests/unit/coordinator/plugins/clickhouse/test_steps.py index 765319c0..3de26df7 100644 --- a/tests/unit/coordinator/plugins/clickhouse/test_steps.py +++ b/tests/unit/coordinator/plugins/clickhouse/test_steps.py @@ -788,6 +788,7 @@ async def test_creates_all_replicated_databases_and_tables_in_manifest() -> None b"SET allow_experimental_object_type=true", b"SET allow_suspicious_codecs=true", b"SET allow_suspicious_low_cardinality_types=true", + b"SET merge_tree_allow_nullable_key=true", b"SET flatten_nested=0", b"CREATE TABLE db-one.table-uno ...", b"CREATE TABLE db-one.table-dos ...", @@ -846,6 +847,7 @@ async def test_creates_all_replicated_databases_and_tables_in_manifest_with_cust b"SET allow_experimental_object_type=true", b"SET allow_suspicious_codecs=true", b"SET allow_suspicious_low_cardinality_types=true", + b"SET merge_tree_allow_nullable_key=true", b"SET flatten_nested=0", b"CREATE TABLE db-one.table-uno ...", b"CREATE TABLE db-one.table-dos ...",