mirror of
https://github.com/Infinidat/infi.clickhouse_orm.git
synced 2024-11-25 02:03:46 +03:00
Drying get_sql methods
Some updates to Nullable documentation
This commit is contained in:
parent
3ba44608f3
commit
bcc4c29d10
|
@ -121,8 +121,7 @@ db.select('SELECT * FROM $db.event', model_class=Event)
|
||||||
|
|
||||||
Working with nullable fields
|
Working with nullable fields
|
||||||
----------------------------
|
----------------------------
|
||||||
From [some time](https://github.com/yandex/ClickHouse/pull/70) ClickHouse provides a NULL value support.
|
[ClickHouse provides a NULL value support](https://clickhouse.yandex/docs/en/data_types/nullable).
|
||||||
Also see some information [here](https://github.com/yandex/ClickHouse/blob/master/dbms/tests/queries/0_stateless/00395_nullable.sql).
|
|
||||||
|
|
||||||
Wrapping another field in a `NullableField` makes it possible to assign `None` to that field. For example:
|
Wrapping another field in a `NullableField` makes it possible to assign `None` to that field. For example:
|
||||||
|
|
||||||
|
@ -148,6 +147,8 @@ to `None`.
|
||||||
|
|
||||||
NOTE: `ArrayField` of `NullableField` is not supported. Also `EnumField` cannot be nullable.
|
NOTE: `ArrayField` of `NullableField` is not supported. Also `EnumField` cannot be nullable.
|
||||||
|
|
||||||
|
NOTE: Using `Nullable` almost always negatively affects performance, keep this in mind when designing your databases.
|
||||||
|
|
||||||
Working with field compression codecs
|
Working with field compression codecs
|
||||||
-------------------------------------
|
-------------------------------------
|
||||||
Besides default data compression, defined in server settings, per-field specification is also available.
|
Besides default data compression, defined in server settings, per-field specification is also available.
|
||||||
|
|
|
@ -76,15 +76,20 @@ class Field(object):
|
||||||
'''
|
'''
|
||||||
sql = self.db_type
|
sql = self.db_type
|
||||||
if with_default_expression:
|
if with_default_expression:
|
||||||
if self.alias:
|
sql += self._extra_params(db)
|
||||||
sql += ' ALIAS %s' % self.alias
|
return sql
|
||||||
elif self.materialized:
|
|
||||||
sql += ' MATERIALIZED %s' % self.materialized
|
def _extra_params(self, db):
|
||||||
else:
|
sql = ''
|
||||||
default = self.to_db_string(self.default)
|
if self.alias:
|
||||||
sql += ' DEFAULT %s' % default
|
sql += ' ALIAS %s' % self.alias
|
||||||
if self.codec and db and db.has_codec_support:
|
elif self.materialized:
|
||||||
sql+= ' CODEC(%s)' % self.codec
|
sql += ' MATERIALIZED %s' % self.materialized
|
||||||
|
elif self.default:
|
||||||
|
default = self.to_db_string(self.default)
|
||||||
|
sql += ' DEFAULT %s' % default
|
||||||
|
if self.codec and db and db.has_codec_support:
|
||||||
|
sql += ' CODEC(%s)' % self.codec
|
||||||
return sql
|
return sql
|
||||||
|
|
||||||
def isinstance(self, types):
|
def isinstance(self, types):
|
||||||
|
@ -511,15 +516,7 @@ class NullableField(Field):
|
||||||
def get_sql(self, with_default_expression=True, db=None):
|
def get_sql(self, with_default_expression=True, db=None):
|
||||||
sql = 'Nullable(%s)' % self.inner_field.get_sql(with_default_expression=False, db=db)
|
sql = 'Nullable(%s)' % self.inner_field.get_sql(with_default_expression=False, db=db)
|
||||||
if with_default_expression:
|
if with_default_expression:
|
||||||
if self.alias:
|
sql += self._extra_params(db)
|
||||||
sql += ' ALIAS %s' % self.alias
|
|
||||||
elif self.materialized:
|
|
||||||
sql += ' MATERIALIZED %s' % self.materialized
|
|
||||||
elif self.default:
|
|
||||||
default = self.to_db_string(self.default)
|
|
||||||
sql += ' DEFAULT %s' % default
|
|
||||||
if self.codec and db and db.has_codec_support:
|
|
||||||
sql+= ' CODEC(%s)' % self.codec
|
|
||||||
return sql
|
return sql
|
||||||
|
|
||||||
|
|
||||||
|
@ -549,13 +546,5 @@ class LowCardinalityField(Field):
|
||||||
sql = self.inner_field.get_sql(with_default_expression=False)
|
sql = self.inner_field.get_sql(with_default_expression=False)
|
||||||
logger.warning('LowCardinalityField not supported on clickhouse-server version < 19.0 using {} as fallback'.format(self.inner_field.__class__.__name__))
|
logger.warning('LowCardinalityField not supported on clickhouse-server version < 19.0 using {} as fallback'.format(self.inner_field.__class__.__name__))
|
||||||
if with_default_expression:
|
if with_default_expression:
|
||||||
if self.alias:
|
sql += self._extra_params(db)
|
||||||
sql += ' ALIAS %s' % self.alias
|
|
||||||
elif self.materialized:
|
|
||||||
sql += ' MATERIALIZED %s' % self.materialized
|
|
||||||
elif self.default:
|
|
||||||
default = self.to_db_string(self.default)
|
|
||||||
sql += ' DEFAULT %s' % default
|
|
||||||
if self.codec and db and db.has_codec_support:
|
|
||||||
sql+= ' CODEC(%s)' % self.codec
|
|
||||||
return sql
|
return sql
|
||||||
|
|
Loading…
Reference in New Issue
Block a user