mirror of
https://github.com/Infinidat/infi.clickhouse_orm.git
synced 2024-11-22 09:06:41 +03:00
allow expressions in MergeTree params
This commit is contained in:
parent
ce784d7af7
commit
9697157d6b
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user