villebro commented on a change in pull request #8464: [SIP-15] Fixing datetime 
conversion and SQL literal
URL: 
https://github.com/apache/incubator-superset/pull/8464#discussion_r340275855
 
 

 ##########
 File path: superset/db_engine_specs/bigquery.py
 ##########
 @@ -72,11 +72,13 @@ class BigQueryEngineSpec(BaseEngineSpec):
     }
 
     @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)"
+        if tt == "TIMESTAMP":
+            return f"""CAST('{dttm.isoformat(sep=" ", timespec="seconds")}' AS 
TIMESTAMP)"""  # pylint: disable=line-too-long
 
 Review comment:
   This doesn't need to be truncated to seconds or have " " separator. Also we 
should add similar logic for `DATETIME`, which should conform to 
`f"""CAST('{dttm.isoformat()}' AS DATETIME)"""`. See below:
   
   
![image](https://user-images.githubusercontent.com/33317356/67800874-c04cbd00-fa90-11e9-8880-df61e9309ac1.png)
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to