Skip to content

Commit

Permalink
Merge pull request #89 from azat-archive/SimpleAggregateFunction
Browse files Browse the repository at this point in the history
Simple aggregate function
  • Loading branch information
xzkostyan committed Jun 14, 2019
2 parents 73807b0 + 5f3dfff commit 5334f0d
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 5 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
env:
- VERSION=19.8.3.8 # SimpleAggregateFunction
- VERSION=19.3.3
- VERSION=18.12.17
- VERSION=18.12.13
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Access for processed rows, bytes and elapsed time of the last executed query.
- Allow to insert `datetime` into Date column. Pull request [#75](https://github.com/mymarilyn/clickhouse-driver/pull/75) by [gle4er](https://github.com/gle4er).
- 'max_partitions_per_insert_block' setting. Pull request [#85](https://github.com/mymarilyn/clickhouse-driver/pull/85) by [mhsekhavat](https://github.com/mhsekhavat).
- SimpleAggregateFunction type.

### Fixed
- Fallback for user name if it's not defined. Pull request [#87](https://github.com/mymarilyn/clickhouse-driver/pull/87) by [wawaka](https://github.com/wawaka).
Expand Down
7 changes: 7 additions & 0 deletions clickhouse_driver/columns/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
from .nothingcolumn import NothingColumn
from .nullcolumn import NullColumn
from .nullablecolumn import create_nullable_column
from .simpleaggregatefunctioncolumn import (
create_simple_aggregate_function_column
)
from .stringcolumn import create_string_column
from .uuidcolumn import UUIDColumn
from .intervalcolumn import (
Expand Down Expand Up @@ -62,6 +65,10 @@ def create_column_with_options(x):
elif spec.startswith('LowCardinality'):
return create_low_cardinality_column(spec, create_column_with_options)

elif spec.startswith('SimpleAggregateFunction'):
return create_simple_aggregate_function_column(
spec, create_column_with_options)

else:
try:
cls = column_by_type[spec]
Expand Down
7 changes: 7 additions & 0 deletions clickhouse_driver/columns/simpleaggregatefunctioncolumn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@


def create_simple_aggregate_function_column(spec, column_by_spec_getter):
# SimpleAggregateFunction(Func, Type) -> Type
inner = spec[24:-1].split(',')[1].strip()
nested = column_by_spec_getter(inner)
return nested
5 changes: 0 additions & 5 deletions tests/columns/test_nullable.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@


class NullableTestCase(BaseTestCase):
def entuple(self, lst):
return tuple(
self.entuple(x) if isinstance(x, list) else x for x in lst
)

def test_simple(self):
columns = 'a Nullable(Int32)'

Expand Down
42 changes: 42 additions & 0 deletions tests/columns/test_simpleaggregatefunction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from tests.testcase import BaseTestCase
from tests.util import require_server_version


class SimpleAggregateFunctionTestCase(BaseTestCase):
@require_server_version(19, 8, 3)
def test_simple(self):
columns = 'a SimpleAggregateFunction(any, Int32)'

data = [(3, ), (2, )]
with self.create_table(columns):
self.client.execute(
'INSERT INTO test (a) VALUES', data
)

query = 'SELECT * FROM test'
inserted = self.emit_cli(query)
self.assertEqual(
inserted, '3\n2\n'
)

inserted = self.client.execute(query)
self.assertEqual(inserted, data)

@require_server_version(19, 8, 3)
def test_nullable(self):
columns = 'a SimpleAggregateFunction(any, Nullable(Int32))'

data = [(3, ), (None, ), (2, )]
with self.create_table(columns):
self.client.execute(
'INSERT INTO test (a) VALUES', data
)

query = 'SELECT * FROM test'
inserted = self.emit_cli(query)
self.assertEqual(
inserted, '3\n\\N\n2\n'
)

inserted = self.client.execute(query)
self.assertEqual(inserted, data)

0 comments on commit 5334f0d

Please sign in to comment.