stevenzwu commented on code in PR #7685: URL: https://github.com/apache/iceberg/pull/7685#discussion_r1202874246
########## 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: Basically, I am saying the 2nd `newOutputFile` from `OutputFileFactory` can behave the same as the first method if the partition object is unpartitioned. ``` /** Generates an {@link EncryptedOutputFile} for unpartitioned writes. */ public EncryptedOutputFile newOutputFile() { OutputFile file = io.newOutputFile(locations.newDataLocation(generateFilename())); return encryptionManager.encrypt(file); } /** Generates an {@link EncryptedOutputFile} for partitioned writes in a given spec. */ public EncryptedOutputFile newOutputFile(PartitionSpec spec, StructLike partition) { String newDataLocation = locations.newDataLocation(spec, partition, generateFilename()); OutputFile rawOutputFile = io.newOutputFile(newDataLocation); return encryptionManager.encrypt(rawOutputFile); } ``` -- 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]
