mirror of
https://github.com/Infinidat/infi.clickhouse_orm.git
synced 2024-11-22 00:56:34 +03:00
RAMEN-208 Support codec compression for clickhouse
This commit is contained in:
parent
1889ac6372
commit
2d3441b127
|
@ -120,7 +120,7 @@ class Database(object):
|
|||
self.server_version = self._get_server_version()
|
||||
# Versions 1.1.53981 and below don't have timezone function
|
||||
self.server_timezone = self._get_server_timezone() if self.server_version > (1, 1, 53981) else pytz.utc
|
||||
# Versions 19.1.16 and below don't support codec compression
|
||||
# Versions 19.1.16 and above support codec compression
|
||||
self.has_codec_support = self.server_version >= (19, 1, 16)
|
||||
|
||||
def create_database(self):
|
||||
|
|
|
@ -82,8 +82,8 @@ class Field(object):
|
|||
else:
|
||||
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
|
||||
if self.codec and db and db.has_codec_support:
|
||||
sql+= ' CODEC(%s)' % self.codec
|
||||
return sql
|
||||
|
||||
def isinstance(self, types):
|
||||
|
@ -395,8 +395,8 @@ class BaseEnumField(Field):
|
|||
if with_default_expression:
|
||||
default = self.to_db_string(self.default)
|
||||
sql = '%s DEFAULT %s' % (sql, default)
|
||||
if self.codec and db and db.has_codec_support:
|
||||
sql+= ' CODEC(%s)' % self.codec
|
||||
if self.codec and db and db.has_codec_support:
|
||||
sql+= ' CODEC(%s)' % self.codec
|
||||
return sql
|
||||
|
||||
@classmethod
|
||||
|
@ -453,8 +453,8 @@ class ArrayField(Field):
|
|||
return '[' + comma_join(array) + ']'
|
||||
|
||||
def get_sql(self, with_default_expression=True, db=None):
|
||||
sql = 'Array(%s)' % self.inner_field.get_sql(with_default_expression=False)
|
||||
if self.codec and db and db.has_codec_support:
|
||||
sql = 'Array(%s)' % self.inner_field.get_sql(with_default_expression=False, db=db)
|
||||
if with_default_expression and self.codec and db and db.has_codec_support:
|
||||
sql+= ' CODEC(%s)' % self.codec
|
||||
return sql
|
||||
|
||||
|
@ -508,7 +508,7 @@ class NullableField(Field):
|
|||
return self.inner_field.to_db_string(value, quote=quote)
|
||||
|
||||
def get_sql(self, with_default_expression=True, db=None):
|
||||
sql = 'Nullable(%s)' % self.inner_field.get_sql(with_default_expression=False)
|
||||
sql = 'Nullable(%s)' % self.inner_field.get_sql(with_default_expression=False, db=db)
|
||||
if with_default_expression:
|
||||
if self.alias:
|
||||
sql += ' ALIAS %s' % self.alias
|
||||
|
@ -517,6 +517,6 @@ class NullableField(Field):
|
|||
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
|
||||
if self.codec and db and db.has_codec_support:
|
||||
sql+= ' CODEC(%s)' % self.codec
|
||||
return sql
|
||||
|
|
|
@ -2,5 +2,5 @@ from infi.clickhouse_orm import migrations
|
|||
from ..test_migrations import *
|
||||
|
||||
operations = [
|
||||
migrations.AlterTableWithBuffer(Model4_compressed)
|
||||
migrations.AlterTable(Model4_compressed),
|
||||
]
|
||||
|
|
|
@ -94,6 +94,8 @@ class MigrationsTestCase(unittest.TestCase):
|
|||
self.assertTrue(self.tableExists(AliasModel1))
|
||||
self.assertEqual(self.getTableFields(AliasModel1),
|
||||
[('date', 'Date'), ('int_field', 'Int8'), ('date_alias', 'Date'), ('int_field_plus_one', 'Int8')])
|
||||
self.database.migrate('tests.sample_migrations', 15)
|
||||
self.assertTrue(self.tableExists(Model4_compressed))
|
||||
|
||||
|
||||
# Several different models with the same table name, to simulate a table that changes over time
|
||||
|
@ -259,7 +261,7 @@ class Model4Buffer_changed(BufferModel, Model4_changed):
|
|||
|
||||
class Model4_compressed(Model):
|
||||
|
||||
date = DateField(codec='Delta(4),ZSTD')
|
||||
date = DateField()
|
||||
f3 = DateTimeField(codec='Delta,ZSTD(10)')
|
||||
f2 = StringField(codec='LZ4HC')
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user