marton-bod commented on a change in pull request #2137:
URL: https://github.com/apache/hive/pull/2137#discussion_r609503889



##########
File path: 
iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergSerDe.java
##########
@@ -77,15 +85,26 @@ public void initialize(@Nullable Configuration 
configuration, Properties serDePr
 
     if (serDeProperties.get(InputFormatConfig.TABLE_SCHEMA) != null) {
       this.tableSchema = SchemaParser.fromJson((String) 
serDeProperties.get(InputFormatConfig.TABLE_SCHEMA));
+      if (serDeProperties.get(InputFormatConfig.PARTITION_SPEC) != null) {
+        PartitionSpec spec =
+            PartitionSpecParser.fromJson(tableSchema, (String) 
serDeProperties.get(InputFormatConfig.PARTITION_SPEC));
+        this.partitionColumns = 
spec.fields().stream().map(PartitionField::name).collect(Collectors.toList());
+      } else {
+        this.partitionColumns = ImmutableList.of();
+      }
     } else {
       try {
         // always prefer the original table schema if there is one
-        this.tableSchema = Catalogs.loadTable(configuration, 
serDeProperties).schema();
+        Table table = Catalogs.loadTable(configuration, serDeProperties);
+        this.tableSchema = table.schema();
+        this.partitionColumns = 
table.spec().fields().stream().map(PartitionField::name).collect(Collectors.toList());
         LOG.info("Using schema from existing table {}", 
SchemaParser.toJson(tableSchema));
       } catch (Exception e) {
         boolean autoConversion = 
configuration.getBoolean(InputFormatConfig.SCHEMA_AUTO_CONVERSION, false);
         // If we can not load the table try the provided hive schema
         this.tableSchema = hiveSchemaOrThrow(serDeProperties, e, 
autoConversion);
+        // This is only for table creation, it is ok to have an empty 
partition column list

Review comment:
       This comment reminds me: can we make it clear earlier at the beginning 
of the catch block, that we expect to get to this catch block only in table 
creation scenarios? I think that'd make it clearer why we're not rethrowing the 
exception and processing things in an alternative way




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

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