fix: Oracle fetch_query and datetime conversion (#9240)

This commit is contained in:
Ville Brofeldt 2020-03-04 23:43:28 +02:00 committed by GitHub
parent 7a91498cf1
commit 969bc87431
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

View File

@ -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}"

View File

@ -44,6 +44,11 @@ class OracleTestCase(DbEngineSpecTestCase):
"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')""",