github-actions[bot] commented on code in PR #69032:
URL: https://github.com/apache/doris/pull/69032#discussion_r4469670114


##########
fe/fe-core/src/main/java/org/apache/doris/datasource/connector/converter/ConnectorSpatialWriteValidator.java:
##########
@@ -0,0 +1,246 @@
+// 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.doris.datasource.connector.converter;
+
+import org.apache.doris.catalog.ArrayType;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.MapType;
+import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.catalog.StructType;
+import org.apache.doris.catalog.Type;
+import org.apache.doris.nereids.exceptions.AnalysisException;
+import org.apache.doris.nereids.trees.expressions.Alias;
+import org.apache.doris.nereids.trees.expressions.CaseWhen;
+import org.apache.doris.nereids.trees.expressions.Cast;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.Array;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.Coalesce;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.CreateMap;
+import 
org.apache.doris.nereids.trees.expressions.functions.scalar.CreateNamedStruct;
+import 
org.apache.doris.nereids.trees.expressions.functions.scalar.CreateStruct;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.If;
+import org.apache.doris.nereids.trees.expressions.literal.ArrayLiteral;
+import org.apache.doris.nereids.trees.expressions.literal.MapLiteral;
+import org.apache.doris.nereids.trees.expressions.literal.StructLiteral;
+import org.apache.doris.nereids.types.DataType;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Preserves the kind and parameters of spatial connector columns before sink 
coercion.
+ * A spatial value is an opaque WKB payload at execution time, so a generic 
cast cannot
+ * safely convert between CRS, edge algorithms, or Geometry and Geography.
+ */
+public final class ConnectorSpatialWriteValidator {
+    private ConnectorSpatialWriteValidator() {
+    }
+
+    public static void validate(List<Column> targetColumns,
+            List<? extends NamedExpression> sourceColumns) {
+        if (targetColumns.size() != sourceColumns.size()) {
+            throw new AnalysisException("Spatial connector write target and 
source columns are not aligned");
+        }
+        for (int i = 0; i < targetColumns.size(); i++) {
+            validate(targetColumns.get(i), sourceColumns.get(i));
+        }
+    }
+
+    public static void validate(Column targetColumn, Expression source) {
+        Type targetType = targetColumn.getType();
+        if (targetType.typeContainsSpatialType()) {
+            validateRequiredArrayNulls(source, targetColumn, 
targetColumn.getName());
+            validateExpression(source, targetType, targetColumn.getName());
+        }
+    }
+
+    private static void validateRequiredArrayNulls(Expression expression, 
Column targetColumn,
+            String columnName) {
+        if (expression instanceof Alias || expression instanceof Cast) {
+            validateRequiredArrayNulls(expression.child(0), targetColumn, 
columnName);
+            return;
+        }
+        if (!(targetColumn.getType() instanceof ArrayType) || 
targetColumn.getChildren().isEmpty()

Review Comment:
   [P2] Reject NULLs in required spatial lists nested inside containers. 
validateRequiredArrayNulls only runs when the top-level target Column is an 
ArrayType; recursive STRUCT/MAP validation descends into nested arrays without 
consulting the nested Column child's isAllowNull. A schema such as STRUCT<items 
ARRAY<GEOMETRY>> with a required list element can therefore accept 
named_struct('items', array(CAST(NULL AS GEOMETRY))) and pass a NULL element to 
the Iceberg writer. Thread nested target-column nullability through the 
recursive validation (and cover nested struct/map cases) while retaining the 
existing direct-list check.



##########
be/src/core/data_type_serde/data_type_varbinary_serde.cpp:
##########
@@ -284,11 +319,11 @@ Status 
DataTypeVarbinarySerDe::read_column_from_arrow(IColumn& column,
     return Status::OK();
 }
 
-Status DataTypeVarbinarySerDe::write_column_to_orc(const std::string& timezone,
-                                                   const IColumn& column, 
const NullMap* null_map,
-                                                   orc::ColumnVectorBatch* 
orc_col_batch,
-                                                   int64_t start, int64_t end, 
Arena& arena,
-                                                   const FormatOptions& 
options) const {
+template <typename ColumnType>

Review Comment:
   [P1] Avoid ColumnVarbinary casts for ORC spatial columns. 
DataTypeSpatial::get_serde() instantiates 
DataTypeVarbinarySerDeBase<ColumnSpatial>, but the ORC methods below this new 
template declaration still assert_cast the input to ColumnVarbinary (the 
matching read cast is at line 350). Iceberg type mapping accepts spatial leaves 
without a file-format gate, and the format-v2 ORC reader invokes the selected 
column SerDe, so an existing external ORC Iceberg spatial table can abort 
during a normal scan before returning data or a clear unsupported-format 
status. Parameterize both ORC methods for ColumnType or reject spatial ORC 
scans before this SerDe is invoked, and add a read-path regression.



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