hello-stephen commented on code in PR #69032:
URL: https://github.com/apache/doris/pull/69032#discussion_r4741089618


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertUtils.java:
##########
@@ -737,10 +739,29 @@ private static void addColumnValue(
         addColumnValue(analyzer, optimizedRowConstructor, value, targetType, 
rewriteContext, strictCast, null);
     }
 
-    private static void addColumnValue(Optional<ExpressionAnalyzer> analyzer,
+    static void addColumnValue(Optional<ExpressionAnalyzer> analyzer,
             ImmutableList.Builder<NamedExpression> optimizedRowConstructor,
             NamedExpression value, DataType targetType, 
ExpressionRewriteContext rewriteContext,
             boolean strictCast, Column targetColumn) {
+        if (targetColumn != null && 
targetColumn.getType().typeContainsSpatialType()) {
+            // Keep the source identity until binding can validate kind, CRS 
and algorithm.
+            if (!analyzer.isPresent()) {
+                optimizedRowConstructor.add(value);
+                return;
+            }
+            value = (NamedExpression) analyzer.get().analyze(value,
+                    new 
ExpressionRewriteContext(analyzer.get().getCascadesContext()));
+            if (value instanceof Alias && value.child(0) instanceof Cast
+                    && 
ConnectorSpatialWriteNormalizer.isMapOrStructCast(value.child(0).getDataType(), 
targetType)) {

Review Comment:
   [P2] Normalize ARRAY casts before validating spatial VALUES
   
   For an Iceberg V3 target `payload ARRAY<STRUCT<k:INT,shape:GEOMETRY>>`, this 
NULL-leaf write is rejected:
   
   ```sql
   INSERT INTO t(payload) VALUES (
     CAST(ARRAY(named_struct('k', CAST(rand()*100 AS INT),
                            'shape', CAST(NULL AS INT)))
          AS ARRAY<STRUCT<k:INT,shape:INT>>));
   ```
   
   The reduced input is `ConnectorSink -> 
InlineTable[Alias(Cast(Array(Struct(dynamic_k, NULL:INT)), ...))]`. `rand()` 
keeps the outer ARRAY cast nonliteral through `buildExprAnalyzer`/FE folding. 
This guard excludes ARRAY, so `ConnectorSpatialWriteValidator` falls back to 
the cast's declared type and rejects INT -> GEOMETRY before `BindSink` can 
normalize the NULL. Removing just the outer cast permits the constructor-level 
NULL handling.
   
   Apply the bound container proof to compatible ARRAY casts here, retaining 
original-cast validation and dynamic-expression evaluation count, and add 
Geometry/Geography VALUES controls. The repaired MERGE `SpatialMergeBranchCast` 
path is not invoked by this early VALUES validator. This is source tracing; the 
SQL was not executed.



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