Skip to content

Commit

Permalink
fix: Oracle fetch_query and datetime conversion (#9240)
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro authored Mar 4, 2020
1 parent 7a91498 commit 969bc87
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
15 changes: 12 additions & 3 deletions superset/db_engine_specs/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -44,6 +43,16 @@ def convert_dttm(cls, target_type: str, dttm: datetime) -> Optional[str]:
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}"
5 changes: 5 additions & 0 deletions tests/db_engine_specs/oracle_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ def test_convert_dttm(self):
"TO_DATE('2019-01-02', 'YYYY-MM-DD')",
)

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')""",
Expand Down

0 comments on commit 969bc87

Please sign in to comment.