# Path: src/infi/clickhouse_orm/utils.py
# 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)
# 
# def get_subclass_names(locals, base_class):
#     from inspect import isclass
#     return [c.__name__ for c in locals.values() if isclass(c) and issubclass(c, base_class)]


import logging
from .utils import comma_join, get_subclass_names
            from infi.clickhouse_orm.database import DatabaseException
        from .models import ModelBase
        self.partition_key = partition_key if partition_key else ('toYYYYMM(`%s`)' % date_col,)
        self.primary_key = primary_key

        self.order_by = order_by
        self.sampling_expr = sampling_expr
        self.index_granularity = index_granularity
        self.replica_table_path = replica_table_path
        self.replica_name = replica_name

    # I changed field name for new reality and syntax
    @property
    def key_cols(self):
        logger.warning('`key_cols` attribute is deprecated and may be removed in future. Use `order_by` attribute instead')
        return self.order_by

    @key_cols.setter
    def key_cols(self, value):
        logger.warning('`key_cols` attribute is deprecated and may be removed in future. Use `order_by` attribute instead')
        self.order_by = value

    def create_table_sql(self, db):
        name = self.__class__.__name__
        if self.replica_name:
            name = 'Replicated' + name

        # In ClickHouse 1.1.54310 custom partitioning key was introduced
        # https://clickhouse.tech/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)" \

# Path: src/infi/clickhouse_orm/utils.py
# 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)
# 
# def get_subclass_names(locals, base_class):
#     from inspect import isclass
#     return [c.__name__ for c in locals.values() if isclass(c) and issubclass(c, base_class)]


# Path: src/infi/clickhouse_orm/engines.py
import logging
from .utils import comma_join, get_subclass_names
            from infi.clickhouse_orm.database import DatabaseException
        from .models import ModelBase

        self.partition_key = partition_key if partition_key else ('toYYYYMM(`%s`)' % date_col,)
        self.primary_key = primary_key

        self.order_by = order_by
        self.sampling_expr = sampling_expr
        self.index_granularity = index_granularity
        self.replica_table_path = replica_table_path
        self.replica_name = replica_name

    # I changed field name for new reality and syntax
    @property
    def key_cols(self):
        logger.warning('`key_cols` attribute is deprecated and may be removed in future. Use `order_by` attribute instead')
        return self.order_by

    @key_cols.setter
    def key_cols(self, value):
        logger.warning('`key_cols` attribute is deprecated and may be removed in future. Use `order_by` attribute instead')
        self.order_by = value

    def create_table_sql(self, db):
        name = self.__class__.__name__
        if self.replica_name:
            name = 'Replicated' + name

        # In ClickHouse 1.1.54310 custom partitioning key was introduced
        # https://clickhouse.tech/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)" \

                            % (comma_join(self.partition_key, stringify=True),