mirror of
https://github.com/Infinidat/infi.clickhouse_orm.git
synced 2025-07-24 06:49:56 +03:00
Merge branch 'pilosus-with-totals-fix' into develop
This commit is contained in:
commit
01f7fbd82c
|
@ -96,7 +96,9 @@ class Database(object):
|
|||
field_types = parse_tsv(next(lines))
|
||||
model_class = model_class or ModelBase.create_ad_hoc_model(zip(field_names, field_types))
|
||||
for line in lines:
|
||||
yield model_class.from_tsv(line, field_names, self.server_timezone, self)
|
||||
# skip blank line left by WITH TOTALS modifier
|
||||
if line:
|
||||
yield model_class.from_tsv(line, field_names, self.server_timezone, self)
|
||||
|
||||
def raw(self, query, settings=None, stream=False):
|
||||
"""
|
||||
|
|
|
@ -38,7 +38,7 @@ def unescape(value):
|
|||
def parse_tsv(line):
|
||||
if PY3 and isinstance(line, binary_type):
|
||||
line = line.decode()
|
||||
if line[-1] == '\n':
|
||||
if line and line[-1] == '\n':
|
||||
line = line[:-1]
|
||||
return [unescape(value) for value in line.split('\t')]
|
||||
|
||||
|
|
|
@ -89,6 +89,15 @@ class DatabaseTestCase(unittest.TestCase):
|
|||
self.assertEqual(results[0].get_database(), self.database)
|
||||
self.assertEqual(results[1].get_database(), self.database)
|
||||
|
||||
def test_select_with_totals(self):
|
||||
self._insert_and_check(self._sample_data(), len(data))
|
||||
query = "SELECT last_name, sum(height) as height FROM `test-db`.person GROUP BY last_name WITH TOTALS"
|
||||
results = list(self.database.select(query))
|
||||
total = sum(r.height for r in results[:-1])
|
||||
# Last line has an empty last name, and total of all heights
|
||||
self.assertFalse(results[-1].last_name)
|
||||
self.assertEquals(total, results[-1].height)
|
||||
|
||||
def test_pagination(self):
|
||||
self._insert_and_check(self._sample_data(), len(data))
|
||||
# Try different page sizes
|
||||
|
|
Loading…
Reference in New Issue
Block a user