Skip to content

Commit

Permalink
Interval columns
Browse files Browse the repository at this point in the history
  • Loading branch information
kszucs authored and xzkostyan committed Jan 11, 2018
1 parent f7b99cc commit 248b84b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
env:
- VERSION=1.1.54276
- VERSION=1.1.54327

language: python
python:
Expand Down
33 changes: 33 additions & 0 deletions src/columns/intervalcolumn.py
Original file line number Diff line number Diff line change
@@ -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'
10 changes: 9 additions & 1 deletion src/columns/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
]}


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


class IntervalTestCase(BaseTestCase):

def test_all(self):
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])
query = 'SELECT {}'.format(columns)

cli_result = self.emit_cli(query)
self.assertEqual(cli_result, '1\t2\t3\t4\t5\t6\t7\n')

client_result = self.client.execute(query)
self.assertEqual(client_result, [(1, 2, 3, 4, 5, 6, 7)])

0 comments on commit 248b84b

Please sign in to comment.