singhpk234 commented on code in PR #5707:
URL: https://github.com/apache/iceberg/pull/5707#discussion_r963776786


##########
core/src/main/java/org/apache/iceberg/TableMetadataParser.java:
##########
@@ -380,7 +380,12 @@ static TableMetadata fromJson(FileIO io, String 
metadataLocation, JsonNode node)
       // parse the spec array
       ImmutableList.Builder<PartitionSpec> builder = ImmutableList.builder();
       for (JsonNode spec : specArray) {
-        builder.add(PartitionSpecParser.fromJson(schema, spec));
+        UnboundPartitionSpec unboundSpec = PartitionSpecParser.fromJson(spec);
+        if (unboundSpec.specId() == defaultSpecId) {
+          builder.add(unboundSpec.bind(schema));

Review Comment:
   Apologies for not being clear, 
   What I meant here was, mapping the current schema to the current spec might 
still cause issue as in case of tables of V1 format, (Considering the UT in 
this PR, last DDL) The current spec will have a `void` transform for 
`day_of_ts` since `day_of_ts` is dropped from partitioning (in V1 format, we 
replace this transform with a `void` transform). Now when we attempt to bind 
current partition spec with current schema, current schema will not have 
`day_of_ts`, but in `PartitionSpec#checkCompatibility` we will try to find 
`schema.findType(field.sourceId())`, from current schema for `void` transform 
of `day_of_ts` and it will fail, as we have removed `day_of_ts` from current 
schema.
   
   
   A sample UT for repro (modified from this PR) : 
   
   ```java
     @Test
     public void testDropColumnOfOldPartitionField() {
       // default table created in v1 format
       sql(
           "CREATE TABLE %s (id bigint NOT NULL, ts timestamp, day_of_ts date) 
USING iceberg PARTITIONED BY (day_of_ts)",
           tableName);
   
       sql("ALTER TABLE %s REPLACE PARTITION FIELD day_of_ts WITH days(ts)", 
tableName);
       sql("ALTER TABLE %s DROP COLUMN day_of_ts", tableName);
     }
   ```



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