mxm commented on code in PR #12424: URL: https://github.com/apache/iceberg/pull/12424#discussion_r1980978055
########## flink/v1.20/flink/src/main/java/org/apache/iceberg/flink/sink/dynamic/PartitionSpecAdjustment.java: ########## @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iceberg.flink.sink.dynamic; + +import org.apache.iceberg.PartitionField; +import org.apache.iceberg.PartitionSpec; +import org.apache.iceberg.Schema; +import org.apache.iceberg.UnboundPartitionSpec; + +public class PartitionSpecAdjustment { + + private PartitionSpecAdjustment() {} + + public static PartitionSpec adjustPartitionSpecToTableSchema( + Schema tableSchema, PartitionSpec userSpec) { + if (userSpec.isUnpartitioned()) { + return userSpec; + } + UnboundPartitionSpec.Builder builder = Review Comment: The input spec is what the user provides in DynamicRecord. The input schema is built by the user, e.g. from an Avro schema, and can be different form the actual Iceberg schema, e.g. the ids used don't necessarily have to match with the ids in the Iceberg schema, new fields added, etc.. The same goes for the PartitionSpec, it is bound to the input schema and references source ids which don't necessarily match with the Iceberg schema. Given these constraints, to still be able to meaningfully evolve the schema, the logic around schema / spec evolution uses field names, not field ids. This is a decision we took after running PoCs with multiple customers. In the future, we might add a "strict" mode, which uses field ids, but so far customers consistently wanted name-based schema / spec evolution. The goal is to translate the input schema / spec such that they **either** match with one of the existing schema / spec ([check for schema](https://github.com/apache/iceberg/blob/d7e65c833e19169388d4e9173d3cb4f1971b6519/flink/v1.20/flink/src/main/java/org/apache/iceberg/flink/sink/dynamic/TableDataCache.java#L115) / [check for spec](https://github.com/apache/iceberg/blob/d7e65c833e19169388d4e9173d3cb4f1971b6519/flink/v1.20/flink/src/main/java/org/apache/iceberg/flink/sink/dynamic/TableDataCache.java#L149)), **or** update the table schema / spec with the minimal amount of changes required. If we didn't adapt the input schema / spec to table schema or the other existing schemas, we would go through a schema / spec change for every record. Not good for table metadata or catalog access / performance. We would also "lose" fields as soon as their ids changed. --- >if you have a unit test to demonstrate the scenario, please point it here. Here is an example where we test compatibility of spec1 (the input spec) to spec2 (table spec). No spec update will be performance in this case: https://github.com/apache/iceberg/blob/d7e65c833e19169388d4e9173d3cb4f1971b6519/flink/v1.20/flink/src/test/java/org/apache/iceberg/flink/sink/dynamic/TestPartitionSpecEvolution.java#L74 Here is the same test, but we change the spec because its buckets changed: https://github.com/apache/iceberg/blob/d7e65c833e19169388d4e9173d3cb4f1971b6519/flink/v1.20/flink/src/test/java/org/apache/iceberg/flink/sink/dynamic/TestPartitionSpecEvolution.java#L96 -- 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: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org