NullableField of ArrayField

This commit is contained in:
Dzianis Sivets 2017-06-16 20:27:05 +03:00
parent 1b0ea035b8
commit 9b7e7a179e
2 changed files with 19 additions and 6 deletions

View File

@ -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):

View File

@ -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',))