sadikovi commented on a change in pull request #35655:
URL: https://github.com/apache/spark/pull/35655#discussion_r815502277



##########
File path: 
sql/core/src/test/scala/org/apache/spark/sql/sources/TableScanSuite.scala
##########
@@ -420,4 +434,32 @@ class TableScanSuite extends DataSourceTest with 
SharedSparkSession {
     val comments = 
planned.schema.fields.map(_.getComment().getOrElse("NO_COMMENT")).mkString(",")
     assert(comments === "SN,SA,NO_COMMENT")
   }
+
+  test("SPARK-38315: control decoding of datetime as Java 8 classes") {
+    val tableName = "relationProviderWithLegacyTimestamps"
+    def scanTable(): Unit = {
+      withTable (tableName) {
+        sql(
+          s"""
+             |CREATE TABLE $tableName (col TIMESTAMP)
+             |USING org.apache.spark.sql.sources.LegacyTimestampSource
+             """.stripMargin)
+        checkAnswer(
+          spark.table(tableName),
+          Row(java.sql.Timestamp.valueOf("2020-01-01 12:34:56")) :: Nil)
+      }
+    }
+
+    withSQLConf(SQLConf.DATETIME_JAVA8API_ENABLED.key -> "true") {
+      val e = intercept[SparkException] {
+        scanTable()
+      }.getCause
+      assert(e.isInstanceOf[java.lang.RuntimeException])
+      assert(e.getMessage.contains("Error while encoding"))
+
+      withSQLConf(SQLConf.LEGACY_DATETIME_ENCODER_ENABLED.key -> "true") {

Review comment:
       Could you add a comment explaining that this test case is supposed to 
pass and should not throw any exceptions?




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

To unsubscribe, e-mail: [email protected]

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