You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by vi...@apache.org on 2021/05/07 12:33:24 UTC

[superset] branch master updated: feat(dremio): implement convert_dttm method (#14519)

This is an automated email from the ASF dual-hosted git repository.

villebro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new d1d98d8  feat(dremio): implement convert_dttm method (#14519)
d1d98d8 is described below

commit d1d98d81b03035f1047326502151ab70f8a6b43e
Author: Ville Brofeldt <33...@users.noreply.github.com>
AuthorDate: Fri May 7 15:31:58 2021 +0300

    feat(dremio): implement convert_dttm method (#14519)
---
 superset/db_engine_specs/dremio.py                 | 16 ++++++++++-
 .../db_engine_specs/dremio_tests.py                | 32 +++++++++-------------
 2 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/superset/db_engine_specs/dremio.py b/superset/db_engine_specs/dremio.py
index 4a11424..a76909b 100644
--- a/superset/db_engine_specs/dremio.py
+++ b/superset/db_engine_specs/dremio.py
@@ -14,10 +14,14 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+from datetime import datetime
+from typing import Optional
+
 from superset.db_engine_specs.base import BaseEngineSpec
+from superset.utils import core as utils
 
 
-class DremioBaseEngineSpec(BaseEngineSpec):
+class DremioEngineSpec(BaseEngineSpec):
 
     engine = "dremio"
     engine_name = "Dremio"
@@ -37,3 +41,13 @@ class DremioBaseEngineSpec(BaseEngineSpec):
     @classmethod
     def epoch_to_dttm(cls) -> str:
         return "TO_DATE({col})"
+
+    @classmethod
+    def convert_dttm(cls, target_type: str, dttm: datetime) -> Optional[str]:
+        tt = target_type.upper()
+        if tt == utils.TemporalType.DATE:
+            return f"TO_DATE('{dttm.date().isoformat()}', 'YYYY-MM-DD')"
+        if tt == utils.TemporalType.TIMESTAMP:
+            dttm_formatted = dttm.isoformat(sep=" ", timespec="milliseconds")
+            return f"""TO_TIMESTAMP('{dttm_formatted}', 'YYYY-MM-DD HH24:MI:SS.FFF')"""
+        return None
diff --git a/superset/db_engine_specs/dremio.py b/tests/db_engine_specs/dremio_tests.py
similarity index 54%
copy from superset/db_engine_specs/dremio.py
copy to tests/db_engine_specs/dremio_tests.py
index 4a11424..02d21c6 100644
--- a/superset/db_engine_specs/dremio.py
+++ b/tests/db_engine_specs/dremio_tests.py
@@ -14,26 +14,20 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-from superset.db_engine_specs.base import BaseEngineSpec
+from superset.db_engine_specs.dremio import DremioEngineSpec
+from tests.db_engine_specs.base_tests import TestDbEngineSpec
 
 
-class DremioBaseEngineSpec(BaseEngineSpec):
+class TestDremioDbEngineSpec(TestDbEngineSpec):
+    def test_convert_dttm(self):
+        dttm = self.get_dttm()
 
-    engine = "dremio"
-    engine_name = "Dremio"
+        self.assertEqual(
+            DremioEngineSpec.convert_dttm("DATE", dttm),
+            "TO_DATE('2019-01-02', 'YYYY-MM-DD')",
+        )
 
-    _time_grain_expressions = {
-        None: "{col}",
-        "PT1S": "DATE_TRUNC('second', {col})",
-        "PT1M": "DATE_TRUNC('minute', {col})",
-        "PT1H": "DATE_TRUNC('hour', {col})",
-        "P1D": "DATE_TRUNC('day', {col})",
-        "P1W": "DATE_TRUNC('week', {col})",
-        "P1M": "DATE_TRUNC('month', {col})",
-        "P0.25Y": "DATE_TRUNC('quarter', {col})",
-        "P1Y": "DATE_TRUNC('year', {col})",
-    }
-
-    @classmethod
-    def epoch_to_dttm(cls) -> str:
-        return "TO_DATE({col})"
+        self.assertEqual(
+            DremioEngineSpec.convert_dttm("TIMESTAMP", dttm),
+            "TO_TIMESTAMP('2019-01-02 03:04:05.678', 'YYYY-MM-DD HH24:MI:SS.FFF')",
+        )