From 9b7e7a179e1bdfc7115efb4577f696d17d0859bf Mon Sep 17 00:00:00 2001 From: Dzianis Sivets <12rvt2008@gmail.com> Date: Fri, 16 Jun 2017 20:27:05 +0300 Subject: [PATCH] NullableField of ArrayField --- src/infi/clickhouse_orm/fields.py | 7 +++++-- tests/test_nullable_fields.py | 18 ++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/infi/clickhouse_orm/fields.py b/src/infi/clickhouse_orm/fields.py index 61f5e00..6c06d44 100644 --- a/src/infi/clickhouse_orm/fields.py +++ b/src/infi/clickhouse_orm/fields.py @@ -368,9 +368,12 @@ class NullableField(Field): class_default = None def __init__(self, inner_field, default=None, alias=None, materialized=None, - extra_null_values=set()): + extra_null_values=None): self.inner_field = inner_field - self._extra_null_values = extra_null_values + if extra_null_values is None: + self._extra_null_values = list() + else: + self._extra_null_values = extra_null_values super(NullableField, self).__init__(default, alias, materialized) def to_python(self, value, timezone_in_use): diff --git a/tests/test_nullable_fields.py b/tests/test_nullable_fields.py index 54c96a3..7dcab92 100644 --- a/tests/test_nullable_fields.py +++ b/tests/test_nullable_fields.py @@ -76,13 +76,17 @@ class NullableFieldsTest(unittest.TestCase): dt = date(1970, 1, 1) self.database.insert([ ModelWithNullable(date_field='2016-08-30', - null_str='', null_int=42, null_date=dt), + null_str='', null_int=42, null_date=dt, + null_array=None), ModelWithNullable(date_field='2016-08-30', - null_str='nothing', null_int=None, null_date=None), + null_str='nothing', null_int=None, null_date=None, + null_array=[1, 2, 3]), ModelWithNullable(date_field='2016-08-31', - null_str=None, null_int=42, null_date=dt), + null_str=None, null_int=42, null_date=dt, + null_array=[]), ModelWithNullable(date_field='2016-08-31', - null_str=None, null_int=None, null_date=None) + null_str=None, null_int=None, null_date=None, + null_array=[3, 2, 1]) ]) def _assert_sample_data(self, results): @@ -101,6 +105,11 @@ class NullableFieldsTest(unittest.TestCase): self.assertIsNone(results[3].null_str) self.assertIsNone(results[3].null_date) + self.assertIsNone(results[0].null_array) + self.assertEquals(results[1].null_array, [1, 2, 3]) + self.assertEquals(results[2].null_array, []) + self.assertEquals(results[3].null_array, [3, 2, 1]) + def test_insert_and_select(self): self._insert_sample_data() query = 'SELECT * from $table ORDER BY date_field' @@ -120,5 +129,6 @@ class ModelWithNullable(Model): null_str = NullableField(StringField(), extra_null_values={''}) null_int = NullableField(Int32Field()) null_date = NullableField(DateField()) + null_array = NullableField(ArrayField(Int32Field())) engine = MergeTree('date_field', ('date_field',))