Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interval columns #16

Merged
merged 7 commits into from
Jan 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)])