Support LowCardinality columns in ad-hoc queries

This commit is contained in:
Itai Shirav 2019-12-12 22:09:27 +02:00
parent 4749918014
commit 4848c7f813
4 changed files with 18 additions and 1 deletions

View File

@ -1,6 +1,10 @@
Change Log Change Log
========== ==========
Unreleased
----------
- Support LowCardinality columns in ad-hoc queries
v1.2.0 v1.2.0
------ ------
- Add support for per-field compression codecs (rbelio, Chocorean) - Add support for per-field compression codecs (rbelio, Chocorean)

View File

@ -88,6 +88,10 @@ class ModelBase(type):
if db_type.startswith('Nullable'): if db_type.startswith('Nullable'):
inner_field = cls.create_ad_hoc_field(db_type[9 : -1]) inner_field = cls.create_ad_hoc_field(db_type[9 : -1])
return orm_fields.NullableField(inner_field) 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 # Simple fields
name = db_type + 'Field' name = db_type + 'Field'
if not hasattr(orm_fields, name): if not hasattr(orm_fields, name):

View File

@ -35,7 +35,7 @@ class TestCaseWithData(unittest.TestCase):
class Person(Model): class Person(Model):
first_name = StringField() first_name = StringField()
last_name = StringField() last_name = LowCardinalityField(StringField())
birthday = DateField() birthday = DateField()
height = Float32Field() height = Float32Field()
passport = NullableField(UInt32Field()) passport = NullableField(UInt32Field())

View File

@ -209,3 +209,12 @@ class DatabaseTestCase(TestCaseWithData):
# Remove the setting and see that now it works # Remove the setting and see that now it works
self.database.add_setting('max_columns_to_read', None) self.database.add_setting('max_columns_to_read', None)
list(self.database.select('SELECT * from system.tables')) 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)