Skip to content

Commit

Permalink
add support for arbitrary SETTINGS in CREATE TABLE
Browse files Browse the repository at this point in the history
  • Loading branch information
beda42 committed Oct 4, 2021
1 parent cd724c2 commit d7d30e8
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions clickhouse_orm/engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __init__(
replica_name=None,
partition_key=None,
primary_key=None,
settings=None,
):
assert type(order_by) in (list, tuple), "order_by must be a list or tuple"
assert date_col is None or isinstance(date_col, str), "date_col must be string if present"
Expand All @@ -47,6 +48,7 @@ def __init__(
assert (replica_table_path is None) == (
replica_name is None
), "both replica_table_path and replica_name must be specified"
assert settings is None or type(settings) is dict, 'settings must be dict'

# These values conflict with each other (old and new syntax of table engines.
# So let's control only one of them is given.
Expand All @@ -60,6 +62,7 @@ def __init__(
self.index_granularity = index_granularity
self.replica_table_path = replica_table_path
self.replica_name = replica_name
self.settings = settings

# I changed field name for new reality and syntax
@property
Expand Down Expand Up @@ -97,6 +100,9 @@ def create_table_sql(self, db):
partition_sql += " SAMPLE BY %s" % self.sampling_expr

partition_sql += " SETTINGS index_granularity=%d" % self.index_granularity
if self.settings:
settings_sql = ", ".join('%s=%s' % (key, value) for key, value in self.settings.items())
partition_sql += ", " + settings_sql

elif not self.date_col:
# Can't import it globally due to circular import
Expand Down Expand Up @@ -144,6 +150,7 @@ def __init__(
replica_name=None,
partition_key=None,
primary_key=None,
settings=None,
):
super(CollapsingMergeTree, self).__init__(
date_col,
Expand All @@ -154,6 +161,7 @@ def __init__(
replica_name,
partition_key,
primary_key,
settings=settings,
)
self.sign_col = sign_col

Expand Down

0 comments on commit d7d30e8

Please sign in to comment.