aokolnychyi commented on code in PR #7685: URL: https://github.com/apache/iceberg/pull/7685#discussion_r1207063167
########## core/src/main/java/org/apache/iceberg/io/PartitionProjection.java: ########## @@ -0,0 +1,99 @@ +/* + * 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.io; + +import org.apache.iceberg.PartitionSpec; +import org.apache.iceberg.StructLike; +import org.apache.iceberg.types.Types; +import org.apache.iceberg.util.StructProjection; + +public interface PartitionProjection extends StructLike { + + PartitionProjection create(PartitionSpec spec, Types.StructType commonPartitionType); + + PartitionProjection wrap(StructLike newStruct); + + static PartitionProjection of(PartitionSpec spec, Types.StructType commonPartitionType) { + if (spec.isUnpartitioned()) { + return UnpartitionedSpecProjection.INSTANCE; + } else { + return new PartitionedSpecProjection().create(spec, commonPartitionType); + } + } + + class UnpartitionedSpecProjection implements PartitionProjection { + static final PartitionProjection INSTANCE = new UnpartitionedSpecProjection(); + + @Override + public PartitionProjection create(PartitionSpec spec, Types.StructType commonPartitionType) { + return this; + } + + @Override + public PartitionProjection wrap(StructLike newStruct) { + return null; Review Comment: If we want always null, I think adding `PartitionProjection` is reasonable to avoid if/else in tight loops and to reuse this logic in other places. That said, we know our file builders will always set null for unpartitioned tables. We only need to fix our writers. What if we fix `RollingFileWriter`? It currently checks `partition == null`. ``` private EncryptedOutputFile newFile() { if (partition == null) { return fileFactory.newOutputFile(); } else { return fileFactory.newOutputFile(spec, partition); } } ``` We could replace it with `spec.isUnpartitioned()`. I also don't mind adding an extra branch to `OutputFileFactory` to be safe but I guess that's optional. -- 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]
