Skip to content

Commit

Permalink
chore: Add Druid SQL timegrains for parity with Druid NoSQL (#15320)
Browse files Browse the repository at this point in the history
Co-authored-by: John Bodley <john.bodley@airbnb.com>
  • Loading branch information
john-bodley and John Bodley committed Jun 25, 2021
1 parent 53aa351 commit accee50
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions superset/db_engine_specs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,15 @@ class TimeGrain(NamedTuple): # pylint: disable=too-few-public-methods
builtin_time_grains: Dict[Optional[str], str] = {
None: __("Original value"),
"PT1S": __("Second"),
"PT5S": __("5 second"),
"PT30S": __("30 second"),
"PT1M": __("Minute"),
"PT5M": __("5 minute"),
"PT10M": __("10 minute"),
"PT15M": __("15 minute"),
"PT0.5H": __("Half hour"),
"PT1H": __("Hour"),
"PT6H": __("6 hour"),
"P1D": __("Day"),
"P1W": __("Week"),
"P1M": __("Month"),
Expand Down
9 changes: 9 additions & 0 deletions superset/db_engine_specs/druid.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,26 @@ class DruidEngineSpec(BaseEngineSpec): # pylint: disable=abstract-method
_time_grain_expressions = {
None: "{col}",
"PT1S": "FLOOR({col} TO SECOND)",
"PT5S": "TIME_FLOOR({col}, 'PT5S')",
"PT30S": "TIME_FLOOR({col}, 'PT30S')",
"PT1M": "FLOOR({col} TO MINUTE)",
"PT5M": "TIME_FLOOR({col}, 'PT5M')",
"PT10M": "TIME_FLOOR({col}, 'PT10M')",
"PT15M": "TIME_FLOOR({col}, 'PT15M')",
"PT0.5H": "TIME_FLOOR({col}, 'PT30M')",
"PT1H": "FLOOR({col} TO HOUR)",
"PT6H": "TIME_FLOOR({col}, 'PT6H')",
"P1D": "FLOOR({col} TO DAY)",
"P1W": "FLOOR({col} TO WEEK)",
"P1M": "FLOOR({col} TO MONTH)",
"P0.25Y": "FLOOR({col} TO QUARTER)",
"P1Y": "FLOOR({col} TO YEAR)",
"P1W/1970-01-03T00:00:00Z": (
"TIMESTAMPADD(DAY, 5, FLOOR(TIMESTAMPADD(DAY, 1, {col}) TO WEEK))"
),
"1969-12-28T00:00:00Z/P1W": (
"TIMESTAMPADD(DAY, -1, FLOOR(TIMESTAMPADD(DAY, 1, {col}) TO WEEK))"
),
}

@classmethod
Expand Down

0 comments on commit accee50

Please sign in to comment.