Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Oracle fetch_query and datetime conversion #9240

Merged
merged 1 commit into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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