mirror of
https://github.com/apache/superset.git
synced 2026-04-23 01:55:09 +00:00
[sql] Fixing datetime SQL literal (#8464)
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from datetime import datetime
|
||||
from typing import List
|
||||
from typing import List, Optional
|
||||
|
||||
from sqlalchemy.engine.reflection import Inspector
|
||||
|
||||
@@ -43,11 +43,13 @@ class ImpalaEngineSpec(BaseEngineSpec):
|
||||
return "from_unixtime({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 "'{}'".format(dttm.strftime("%Y-%m-%d"))
|
||||
return "'{}'".format(dttm.strftime("%Y-%m-%d %H:%M:%S"))
|
||||
return f"CAST('{dttm.date().isoformat()}' AS DATE)"
|
||||
elif tt == "TIMESTAMP":
|
||||
return f"""CAST('{dttm.isoformat(timespec="microseconds")}' AS TIMESTAMP)"""
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def get_schema_names(cls, inspector: Inspector) -> List[str]:
|
||||
|
||||
Reference in New Issue
Block a user