924060929 commented on code in PR #66345:
URL: https://github.com/apache/doris/pull/66345#discussion_r3700942969


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java:
##########
@@ -717,7 +716,9 @@ public PlanFragment visitPhysicalConnectorTableSink(
         // TSortInfo here (the connector's planWrite has no bound exprs). 
Empty for connectors with no
         // write sort (jdbc/maxcompute) -> null, byte-identical unsorted sink.
         TSortInfo writeSortInfo = buildConnectorWriteSortInfo(
-                writePlanProvider.getWriteSortColumns(connSession, 
providerTableHandle),
+                // Resolve against the actual bound output subset. A 
full-schema ordinal can be out of range
+                // for a partial INSERT even when the table schema itself has 
not changed.
+                writePlanProvider.getWriteSortColumns(connSession, 
providerTableHandle, connectorColumns),

Review Comment:
   [P1] Resolve the write-sort position in the same coordinate space that 
consumes it. `connectorColumns` comes from `connectorTableSink.getCols()`, so 
it is the partial/user-ordered write subset, but 
`buildConnectorWriteSortInfo()` applies the returned index to 
`connectorTableSink.getOutput()`. For a positional Iceberg write, `BindSink` 
has already projected that output into full target-schema order. For example, 
with schema `[a, b, c]`, `WRITE ORDERED BY c`, and `INSERT INTO t(c) SELECT x`, 
the provider maps field-id(c) to subset index 0, then this path sorts full 
output slot 0 (`a`, normally a NULL fill) instead of `c`. A reordered column 
list misroutes keys similarly, and a statically supplied sort column may 
disappear from the subset entirely. The write then does not honor the 
table-declared Iceberg sort order. Please resolve stable field ids against a 
bind-time, output-aligned column list (or return field ids/ExprIds instead of 
ordinals), and add an end-to-end `TSortInfo.orderi
 ng_exprs` assertion for partial/reordered/static-partition INSERTs.



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