mirror of
https://github.com/apache/superset.git
synced 2026-04-20 16:44:46 +00:00
[sql] Fixing datetime SQL literal (#8464)
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from urllib import parse
|
||||
|
||||
from superset.db_engine_specs.base import BaseEngineSpec
|
||||
@@ -49,13 +50,13 @@ class DrillEngineSpec(BaseEngineSpec):
|
||||
return "TO_DATE({col})"
|
||||
|
||||
@classmethod
|
||||
def convert_dttm(cls, target_type: str, dttm: datetime) -> str:
|
||||
def convert_dttm(cls, target_type: str, dttm: datetime) -> Optional[str]:
|
||||
tt = target_type.upper()
|
||||
if tt == "DATE":
|
||||
return "CAST('{}' AS DATE)".format(dttm.isoformat()[:10])
|
||||
return f"TO_DATE('{dttm.date().isoformat()}', 'yyyy-MM-dd')"
|
||||
elif tt == "TIMESTAMP":
|
||||
return "CAST('{}' AS TIMESTAMP)".format(dttm.strftime("%Y-%m-%d %H:%M:%S"))
|
||||
return "'{}'".format(dttm.strftime("%Y-%m-%d %H:%M:%S"))
|
||||
return f"""TO_TIMESTAMP('{dttm.isoformat(sep=" ", timespec="seconds")}', 'yyyy-MM-dd HH:mm:ss')""" # pylint: disable=line-too-long
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def adjust_database_uri(cls, uri, selected_schema):
|
||||
|
||||
Reference in New Issue
Block a user