mirror of
https://github.com/carrotquest/django-clickhouse.git
synced 2024-11-25 02:23:45 +03:00
Fixed bug with batched insert_tuple
This commit is contained in:
parent
ab2fe24f74
commit
2798cbb602
|
@ -97,7 +97,8 @@ class Database(InfiDatabase):
|
|||
buf = BytesIO()
|
||||
query = 'INSERT INTO `%s`.`%s` (%s) FORMAT TabSeparated\n' \
|
||||
% (self.db_name, model_class.table_name(), fields_list)
|
||||
buf.write(query.encode('utf-8'))
|
||||
query_enc = query.encode('utf-8')
|
||||
buf.write(query_enc)
|
||||
buf.write(tuple_to_csv(first_tuple).encode('utf-8'))
|
||||
|
||||
# Collect lines in batches of batch_size
|
||||
|
@ -112,6 +113,7 @@ class Database(InfiDatabase):
|
|||
yield buf.getvalue()
|
||||
# Start a new batch
|
||||
buf = BytesIO()
|
||||
buf.write(query_enc)
|
||||
lines = 0
|
||||
|
||||
# Return any remaining lines in partial batch
|
||||
|
|
|
@ -31,6 +31,22 @@ class CollapsingMergeTreeTest(TestCase):
|
|||
'str_field': str(i)
|
||||
} for i in range(10)], [item.to_dict() for item in qs])
|
||||
|
||||
def test_insert_tuples_batch_size(self):
|
||||
tuple_class = ClickHouseTestModel.get_tuple_class()
|
||||
data = [
|
||||
tuple_class(id=i, created_date=date.today(), value=i, str_field=str(i))
|
||||
for i in range(10)
|
||||
]
|
||||
self.db.insert_tuples(ClickHouseTestModel, data, batch_size=2)
|
||||
|
||||
qs = ClickHouseTestModel.objects.order_by('id').all()
|
||||
self.assertListEqual([{
|
||||
'id': i,
|
||||
'created_date': date.today(),
|
||||
'value': i,
|
||||
'str_field': str(i)
|
||||
} for i in range(10)], [item.to_dict() for item in qs])
|
||||
|
||||
def test_insert_tuples_special_characters(self):
|
||||
tuple_class = ClickHouseTestModel.get_tuple_class()
|
||||
data = [tuple_class(id=1, created_date=date.today(), value=1, str_field='\t')]
|
||||
|
|
Loading…
Reference in New Issue
Block a user