szehon-ho commented on code in PR #58632:
URL: https://github.com/apache/spark/pull/58632#discussion_r4139941626


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/types/DataTypeUtils.scala:
##########
@@ -213,13 +217,26 @@ object DataTypeUtils {
       // If write-side data type is a user-defined type, check with its 
underlying data type.
       case (w, r) if w.isInstanceOf[UserDefinedType[_]] && 
!r.isInstanceOf[UserDefinedType[_]] =>
         canWrite(tableName, w.asInstanceOf[UserDefinedType[_]].sqlType, r, 
byName, resolver,
-          context, storeAssignmentPolicy, addError)
+          context, storeAssignmentPolicy, addError, 
ansiStoreAssignmentCastCheck)
 
       // If read-side data type is a user-defined type, check with its 
underlying data type.
       case (w, r) if r.isInstanceOf[UserDefinedType[_]] && 
!w.isInstanceOf[UserDefinedType[_]] =>
         canWrite(tableName, w, r.asInstanceOf[UserDefinedType[_]].sqlType, 
byName, resolver,
-          context, storeAssignmentPolicy, addError)
-
+          context, storeAssignmentPolicy, addError, 
ansiStoreAssignmentCastCheck)
+
+      // AT_RUNTIME defers to the inserted ANSI cast, which fails on malformed 
or overflowing
+      // values at runtime. Clearly invalid conversion are still rejected 
either in an earlier
+      // branch of this match clause, or in checkAnalysis.
+      case (w, r) if storeAssignmentPolicy == ANSI && 
ansiStoreAssignmentCastCheck == AT_RUNTIME =>
+        (w, r) match {
+          // Long/decimal -> timestamp can silently overflow, and variant -> 
complex types doesn't
+          // enforce nested field non-nullability. Keep rejecting them for now.
+          case (LongType | _: DecimalType, TimestampType) |
+               (VariantType, _: StructType | _: ArrayType | _: MapType) =>
+            throw 
QueryCompilationErrors.incompatibleDataToTableCannotSafelyCastError(
+              tableName, context, w.catalogString, r.catalogString)
+          case _ => true

Review Comment:
   **[P2] Keep unsupported datetime-to-VARIANT casts rejected**
   
   With TIME support enabled, `AT_RUNTIME` now admits `TIME -> VARIANT`; the 
same applies to nanosecond timestamps when their preview flag is enabled. These 
conversions also pass `Cast.canAnsiCast`, because `VariantGet.checkDataType` 
accepts every `DatetimeType`. However, 
`VariantExpressionEvalUtils.buildVariant` only implements DATE and the 
microsecond timestamp types, so a non-null TIME or nanosecond timestamp reaches 
a `MatchError`. The later analysis check therefore does not reject these 
unsupported conversions as the comment above expects. Please keep them rejected 
until the runtime implementation exists, and add a regression test.



##########
sql/catalyst/src/main/java/org/apache/spark/sql/internal/connector/SchemaAlignmentConfig.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.internal.connector;
+
+import org.apache.spark.sql.connector.catalog.Table;
+
+/**
+ * Schema alignment configuration for DSv2 batch/row-level writes to a {@link 
Table}, exposed via
+ * {@link ConfigurableSchemaAlignment}.
+ */
+public interface SchemaAlignmentConfig {

Review Comment:
   im still not sure why its an interface, can't it just be an enum inside the 
above interface?



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