RussellSpitzer commented on code in PR #12327:
URL: https://github.com/apache/iceberg/pull/12327#discussion_r1962474190


##########
spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/procedures/AddFilesProcedure.java:
##########
@@ -196,11 +193,36 @@ private void importFileTable(
       String format,
       Map<String, String> partitionFilter,
       boolean checkDuplicateFiles,
-      PartitionSpec spec,
       int parallelism) {
+
+    org.apache.spark.sql.execution.datasources.PartitionSpec inferredSpec =
+        getInferredSpec(spark(), tableLocation);
+
+    List<String> sparkPartNames =
+        JavaConverters.seqAsJavaList(inferredSpec.partitionColumns()).stream()
+            .map(StructField::name)
+            .map(name -> name.toLowerCase(Locale.ROOT))
+            .collect(Collectors.toList());
+    PartitionSpec matchingSpec = null;
+    for (PartitionSpec icebergSpec : table.specs().values()) {
+      List<String> icebergPartNames =
+          icebergSpec.fields().stream()
+              .map(PartitionField::name)
+              .map(name -> name.toLowerCase(Locale.ROOT))
+              .collect(Collectors.toList());
+      if (icebergPartNames.equals(sparkPartNames)) {
+        matchingSpec = icebergSpec;
+        break;
+      }
+    }
+    if (matchingSpec == null) {
+      // If the inferred spec does not match any existing spec, use the 
Iceberg table's latest spec
+      matchingSpec = table.spec();

Review Comment:
   I think this is an error case



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