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


##########
fe/fe-connector/fe-connector-hive/src/main/java/org/apache/doris/connector/hive/HiveWritePlanProvider.java:
##########
@@ -351,6 +359,60 @@ private List<THivePartition> 
buildExistingPartitions(HmsTableInfo table) {
         return partitions;
     }
 
+    private static Optional<String> fullyStaticPartitionName(HmsTableInfo 
table, ConnectorWriteHandle handle) {
+        // Typed partition text can differ between FE literals and BE 
directory formatting (e.g. BOOLEAN
+        // true versus 1). Narrow only string partitions, whose cast values 
are the bytes BE will write.
+        for (ConnectorColumn column : table.getPartitionKeys()) {
+            String type = column.getType().getTypeName();
+            if (!"STRING".equalsIgnoreCase(type) && 
!"VARCHAR".equalsIgnoreCase(type)
+                    && !"CHAR".equalsIgnoreCase(type)) {
+                return Optional.empty();
+            }
+        }
+        // Decide completeness from the literal spec BEFORE asking the handle 
to cast it: a partially specified
+        // write can carry a literal whose FE cast fails even though another 
partition key is dynamic and the
+        // full listing would be used. A missing or SQL NULL key is not a 
fully static write.
+        Map<String, String> literalSpec = new 
TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+        literalSpec.putAll(handle.getStaticPartitionSpec());
+        Set<String> nullKeys = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
+        nullKeys.addAll(handle.getStaticPartitionNullKeys());
+        for (ConnectorColumn column : table.getPartitionKeys()) {
+            if (literalSpec.get(column.getName()) == null || 
nullKeys.contains(column.getName())) {
+                return Optional.empty();
+            }
+        }
+        // The cast is only for the lookup optimization. If the FE cannot 
evaluate it, keep the full
+        // listing and leave the row value to BE, as the existing row path 
does.
+        Map<String, String> castValues;
+        try {
+            castValues = handle.getCastStaticPartitionSpec();

Review Comment:
   [P2] Use the BE row value when narrowing the partition lookup
   
   With `debug_skip_fold_constant=true`, `INSERT OVERWRITE ... PARTITION(p=1e3) 
SELECT ...` on a Hive table with a `STRING` partition key can silently append 
to an existing `p=1000` partition. This independent FE cast renders the decimal 
as `1E+3`, so the singleton request omits `p=1000`. The row cast runs on the BE 
and renders the same decimal as `1000`. `VHiveTableWriter` classifies the 
target as `NEW`, then `HiveConnectorTransaction.finishInsertTable` finds it in 
HMS and appends, keeping the rows the overwrite should replace. Use the full 
listing when a partition value needs a cast whose result can differ from the 
bound row, and cover this overwrite with a cast that executes on the BE.



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