[sql] Fixing datetime SQL literal (#8464)

This commit is contained in:
John Bodley
2019-10-29 23:24:48 -07:00
committed by GitHub
parent 7afda6e4f5
commit 0a3b121244
33 changed files with 436 additions and 82 deletions

View File

@@ -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]: