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 2020/03/04 21:43:43 UTC

[incubator-superset] branch master updated: fix: Oracle fetch_query and datetime conversion (#9240)

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/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 969bc87  fix: Oracle fetch_query and datetime conversion (#9240)
969bc87 is described below

commit 969bc87431264bb71462ca834b934fd295ed0650
Author: Ville Brofeldt <33...@users.noreply.github.com>
AuthorDate: Wed Mar 4 23:43:28 2020 +0200

    fix: Oracle fetch_query and datetime conversion (#9240)
---
 superset/db_engine_specs/oracle.py    | 15 ++++++++++++---
 tests/db_engine_specs/oracle_tests.py |  5 +++++
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/superset/db_engine_specs/oracle.py b/superset/db_engine_specs/oracle.py
index 2a20d4b..e72eef0 100644
--- a/superset/db_engine_specs/oracle.py
+++ b/superset/db_engine_specs/oracle.py
@@ -17,11 +17,10 @@
 from datetime import datetime
 from typing import Optional
 
-from superset.db_engine_specs.base import LimitMethod
-from superset.db_engine_specs.postgres import PostgresBaseEngineSpec
+from superset.db_engine_specs.base import BaseEngineSpec, LimitMethod
 
 
-class OracleEngineSpec(PostgresBaseEngineSpec):
+class OracleEngineSpec(BaseEngineSpec):
     engine = "oracle"
     limit_method = LimitMethod.WRAP_SQL
     force_column_alias_quotes = True
@@ -44,6 +43,16 @@ class OracleEngineSpec(PostgresBaseEngineSpec):
         tt = target_type.upper()
         if tt == "DATE":
             return f"TO_DATE('{dttm.date().isoformat()}', 'YYYY-MM-DD')"
+        if tt == "DATETIME":
+            return f"""TO_DATE('{dttm.isoformat(timespec="seconds")}', 'YYYY-MM-DD"T"HH24:MI:SS')"""  # pylint: disable=line-too-long
         if tt == "TIMESTAMP":
             return f"""TO_TIMESTAMP('{dttm.isoformat(timespec="microseconds")}', 'YYYY-MM-DD"T"HH24:MI:SS.ff6')"""  # pylint: disable=line-too-long
         return None
+
+    @classmethod
+    def epoch_to_dttm(cls) -> str:
+        return "TO_DATE('1970-01-01','YYYY-MM-DD')+(1/24/60/60)*{col}"
+
+    @classmethod
+    def epoch_ms_to_dttm(cls) -> str:
+        return "TO_DATE('1970-01-01','YYYY-MM-DD')+(1/24/60/60/1000)*{col}"
diff --git a/tests/db_engine_specs/oracle_tests.py b/tests/db_engine_specs/oracle_tests.py
index 9e39405..09806a0 100644
--- a/tests/db_engine_specs/oracle_tests.py
+++ b/tests/db_engine_specs/oracle_tests.py
@@ -45,6 +45,11 @@ class OracleTestCase(DbEngineSpecTestCase):
         )
 
         self.assertEqual(
+            OracleEngineSpec.convert_dttm("DATETIME", dttm),
+            """TO_DATE('2019-01-02T03:04:05', 'YYYY-MM-DD"T"HH24:MI:SS')""",
+        )
+
+        self.assertEqual(
             OracleEngineSpec.convert_dttm("TIMESTAMP", dttm),
             """TO_TIMESTAMP('2019-01-02T03:04:05.678900', 'YYYY-MM-DD"T"HH24:MI:SS.ff6')""",
         )