From 63e388d646b812851833f5703e1b5f98eb571951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kriszti=C3=A1n=20Sz=C5=B1cs?= Date: Tue, 9 Jan 2018 09:21:08 +0100 Subject: [PATCH 1/7] interval columns --- src/columns/intervalcolumn.py | 33 +++++++++++++++++++++++++++++++++ src/columns/service.py | 10 +++++++++- tests/columns/test_interval.py | 31 +++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/columns/intervalcolumn.py create mode 100644 tests/columns/test_interval.py diff --git a/src/columns/intervalcolumn.py b/src/columns/intervalcolumn.py new file mode 100644 index 00000000..94d31afc --- /dev/null +++ b/src/columns/intervalcolumn.py @@ -0,0 +1,33 @@ +from .intcolumn import Int64Column + + +class IntervalColumn(Int64Column): + pass + + +class IntervalDayColumn(IntervalColumn): + ch_type = 'IntervalDay' + + +class IntervalWeekColumn(IntervalColumn): + ch_type = 'IntervalWeek' + + +class IntervalMonthColumn(IntervalColumn): + ch_type = 'IntervalMonth' + + +class IntervalYearColumn(IntervalColumn): + ch_type = 'IntervalYear' + + +class IntervalHourColumn(IntervalColumn): + ch_type = 'IntervalHour' + + +class IntervalMinuteColumn(IntervalColumn): + ch_type = 'IntervalMinute' + + +class IntervalSecondColumn(IntervalColumn): + ch_type = 'IntervalSecond' diff --git a/src/columns/service.py b/src/columns/service.py index b1461cd2..76cedfae 100644 --- a/src/columns/service.py +++ b/src/columns/service.py @@ -13,13 +13,21 @@ from .nullablecolumn import create_nullable_column from .stringcolumn import String, FixedString from .uuidcolumn import UUIDColumn +from .intervalcolumn import ( + IntervalYearColumn, IntervalMonthColumn, IntervalWeekColumn, + IntervalDayColumn, IntervalHourColumn, IntervalMinuteColumn, + IntervalSecondColumn +) column_by_type = {c.ch_type: c for c in [ DateColumn, DateTimeColumn, String, Float32, Float64, Int8Column, Int16Column, Int32Column, Int64Column, UInt8Column, UInt16Column, UInt32Column, UInt64Column, - NullColumn, UUIDColumn + NullColumn, UUIDColumn, + IntervalYearColumn, IntervalMonthColumn, IntervalWeekColumn, + IntervalDayColumn, IntervalHourColumn, IntervalMinuteColumn, + IntervalSecondColumn ]} diff --git a/tests/columns/test_interval.py b/tests/columns/test_interval.py new file mode 100644 index 00000000..8767201a --- /dev/null +++ b/tests/columns/test_interval.py @@ -0,0 +1,31 @@ +from tests.testcase import BaseTestCase + + +class IntervalTestCase(BaseTestCase): + + def test_all(self): + columns = ( + 'a IntervalDay, b IntervalWeek, c IntervalMonth, d IntervalYear, ' + 'e IntervalHour, f IntervalMinute, g IntervalSecond' + ) + + data = [ + (-10, -300, -123581321, -123581321345589144, + 10, 300, 123581321, 123581321345589144) + ] + with self.create_table(columns): + self.client.execute( + 'INSERT INTO test (a, b, c, d, e, f, g, h) VALUES', data + ) + + query = 'SELECT * FROM test' + inserted = self.emit_cli(query) + self.assertEqual( + inserted, ( + '-10\t-300\t-123581321\t-123581321345589144\t' + '10\t300\t123581321\t123581321345589144\n' + ) + ) + + inserted = self.client.execute(query) + self.assertEqual(inserted, data) From 62dc6af75f7cf8b47e708d32ace18b1dd02f6db5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kriszti=C3=A1n=20Sz=C5=B1cs?= Date: Tue, 9 Jan 2018 09:40:41 +0100 Subject: [PATCH 2/7] fix interval test --- tests/columns/test_interval.py | 39 ++++++++++++++-------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/tests/columns/test_interval.py b/tests/columns/test_interval.py index 8767201a..85d5e477 100644 --- a/tests/columns/test_interval.py +++ b/tests/columns/test_interval.py @@ -4,28 +4,21 @@ class IntervalTestCase(BaseTestCase): def test_all(self): - columns = ( - 'a IntervalDay, b IntervalWeek, c IntervalMonth, d IntervalYear, ' - 'e IntervalHour, f IntervalMinute, g IntervalSecond' - ) + interval = { + 'YEAR': 1, + 'MONTH': 2, + 'WEEK': 3, + 'DAY': 4, + 'HOUR': 5, + 'MINUTE': 6, + 'SECOND': 7 + } + columns = ', '.join(['INTERVAL {} {}'.format(v, k) + for k, v in interval.items()]) + query = 'SELECT {} FROM system.numbers'.format(columns) - data = [ - (-10, -300, -123581321, -123581321345589144, - 10, 300, 123581321, 123581321345589144) - ] - with self.create_table(columns): - self.client.execute( - 'INSERT INTO test (a, b, c, d, e, f, g, h) VALUES', data - ) + cli_result = self.emit_cli(query) + self.assertEqual(cli_result, '1\t2\t3\t4\t5\t6\t7\n') - query = 'SELECT * FROM test' - inserted = self.emit_cli(query) - self.assertEqual( - inserted, ( - '-10\t-300\t-123581321\t-123581321345589144\t' - '10\t300\t123581321\t123581321345589144\n' - ) - ) - - inserted = self.client.execute(query) - self.assertEqual(inserted, data) + client_result = self.client.execute(query) + self.assertEqual(client_result, cli_result) From ce7396e8e09f425f82e5e2961485aac3a9c760ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kriszti=C3=A1n=20Sz=C5=B1cs?= Date: Tue, 9 Jan 2018 10:14:28 +0100 Subject: [PATCH 3/7] update clickhouse version --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 70539a47..289860e8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ env: - - VERSION=1.1.54276 + - VERSION=1.1.54327 language: python python: From c9345c8ebaad921094432adff8919f2865cd8815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kriszti=C3=A1n=20Sz=C5=B1cs?= Date: Tue, 9 Jan 2018 10:21:52 +0100 Subject: [PATCH 4/7] limit query from system.numbers --- tests/columns/test_interval.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/columns/test_interval.py b/tests/columns/test_interval.py index 85d5e477..f61bdd3e 100644 --- a/tests/columns/test_interval.py +++ b/tests/columns/test_interval.py @@ -15,7 +15,7 @@ def test_all(self): } columns = ', '.join(['INTERVAL {} {}'.format(v, k) for k, v in interval.items()]) - query = 'SELECT {} FROM system.numbers'.format(columns) + query = 'SELECT {} FROM system.numbers LIMIT 1'.format(columns) cli_result = self.emit_cli(query) self.assertEqual(cli_result, '1\t2\t3\t4\t5\t6\t7\n') From 92c56cdaf304f3463c07bdc57e65d8e5bc0630fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kriszti=C3=A1n=20Sz=C5=B1cs?= Date: Tue, 9 Jan 2018 10:31:46 +0100 Subject: [PATCH 5/7] maintain ordering in interval test --- tests/columns/test_interval.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/columns/test_interval.py b/tests/columns/test_interval.py index f61bdd3e..845eef22 100644 --- a/tests/columns/test_interval.py +++ b/tests/columns/test_interval.py @@ -4,17 +4,17 @@ class IntervalTestCase(BaseTestCase): def test_all(self): - interval = { - 'YEAR': 1, - 'MONTH': 2, - 'WEEK': 3, - 'DAY': 4, - 'HOUR': 5, - 'MINUTE': 6, - 'SECOND': 7 - } + interval = [ + ('YEAR', 1), + ('MONTH', 2), + ('WEEK', 3), + ('DAY', 4), + ('HOUR', 5), + ('MINUTE', 6), + ('SECOND', 7) + ] columns = ', '.join(['INTERVAL {} {}'.format(v, k) - for k, v in interval.items()]) + for k, v in interval]) query = 'SELECT {} FROM system.numbers LIMIT 1'.format(columns) cli_result = self.emit_cli(query) From 0f0a4e3a0cdd2410fc82082848858add8394adc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kriszti=C3=A1n=20Sz=C5=B1cs?= Date: Tue, 9 Jan 2018 10:35:43 +0100 Subject: [PATCH 6/7] assert client result is a tuple --- tests/columns/test_interval.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/columns/test_interval.py b/tests/columns/test_interval.py index 845eef22..b15e8250 100644 --- a/tests/columns/test_interval.py +++ b/tests/columns/test_interval.py @@ -21,4 +21,4 @@ def test_all(self): self.assertEqual(cli_result, '1\t2\t3\t4\t5\t6\t7\n') client_result = self.client.execute(query) - self.assertEqual(client_result, cli_result) + self.assertEqual(client_result, [(1, 2, 3, 4, 5, 6, 7)]) From a26add5f3c4568330408c3c5b173caf610e9f084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kriszti=C3=A1n=20Sz=C5=B1cs?= Date: Thu, 11 Jan 2018 11:00:24 +0100 Subject: [PATCH 7/7] fix review issue --- tests/columns/test_interval.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/columns/test_interval.py b/tests/columns/test_interval.py index b15e8250..40f98e23 100644 --- a/tests/columns/test_interval.py +++ b/tests/columns/test_interval.py @@ -15,7 +15,7 @@ def test_all(self): ] columns = ', '.join(['INTERVAL {} {}'.format(v, k) for k, v in interval]) - query = 'SELECT {} FROM system.numbers LIMIT 1'.format(columns) + query = 'SELECT {}'.format(columns) cli_result = self.emit_cli(query) self.assertEqual(cli_result, '1\t2\t3\t4\t5\t6\t7\n')