mirror of
https://github.com/Infinidat/infi.clickhouse_orm.git
synced 2025-02-19 18:00:32 +03:00
Add a test for "with totals"
This commit is contained in:
parent
b27756d44b
commit
e1ef96f05b
|
@ -38,14 +38,7 @@ def unescape(value):
|
|||
def parse_tsv(line):
|
||||
if PY3 and isinstance(line, binary_type):
|
||||
line = line.decode()
|
||||
# GROUP BY WITH TOTALS modifier contains a blank line (second last row)
|
||||
# separating normal result from the totals (last row)
|
||||
# Let's skip the blank line
|
||||
try:
|
||||
last_element = line[-1]
|
||||
except IndexError:
|
||||
return
|
||||
if last_element == '\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