allow expressions in MergeTree params

This commit is contained in:
Itai Shirav 2020-05-16 12:15:01 +03:00
parent ce784d7af7
commit 9697157d6b
3 changed files with 11 additions and 7 deletions

View File

@ -77,11 +77,12 @@ class MergeTree(Engine):
# https://clickhouse.yandex/docs/en/table_engines/custom_partitioning_key/
# Let's check version and use new syntax if available
if db.server_version >= (1, 1, 54310):
partition_sql = "PARTITION BY %s ORDER BY %s" \
% ('(%s)' % comma_join(self.partition_key), '(%s)' % comma_join(self.order_by))
partition_sql = "PARTITION BY (%s) ORDER BY (%s)" \
% (comma_join(self.partition_key, stringify=True),
comma_join(self.order_by, stringify=True))
if self.primary_key:
partition_sql += " PRIMARY KEY (%s)" % comma_join(self.primary_key)
partition_sql += " PRIMARY KEY (%s)" % comma_join(self.primary_key, stringify=True)
if self.sampling_expr:
partition_sql += " SAMPLE BY %s" % self.sampling_expr
@ -113,7 +114,7 @@ class MergeTree(Engine):
params.append(self.date_col)
if self.sampling_expr:
params.append(self.sampling_expr)
params.append('(%s)' % comma_join(self.order_by))
params.append('(%s)' % comma_join(self.order_by, stringify=True))
params.append(str(self.index_granularity))
return params

View File

@ -68,7 +68,7 @@ def parametric(func):
def inner(*args, **kwargs):
f = func(*args, **kwargs)
# Append the parameter to the function name
parameters_str = comma_join([str(p) for p in parameters])
parameters_str = comma_join(parameters, stringify=True)
f.name = '%s(%s)' % (f.name, parameters_str)
return f
return inner

View File

@ -96,10 +96,13 @@ def import_submodules(package_name):
}
def comma_join(items):
def comma_join(items, stringify=False):
"""
Joins an iterable of strings with commas.
"""
if stringify:
return ', '.join(str(item) for item in items)
else:
return ', '.join(items)