File: test_simpleaggregatefunction.py

package info (click to toggle)
python-clickhouse-driver 0.2.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,516 kB
  • sloc: python: 10,950; pascal: 42; makefile: 31; sh: 3
file content (111 lines) | stat: -rw-r--r-- 3,197 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
from enum import IntEnum

from tests.testcase import BaseTestCase


class SimpleAggregateFunctionTestCase(BaseTestCase):
    required_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)

    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)

    def test_simple_agg_function(self):
        class A(IntEnum):
            hello = -1
            world = 2

        columns = "a SimpleAggregateFunction(anyLast, " \
                  "Enum8('hello' = -1, 'world' = 2))"

        data = [(A.hello,), (A.world,), (-1,), (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, (
                    'hello\n'
                    'world\n'
                    'hello\n'
                    'world\n'
                )
            )

            inserted = self.client.execute(query)
            self.assertEqual(
                inserted, [
                    ('hello',), ('world',),
                    ('hello',), ('world',)
                ]
            )

    def test_simple_agg_function_nullable(self):
        class A(IntEnum):
            hello = -1
            world = 2

        columns = "a SimpleAggregateFunction(anyLast, " \
                  "Nullable(Enum8('hello' = -1, 'world' = 2)))"

        data = [(A.hello,), (A.world,), (None,), (-1,), (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, (
                    'hello\n'
                    'world\n'
                    '\\N\n'
                    'hello\n'
                    'world\n'
                )
            )

            inserted = self.client.execute(query)
            self.assertEqual(
                inserted, [
                    ('hello',), ('world',),
                    (None, ),
                    ('hello',), ('world',)
                ]
            )