diff --git a/superset/db_engine_specs/hive.py b/superset/db_engine_specs/hive.py index 478a65ec909ef..bb2c43c83d601 100644 --- a/superset/db_engine_specs/hive.py +++ b/superset/db_engine_specs/hive.py @@ -56,6 +56,20 @@ class HiveEngineSpec(PrestoEngineSpec): engine = "hive" max_column_name_length = 767 + # pylint: disable=line-too-long + _time_grain_expressions = { + None: "{col}", + "PT1S": "from_unixtime(unix_timestamp({col}), 'yyyy-MM-dd HH:mm:ss')", + "PT1M": "from_unixtime(unix_timestamp({col}), 'yyyy-MM-dd HH:mm:00')", + "PT1H": "from_unixtime(unix_timestamp({col}), 'yyyy-MM-dd HH:00:00')", + "P1D": "from_unixtime(unix_timestamp({col}), 'yyyy-MM-dd 00:00:00')", + "P1W": "date_format(date_sub({col}, CAST(7-from_unixtime(unix_timestamp({col}),'u') as int)), 'yyyy-MM-dd 00:00:00')", + "P1M": "from_unixtime(unix_timestamp({col}), 'yyyy-MM-01 00:00:00')", + "P0.25Y": "date_format(add_months(trunc({col}, 'MM'), -(month({col})-1)%3), 'yyyy-MM-dd 00:00:00')", + "P1Y": "from_unixtime(unix_timestamp({col}), 'yyyy-01-01 00:00:00')", + "P1W/1970-01-03T00:00:00Z": "date_format(date_add({col}, INT(6-from_unixtime(unix_timestamp({col}), 'u'))), 'yyyy-MM-dd 00:00:00')", + "1969-12-28T00:00:00Z/P1W": "date_format(date_add({col}, -INT(from_unixtime(unix_timestamp({col}), 'u'))), 'yyyy-MM-dd 00:00:00')", + } # Scoping regex at class level to avoid recompiling # 17/02/07 19:36:38 INFO ql.Driver: Total jobs = 5