You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "stevenzwu (via GitHub)" <gi...@apache.org> on 2023/05/23 15:54:43 UTC

[GitHub] [iceberg] stevenzwu commented on a diff in pull request #7685: Spark: Positional deletes creates partitioned path on unpartitioned tables

stevenzwu commented on code in PR #7685:
URL: https://github.com/apache/iceberg/pull/7685#discussion_r1202608982


##########
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:
   I traced through the code. this seems to be the relevant fix.
   
   It tries to influence the `OutputFileFactory`, which then calls `LocationProvider` interface.
   ```
     public EncryptedOutputFile newOutputFile(PartitionSpec spec, StructLike partition) {
       String newDataLocation = locations.newDataLocation(spec, partition, generateFilename());
       OutputFile rawOutputFile = io.newOutputFile(newDataLocation);
       return encryptionManager.encrypt(rawOutputFile);
     }
   ```
   
   I am wondering if the fix should be done in `OutputFileFactory`. If it is unpartitioned spec, it should call the other `newDataLocation` method without partition from `LocationProvider` interface.
   ```
     /**
      * Return a fully-qualified data file location for the given filename.
      *
      * @param filename a file name
      * @return a fully-qualified location URI for a data file
      */
     String newDataLocation(String filename);
   
     /**
      * Return a fully-qualified data file location for the given partition and filename.
      *
      * @param spec a partition spec
      * @param partitionData a tuple of partition data for data in the file, matching the given spec
      * @param filename a file name
      * @return a fully-qualified location URI for a data file
      */
     String newDataLocation(PartitionSpec spec, StructLike partitionData, String filename);
   ```
   



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org