Skip to content

Commit

Permalink
Merge pull request #172 from Aiven-Open/kmichel-allow-null-keys
Browse files Browse the repository at this point in the history
clickhouse: fix restore with allow_nullable_key
  • Loading branch information
alanfranz authored Dec 16, 2023
2 parents 4060495 + 5cac852 commit 416d6b5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions astacus/coordinator/plugins/clickhouse/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions tests/integration/coordinator/plugins/clickhouse/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)) "
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/coordinator/plugins/clickhouse/test_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...",
Expand Down Expand Up @@ -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 ...",
Expand Down

0 comments on commit 416d6b5

Please sign in to comment.