Skip to content

Commit

Permalink
add TimeFormatExtraction
Browse files Browse the repository at this point in the history
  • Loading branch information
dakra authored and xvrl committed Apr 6, 2016
1 parent 316ce6e commit 1bf68ae
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pydruid/utils/dimensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,27 @@ def build(self):
return extractor


class TimeFormatExtraction(ExtractionFunction):

extraction_type = 'timeFormat'

def __init__(self, format, locale=None, time_zone=None):
super(TimeFormatExtraction, self).__init__()
self._format = format
self._locale = locale
self._time_zone = time_zone

def build(self):
extractor = super(TimeFormatExtraction, self).build()
extractor['format'] = self._format
if self._locale:
extractor['locale'] = self._locale
if self._time_zone:
extractor['timeZone'] = self._time_zone

return extractor


class LookupExtraction(ExtractionFunction):

extraction_type = 'lookup'
Expand Down
37 changes: 37 additions & 0 deletions tests/utils/test_dimensions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pydruid.utils.dimensions import RegexExtraction
from pydruid.utils.dimensions import PartialExtraction
from pydruid.utils.dimensions import JavascriptExtraction
from pydruid.utils.dimensions import TimeFormatExtraction
from pydruid.utils.dimensions import MapLookupExtraction
from pydruid.utils.dimensions import DimensionSpec
from pydruid.utils.dimensions import build_dimension
Expand Down Expand Up @@ -103,6 +104,42 @@ def test_js_not_injective(self):
assert actual == expected


class TestTimeFormatExtraction(object):

def test_time_format_all_set(self):
ext_fn = TimeFormatExtraction('EEEE', 'en-US', 'Europe/Berlin')
actual = ext_fn.build()
expected = {
'type': 'timeFormat',
'format': 'EEEE',
'locale': 'en-US',
'timeZone': 'Europe/Berlin'
}

assert actual == expected

def test_time_format_no_timezone(self):
ext_fn = TimeFormatExtraction('EEEE', 'en-US')
actual = ext_fn.build()
expected = {
'type': 'timeFormat',
'format': 'EEEE',
'locale': 'en-US',
}

assert actual == expected

def test_time_format_only_format(self):
ext_fn = TimeFormatExtraction('EEEE')
actual = ext_fn.build()
expected = {
'type': 'timeFormat',
'format': 'EEEE',
}

assert actual == expected


class TestMapLookupExtraction(object):

mapping = {
Expand Down

0 comments on commit 1bf68ae

Please sign in to comment.