-
-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #279 from adrian17/bool-type
Bool support
- Loading branch information
Showing
6 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,7 @@ Features | |
* Enum8/16 | ||
* Array(T) | ||
* Nullable(T) | ||
* Bool | ||
* UUID | ||
* Decimal | ||
* IPv4/IPv6 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from .base import FormatColumn | ||
|
||
|
||
class BoolColumn(FormatColumn): | ||
ch_type = 'Bool' | ||
py_types = (bool, ) | ||
format = '?' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
from tests.testcase import BaseTestCase | ||
from clickhouse_driver import errors | ||
|
||
|
||
class BoolTestCase(BaseTestCase): | ||
required_server_version = (21, 12) | ||
|
||
def test_simple(self): | ||
columns = ("a Bool") | ||
|
||
data = [(1,), (0,), (True,), (False,), (None,), ("False",), ("",)] | ||
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, ( | ||
'true\n' | ||
'false\n' | ||
'true\n' | ||
'false\n' | ||
'false\n' | ||
'true\n' | ||
'false\n' | ||
) | ||
) | ||
|
||
inserted = self.client.execute(query) | ||
self.assertEqual( | ||
inserted, [ | ||
(True, ), | ||
(False, ), | ||
(True, ), | ||
(False, ), | ||
(False, ), | ||
(True, ), | ||
(False, ), | ||
] | ||
) | ||
|
||
def test_errors(self): | ||
columns = "a Bool" | ||
with self.create_table(columns): | ||
with self.assertRaises(errors.TypeMismatchError): | ||
self.client.execute( | ||
'INSERT INTO test (a) VALUES', [(1, )], | ||
types_check=True | ||
) | ||
|
||
def test_nullable(self): | ||
columns = "a Nullable(Bool)" | ||
|
||
data = [(None, ), (True, ), (False, )] | ||
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, ( | ||
'\\N\ntrue\nfalse\n' | ||
) | ||
) | ||
|
||
inserted = self.client.execute(query) | ||
self.assertEqual( | ||
inserted, [ | ||
(None, ), (True, ), (False, ), | ||
] | ||
) |