From a6f46013d966b243fbdca072e7898cdbf2a2f3d6 Mon Sep 17 00:00:00 2001 From: "Hugh A. Miles II" Date: Tue, 19 Apr 2022 11:16:48 -0700 Subject: [PATCH] feat: 10/15/30 min grain to Pinot (#19724) * add new grains to pinot * update test --- superset/db_engine_specs/pinot.py | 8 ++++++++ .../db_engine_specs/pinot_tests.py | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/superset/db_engine_specs/pinot.py b/superset/db_engine_specs/pinot.py index 051f42501f929..38e30accecbc0 100644 --- a/superset/db_engine_specs/pinot.py +++ b/superset/db_engine_specs/pinot.py @@ -33,6 +33,10 @@ class PinotEngineSpec(BaseEngineSpec): # pylint: disable=abstract-method _time_grain_expressions: Dict[Optional[str], str] = { "PT1S": "1:SECONDS", "PT1M": "1:MINUTES", + "PT5M": "5:MINUTES", + "PT10M": "10:MINUTES", + "PT15M": "15:MINUTES", + "PT30M": "30:MINUTES", "PT1H": "1:HOURS", "P1D": "1:DAYS", "P1W": "week", @@ -53,6 +57,10 @@ class PinotEngineSpec(BaseEngineSpec): # pylint: disable=abstract-method _use_date_trunc_function: Dict[str, bool] = { "PT1S": False, "PT1M": False, + "PT5M": False, + "PT10M": False, + "PT15M": False, + "PT30M": False, "PT1H": False, "P1D": False, "P1W": True, diff --git a/tests/integration_tests/db_engine_specs/pinot_tests.py b/tests/integration_tests/db_engine_specs/pinot_tests.py index 803dd67cbacfa..c6e364a8ea5fe 100644 --- a/tests/integration_tests/db_engine_specs/pinot_tests.py +++ b/tests/integration_tests/db_engine_specs/pinot_tests.py @@ -45,6 +45,19 @@ def test_pinot_time_expression_simple_date_format_1d_grain(self): ), ) + def test_pinot_time_expression_simple_date_format_10m_grain(self): + col = column("tstamp") + expr = PinotEngineSpec.get_timestamp_expr(col, "%Y-%m-%d %H:%M:%S", "PT10M") + result = str(expr.compile()) + self.assertEqual( + result, + ( + "DATETIMECONVERT(tstamp, " + + "'1:SECONDS:SIMPLE_DATE_FORMAT:yyyy-MM-dd HH:mm:ss', " + + "'1:SECONDS:SIMPLE_DATE_FORMAT:yyyy-MM-dd HH:mm:ss', '10:MINUTES')" + ), + ) + def test_pinot_time_expression_simple_date_format_1w_grain(self): col = column("tstamp") expr = PinotEngineSpec.get_timestamp_expr(col, "%Y-%m-%d %H:%M:%S", "P1W")