kiszk commented on a change in pull request #28593:
URL: https://github.com/apache/spark/pull/28593#discussion_r430862928



##########
File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CastSuite.scala
##########
@@ -1311,6 +1311,27 @@ class CastSuite extends CastSuiteBase {
       checkEvaluation(cast(negativeTs, LongType), expectedSecs)
     }
   }
+
+  test("SPARK-31710:fail casting from integral to timestamp by default") {
+    withSQLConf(SQLConf.LEGACY_AllOW_CAST_NUMERIC_TO_TIMESTAMP.key -> "false") 
{
+      assert(!cast(2.toByte, TimestampType).resolved)
+      assert(!cast(10.toShort, TimestampType).resolved)
+      assert(!cast(3, TimestampType).resolved)
+      assert(!cast(10L, TimestampType).resolved)
+      assert(!cast(Decimal(1.2), TimestampType).resolved)
+      assert(!cast(1.7f, TimestampType).resolved)
+      assert(!cast(2.3d, TimestampType).resolved)
+    }
+    withSQLConf(SQLConf.LEGACY_AllOW_CAST_NUMERIC_TO_TIMESTAMP.key -> "true") {
+      assert(cast(2.toByte, TimestampType).resolved)
+      assert(cast(10.toShort, TimestampType).resolved)
+      assert(cast(3, TimestampType).resolved)
+      assert(cast(10L, TimestampType).resolved)
+      assert(cast(Decimal(1.2), TimestampType).resolved)
+      assert(cast(1.7f, TimestampType).resolved)
+      assert(cast(2.3d, TimestampType).resolved)
+    }
+  }

Review comment:
       How about the following style to make it small?
   
   ```
     Seq(true, false).foreach { enabled =>
       withSQLConf(SQLConf.LEGACY_AllOW_CAST_NUMERIC_TO_TIMESTAMP.key -> 
enabled.toString) {
         assert(cast(2.toByte, TimestampType).resolved == enabled)
         ...
       }
     }
   ```




----------------------------------------------------------------
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:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to