yihua commented on code in PR #12798:
URL: https://github.com/apache/hudi/pull/12798#discussion_r1964551803


##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/TestTableColumnTypeMismatch.scala:
##########
@@ -0,0 +1,941 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.hudi
+
+import org.apache.hudi.{DataSourceWriteOptions, ScalaAssertionSupport}
+
+import org.apache.spark.sql.AnalysisException
+import 
org.apache.spark.sql.hudi.ErrorMessageChecker.isIncompatibleDataException
+import org.apache.spark.sql.hudi.common.HoodieSparkSqlTestBase
+
+class TestTableColumnTypeMismatch extends HoodieSparkSqlTestBase with 
ScalaAssertionSupport {

Review Comment:
   Could you report the testing time increase of all new tests added? We need 
to revisit these if they take non-trivial time to finish.



##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/TestTableColumnTypeMismatch.scala:
##########
@@ -0,0 +1,941 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.hudi
+
+import org.apache.hudi.{DataSourceWriteOptions, ScalaAssertionSupport}
+
+import org.apache.spark.sql.AnalysisException
+import 
org.apache.spark.sql.hudi.ErrorMessageChecker.isIncompatibleDataException
+import org.apache.spark.sql.hudi.common.HoodieSparkSqlTestBase
+
+class TestTableColumnTypeMismatch extends HoodieSparkSqlTestBase with 
ScalaAssertionSupport {
+
+  test("Test Spark implicit type casting behaviors") {
+    // Capturing the current behavior of Spark's implicit type casting.
+    withRecordType()(withTempDir { tmp =>
+      // Define test cases for implicit casting
+      case class TypeCastTestCase(
+                                   sourceType: String,
+                                   targetType: String,
+                                   testValue: String, // SQL literal expression
+                                   expectedValue: Any,
+                                   shouldSucceed: Boolean,
+                                   description: String = ""
+                                 )
+
+      val testCases = Seq(
+        // Numeric widening conversions (always safe)
+        TypeCastTestCase("tinyint", "smallint", "127", 127, true, "tinyint to 
smallint widening"),
+        TypeCastTestCase("tinyint", "int", "127", 127, true, "tinyint to int 
widening"),
+        TypeCastTestCase("tinyint", "bigint", "127", 127L, true, "tinyint to 
bigint widening"),
+        TypeCastTestCase("tinyint", "float", "127", 127.0f, true, "tinyint to 
float widening"),
+        TypeCastTestCase("tinyint", "double", "127", 127.0d, true, "tinyint to 
double widening"),
+        TypeCastTestCase("tinyint", "decimal(10,1)", "127", 
java.math.BigDecimal.valueOf(127.0), true, "tinyint to decimal widening"),
+
+        TypeCastTestCase("smallint", "int", "32767", 32767, true, "smallint to 
int widening"),
+        TypeCastTestCase("smallint", "bigint", "32767", 32767L, true, 
"smallint to bigint widening"),
+        TypeCastTestCase("smallint", "float", "32767", 32767.0f, true, 
"smallint to float widening"),

Review Comment:
   If needed, could we just run one SQL statement containing all type cast 
cases instead of running each type cast one by one to save time in testing?



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

Reply via email to