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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/PluginDrivenInsertCommandContext.java:
##########
@@ -87,13 +94,63 @@ public void 
setStaticPartitionSpecFromExpressions(Map<String, Expression> partit
                 // Binary partition keys must bypass character decoding, 
including empty and non-UTF-8 bytes.
                 spec.put(entry.getKey(), literal instanceof VarBinaryLiteral
                         ? "0x" + literal.toString() : 
literal.getStringValue());
+                literals.put(entry.getKey(), literal);
                 if (entry.getValue() instanceof NullLiteral) {
                     nullKeys.add(entry.getKey());
                 }
             }
         }
         this.staticPartitionSpec = spec;
         this.staticPartitionNullKeys = nullKeys;
+        this.staticPartitionLiterals = literals;
+    }
+
+    public void setBoundTargetSchema(List<Column> boundTargetSchema) {
+        this.boundTargetSchema = boundTargetSchema;
+    }
+
+    /**
+     * Casts the static partition values to the types of their columns in the 
bound target schema; see
+     * {@code ConnectorWriteHandle#getCastStaticPartitionSpec}. Each value is 
the one BindSink materializes into
+     * the rows, after constant folding, but a value that does not fit its 
type fails here instead of becoming
+     * NULL.
+     */
+    public Map<String, String> castStaticPartitionSpec() {
+        Preconditions.checkState(staticPartitionLiterals.isEmpty() || 
!boundTargetSchema.isEmpty(),
+                "static partition values are cast before the sink is bound to 
a target schema");
+        Map<String, String> spec = new LinkedHashMap<>();
+        for (Map.Entry<String, Literal> entry : 
staticPartitionLiterals.entrySet()) {
+            if (staticPartitionNullKeys.contains(entry.getKey())) {
+                continue;
+            }
+            Literal value = entry.getValue();
+            Optional<Column> column = boundTargetSchema.stream()
+                    .filter(candidate -> 
candidate.getName().equalsIgnoreCase(entry.getKey()))
+                    .findFirst();
+            if (column.isPresent()) {
+                value = writtenValue(value, 
DataType.fromCatalogType(column.get().getType()));
+            }
+            spec.put(entry.getKey(), value.getStringValue());

Review Comment:
   [P1] Preserve binary partition bytes in the static overwrite target. For a 
Paimon `VARBINARY(2147483647)` partition, `PARTITION (p = X'4142')` leaves a 
matching `VarBinaryLiteral` intact after the checked cast, but 
`getStringValue()` calls `String.valueOf(byte[])` and emits `[B@...`. Paimon 
parses that string as UTF-8 bytes, so a runtime-empty overwrite commits against 
a different partition and leaves an existing `0x4142` partition untouched while 
reporting success. Keep the target in a representation Paimon can round-trip, 
or reject binary values that its string API cannot represent; cover an empty 
binary overwrite in a test. This is distinct from the existing append-only 
VARBINARY thread.



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