TJX2014 opened a new pull request #29043:
URL: https://github.com/apache/spark/pull/29043


   ### What changes were proposed in this pull request?
   1. Change timestamp to mysql to datetime in 
`org.apache.spark.sql.jdbc.MySQLDialect#getJDBCType`
   2. Add UT in `org.apache.spark.sql.test.SQLTestUtils#test` .
   
   ### Why are the changes needed?
   Because write spark timestamp to mysql should has a '1000-01-01 00:00:00' to 
'9999-12-31 23:59:59' range.
   see https://dev.mysql.com/doc/refman/5.7/en/datetime.html
   While the date type in mysql should be datetime rather than timestamp.
   **Before this patch**, when we use timestamp data type in mysql by auto 
created table:
   `sql("select cast('1111-01-01 00:00:01' as 
timestamp)").toDF("ts").write.mode("append").jdbc("jdbc:mysql://localhost:3306/test",
 "ts_test3",prop)`
   we will get an exception:
   `com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime 
value: '1111-01-01 00:00:01' for column 'ts' at row`
   
   ### Does this PR introduce _any_ user-facing change?
   Yes, **after this patch**, people could insert '1000-01-01 00:00:00' to 
'9999-12-31 23:59:59' range timestamp to mysql by table auto created.
   
   ### How was this patch tested?
   Unit test.
   


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



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

Reply via email to