KnightChess commented on a change in pull request #3459:
URL: https://github.com/apache/iceberg/pull/3459#discussion_r755105296



##########
File path: 
spark/v3.2/spark/src/main/java/org/apache/iceberg/spark/source/SparkTable.java
##########
@@ -315,23 +320,38 @@ public void deleteWhere(Filter[] filters) {
   public StructType partitionSchema() {
     if (lazyPartitionSchema == null) {
       Table table = table();
-      PartitionsTable partitionsTable =
-          (PartitionsTable) 
MetadataTableUtils.createMetadataTableInstance(table, 
MetadataTableType.PARTITIONS);
-      Types.NestedField partition = 
partitionsTable.schema().findField("partition");
-      if (partition != null) {
-        this.lazyPartitionSchema = (StructType) 
SparkSchemaUtil.convert(partition.type());
+      PartitionSpec spec = table.spec();
+      if (spec != null) {
+        // type always String when transform is void
+        List<PartitionField> fields = spec.fields();
+        Types.StructType structType = spec.partitionType();
+        List<Types.NestedField> fieldsType = structType.fields();
+        StructField[] structFields = new StructField[fields.size()];
+
+        for (int i = 0; i < fields.size(); ++i) {
+          PartitionField partitionField = fields.get(i);
+          Types.NestedField nestedField = fieldsType.get(i);
+          if ("void".equals(partitionField.transform().toString())) {
+            structFields[i] = StructField.apply(nestedField.name(), 
DataTypes.StringType, nestedField.isOptional(),
+                Metadata.empty());
+          } else {
+            structFields[i] = StructField.apply(nestedField.name(), 
SparkSchemaUtil.convert(nestedField.type()),
+                nestedField.isOptional(), Metadata.empty());
+          }

Review comment:
       for compatible history, the field type always String when transform is 
void.( It seems to only timestamp that's going to be a problem when evolution




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