diff --git a/CHANGELOG.md b/CHANGELOG.md index 97042a9..642e3f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ Change Log ========== +Unreleased +---------- +- Support LowCardinality columns in ad-hoc queries + v1.2.0 ------ - Add support for per-field compression codecs (rbelio, Chocorean) diff --git a/src/infi/clickhouse_orm/models.py b/src/infi/clickhouse_orm/models.py index 5f8b085..7965d02 100644 --- a/src/infi/clickhouse_orm/models.py +++ b/src/infi/clickhouse_orm/models.py @@ -88,6 +88,10 @@ class ModelBase(type): if db_type.startswith('Nullable'): inner_field = cls.create_ad_hoc_field(db_type[9 : -1]) return orm_fields.NullableField(inner_field) + # LowCardinality + if db_type.startswith('LowCardinality'): + inner_field = cls.create_ad_hoc_field(db_type[15 : -1]) + return orm_fields.LowCardinalityField(inner_field) # Simple fields name = db_type + 'Field' if not hasattr(orm_fields, name): diff --git a/tests/base_test_with_data.py b/tests/base_test_with_data.py index f080f85..8cbea48 100644 --- a/tests/base_test_with_data.py +++ b/tests/base_test_with_data.py @@ -35,7 +35,7 @@ class TestCaseWithData(unittest.TestCase): class Person(Model): first_name = StringField() - last_name = StringField() + last_name = LowCardinalityField(StringField()) birthday = DateField() height = Float32Field() passport = NullableField(UInt32Field()) diff --git a/tests/test_database.py b/tests/test_database.py index 2a50590..0433bff 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -209,3 +209,12 @@ class DatabaseTestCase(TestCaseWithData): # Remove the setting and see that now it works self.database.add_setting('max_columns_to_read', None) list(self.database.select('SELECT * from system.tables')) + + def test_create_ad_hoc_field(self): + # Tests that create_ad_hoc_field works for all column types in the database + from infi.clickhouse_orm.models import ModelBase + query = "SELECT DISTINCT type FROM system.columns" + for row in self.database.select(query): + if row.type in ('IPv4', 'IPv6'): + continue # unsupported yet + ModelBase.create_ad_hoc_field(row.type)