johanl-db commented on code in PR #58632:
URL: https://github.com/apache/spark/pull/58632#discussion_r4105692332
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/types/DataTypeUtils.scala:
##########
@@ -199,7 +202,7 @@ object DataTypeUtils {
case (_: NullType, _) if storeAssignmentPolicy == ANSI => true
case (w: AtomicType, r: AtomicType) if storeAssignmentPolicy == ANSI =>
- if (!Cast.canANSIStoreAssign(w, r)) {
+ if (!Cast.canANSIStoreAssign(w, r) && ansiStoreAssignmentCastCheck ==
AT_ANALYSIS) {
Review Comment:
I took a quick look to try and add proper checks, but that's exceeding the
scope of this PR
The timestamp issue seems to be a broader issue with
decimal/long->timestamp, not just for writes (writes just happened to not allow
that cast in DSv2 until now).
Variant-> complex types would also required additional work.
For now, I'm just keeping these casts rejected
##########
sql/catalyst/src/main/java/org/apache/spark/sql/internal/connector/ConfigurableSchemaAlignment.java:
##########
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+/**
+ * Allows connectors to configure schema alignment and casting behavior for
DSv2 batch/row-level
+ * writes to a {@link Table}. It is not consulted for streaming writes, where
alignment is
+ * delegated to the connector.
+ */
+public interface ConfigurableSchemaAlignment extends Table {
Review Comment:
I do expect `SchemaAlignmentConfig` will be extended in the future, hence
the generic name.
For example, earlier version of this PR included the option to allow
`spark.sql.storeAssignmentPolicy`, and beyond storeAssignmentPolicy, there are
previous examples of tuning schema alignment behavior that I believe would be
better suited to be toggled by connectors rather than session-wide conf, in
case we have similar cases in the future. For example
[coerceNestedTypes](https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveRowLevelCommandAssignments.scala#L54)
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/types/DataTypeUtils.scala:
##########
@@ -213,12 +216,18 @@ 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 (_, _) if storeAssignmentPolicy == ANSI &&
ansiStoreAssignmentCastCheck == AT_RUNTIME =>
Review Comment:
See
https://github.com/apache/spark/pull/58632/changes/BASE..2ff5f563fb76c2f40f0a34bc4f47d65c1f9015fc#r4105692332.
Rejecting Variant -> complex types for now
--
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]