Skip to content

Commit

Permalink
Swap engine/primary key clause ordering #1055
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Coetzee <[email protected]>
  • Loading branch information
Pipboyguy committed Mar 19, 2024
1 parent 45bafa7 commit 29b5a07
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
8 changes: 4 additions & 4 deletions dlt/destinations/impl/clickhouse/clickhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ def _get_table_update_sql(
if generate_alter:
return sql

# Default to 'ReplicatedMergeTree' if user didn't explicitly set a table engine hint.
# 'ReplicatedMergeTree' is the only supported engine for Clickhouse Cloud.
sql[0] = f"{sql[0]}\nENGINE = {table.get(TABLE_ENGINE_TYPE_HINT, 'replicated_merge_tree')}"

# TODO: Remove `unique` and `primary_key` default implementations.
if primary_key_list := [
self.capabilities.escape_identifier(c["name"])
Expand All @@ -222,10 +226,6 @@ def _get_table_update_sql(
else:
sql[0] += "\nPRIMARY KEY tuple()"

# Default to 'ReplicatedMergeTree' if user didn't explicitly set a table engine hint.
# 'ReplicatedMergeTree' is the only supported engine for Clickhouse Cloud.
sql[0] = f"{sql[0]}\nENGINE = {table.get(TABLE_ENGINE_TYPE_HINT, 'replicated_merge_tree')}"

return sql

def _get_column_def_sql(self, c: TColumnSchema, table_format: TTableFormat = None) -> str:
Expand Down
4 changes: 1 addition & 3 deletions dlt/destinations/impl/clickhouse/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ def __init__(
*,
credentials: ClickhouseCredentials = None,
dataset_name: str = None,
create_indexes: bool = False,
stage_name: str = None,
keep_staged_files: bool = True,
create_indexes: bool = True,
destination_name: str = None,
environment: str = None
) -> None:
Expand Down
4 changes: 1 addition & 3 deletions tests/load/clickhouse/test_clickhouse_table_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ def clickhouse_client(empty_schema: Schema) -> ClickhouseClient:
)


pytest.mark.usefixtures("empty_schema")


def test_create_table(clickhouse_client: ClickhouseClient) -> None:
statements = clickhouse_client._get_table_update_sql("event_test_table", TABLE_UPDATE, False)
assert len(statements) == 1
sql = statements[0]
print(sql)
sqlfluff.parse(sql, dialect="clickhouse")

assert sql.strip().startswith("CREATE TABLE")
Expand Down

0 comments on commit 29b5a07

Please sign in to comment.