From 0a94ac98a33546c93d9bb5f4e629824f3f086349 Mon Sep 17 00:00:00 2001 From: Itai Shirav Date: Fri, 7 Feb 2020 15:30:15 +0200 Subject: [PATCH] Minor fixes --- src/infi/clickhouse_orm/models.py | 8 +++++--- src/infi/clickhouse_orm/query.py | 2 +- tests/test_database.py | 2 -- tests/test_funcs.py | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/infi/clickhouse_orm/models.py b/src/infi/clickhouse_orm/models.py index 7b4d603..9f32987 100644 --- a/src/infi/clickhouse_orm/models.py +++ b/src/infi/clickhouse_orm/models.py @@ -87,10 +87,12 @@ class ModelBase(type): if db_type.startswith('FixedString'): length = int(db_type[12 : -1]) return orm_fields.FixedStringField(length) - # Decimal + # Decimal / Decimal32 / Decimal64 / Decimal128 if db_type.startswith('Decimal'): - precision, scale = [int(n.strip()) for n in db_type[8 : -1].split(',')] - return orm_fields.DecimalField(precision, scale) + p = db_type.index('(') + args = [int(n.strip()) for n in db_type[p + 1 : -1].split(',')] + field_class = getattr(orm_fields, db_type[:p] + 'Field') + return field_class(*args) # Nullable if db_type.startswith('Nullable'): inner_field = cls.create_ad_hoc_field(db_type[9 : -1]) diff --git a/src/infi/clickhouse_orm/query.py b/src/infi/clickhouse_orm/query.py index 00a2904..c28462d 100644 --- a/src/infi/clickhouse_orm/query.py +++ b/src/infi/clickhouse_orm/query.py @@ -351,7 +351,7 @@ class QuerySet(object): - `offset_limit`: either an integer specifying the limit, or a tuple of integers (offset, limit). - `fields`: the field names to use in the clause. """ - if isinstance(offset_limit, six.integer_types): + if isinstance(offset_limit, int): # Single limit offset_limit = (0, offset_limit) offset = offset_limit[0] diff --git a/tests/test_database.py b/tests/test_database.py index 0433bff..e6aa435 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -215,6 +215,4 @@ class DatabaseTestCase(TestCaseWithData): 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) diff --git a/tests/test_funcs.py b/tests/test_funcs.py index 5068409..0cd5a24 100644 --- a/tests/test_funcs.py +++ b/tests/test_funcs.py @@ -307,7 +307,7 @@ class FuncsTestCase(TestCaseWithData): try: self._test_func(F.base64Decode(F.base64Encode('Hello')), 'Hello') self._test_func(F.tryBase64Decode(F.base64Encode('Hello')), 'Hello') - self._test_func(F.tryBase64Decode('zzz'), None) + self._test_func(F.tryBase64Decode(':-)'), None) except ServerError as e: # ClickHouse version that doesn't support these functions raise unittest.SkipTest(e.message)