From 0b0106f11cac9a1da038daae6c3190b73fae216c Mon Sep 17 00:00:00 2001 From: Xiang Fu Date: Sat, 30 May 2020 17:21:30 -0700 Subject: [PATCH 1/2] Update how pinot handles selection logic --- superset/db_engine_specs/pinot.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/superset/db_engine_specs/pinot.py b/superset/db_engine_specs/pinot.py index ddd6f83c0d6c..14b5221a07aa 100644 --- a/superset/db_engine_specs/pinot.py +++ b/superset/db_engine_specs/pinot.py @@ -79,9 +79,12 @@ def get_timestamp_expr( else: seconds_or_ms = "MILLISECONDS" if pdf == "epoch_ms" else "SECONDS" tf = f"1:{seconds_or_ms}:EPOCH" - granularity = cls.get_time_grain_expressions().get(time_grain) - if not granularity: - raise NotImplementedError("No pinot grain spec for " + str(time_grain)) + if time_grain: + granularity = cls.get_time_grain_expressions().get(time_grain) + if not granularity: + raise NotImplementedError("No pinot grain spec for " + str(time_grain)) + else: + return TimestampExpression(f"{{col}}", col) # In pinot the output is a string since there is no timestamp column like pg time_expr = f'DATETIMECONVERT({{col}}, "{tf}", "{tf}", "{granularity}")' return TimestampExpression(time_expr, col) @@ -90,13 +93,4 @@ def get_timestamp_expr( def make_select_compatible( cls, groupby_exprs: Dict[str, ColumnElement], select_exprs: List[ColumnElement] ) -> List[ColumnElement]: - # Pinot does not want the group by expr's to appear in the select clause - select_sans_groupby = [] - # We want identity and not equality, so doing the filtering manually - for sel in select_exprs: - for gr in groupby_exprs: - if sel is gr: - break - else: - select_sans_groupby.append(sel) - return select_sans_groupby + return select_exprs From 2ad1ccaaf3c3cbc4cf03e5f5135274b07584dde8 Mon Sep 17 00:00:00 2001 From: Xiang Fu Date: Mon, 1 Jun 2020 23:15:59 -0700 Subject: [PATCH 2/2] Change DATETIMECONVERT argument to use single quote for literals --- superset/db_engine_specs/pinot.py | 2 +- tests/db_engine_specs/pinot_tests.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/superset/db_engine_specs/pinot.py b/superset/db_engine_specs/pinot.py index 14b5221a07aa..9243fefa7da1 100644 --- a/superset/db_engine_specs/pinot.py +++ b/superset/db_engine_specs/pinot.py @@ -86,7 +86,7 @@ def get_timestamp_expr( else: return TimestampExpression(f"{{col}}", col) # In pinot the output is a string since there is no timestamp column like pg - time_expr = f'DATETIMECONVERT({{col}}, "{tf}", "{tf}", "{granularity}")' + time_expr = f"DATETIMECONVERT({{col}}, '{tf}', '{tf}', '{granularity}')" return TimestampExpression(time_expr, col) @classmethod diff --git a/tests/db_engine_specs/pinot_tests.py b/tests/db_engine_specs/pinot_tests.py index a96e9c12bcee..405ac9b16167 100644 --- a/tests/db_engine_specs/pinot_tests.py +++ b/tests/db_engine_specs/pinot_tests.py @@ -29,5 +29,5 @@ def test_pinot_time_expression_sec_one_1m_grain(self): result = str(expr.compile()) self.assertEqual( result, - 'DATETIMECONVERT(tstamp, "1:SECONDS:EPOCH", "1:SECONDS:EPOCH", "1:MONTHS")', + "DATETIMECONVERT(tstamp, '1:SECONDS:EPOCH', '1:SECONDS:EPOCH', '1:MONTHS')", ) # noqa