RussellSpitzer commented on a change in pull request #3459:
URL: https://github.com/apache/iceberg/pull/3459#discussion_r745811355



##########
File path: 
spark/v3.2/spark/src/main/java/org/apache/iceberg/spark/source/SparkTable.java
##########
@@ -298,6 +311,103 @@ public void deleteWhere(Filter[] filters) {
     }
   }
 
+  @Override
+  public StructType partitionSchema() {
+    if (lazyPartitionSchema == null) {
+      Table table = table();
+      PartitionsTable partitionsTable =
+          (PartitionsTable) 
MetadataTableUtils.createMetadataTableInstance(table, 
MetadataTableType.PARTITIONS);
+      Types.NestedField partition = 
partitionsTable.schema().findField("partition");
+      if (partition != null) {
+        this.lazyPartitionSchema = (StructType) 
SparkSchemaUtil.convert(partition.type());
+      } else {
+        this.lazyPartitionSchema = new StructType();
+      }
+    }
+
+    return lazyPartitionSchema;
+  }
+
+  @Override
+  public void createPartition(InternalRow ident, Map<String, String> 
properties)
+      throws UnsupportedOperationException {
+    throw new UnsupportedOperationException("Cannot create partition: 
partitions exist only when there are rows");
+  }
+
+  @Override
+  public boolean dropPartition(InternalRow ident) {
+    throw new UnsupportedOperationException("Cannot drop partition: not 
implemented");
+  }
+
+  @Override
+  public void replacePartitionMetadata(InternalRow ident, Map<String, String> 
properties)
+      throws UnsupportedOperationException {
+    throw new UnsupportedOperationException("Cannot replace partition 
metadata: partition metadata is only related to" +

Review comment:
       Here I would just say "Iceberg partitions do not support metadata"

##########
File path: 
spark/v3.2/spark/src/main/java/org/apache/iceberg/spark/source/SparkTable.java
##########
@@ -298,6 +311,103 @@ public void deleteWhere(Filter[] filters) {
     }
   }
 
+  @Override
+  public StructType partitionSchema() {
+    if (lazyPartitionSchema == null) {
+      Table table = table();
+      PartitionsTable partitionsTable =
+          (PartitionsTable) 
MetadataTableUtils.createMetadataTableInstance(table, 
MetadataTableType.PARTITIONS);
+      Types.NestedField partition = 
partitionsTable.schema().findField("partition");
+      if (partition != null) {
+        this.lazyPartitionSchema = (StructType) 
SparkSchemaUtil.convert(partition.type());
+      } else {
+        this.lazyPartitionSchema = new StructType();
+      }
+    }
+
+    return lazyPartitionSchema;
+  }
+
+  @Override
+  public void createPartition(InternalRow ident, Map<String, String> 
properties)
+      throws UnsupportedOperationException {
+    throw new UnsupportedOperationException("Cannot create partition: 
partitions exist only when there are rows");
+  }
+
+  @Override
+  public boolean dropPartition(InternalRow ident) {
+    throw new UnsupportedOperationException("Cannot drop partition: not 
implemented");
+  }
+
+  @Override
+  public void replacePartitionMetadata(InternalRow ident, Map<String, String> 
properties)
+      throws UnsupportedOperationException {
+    throw new UnsupportedOperationException("Cannot replace partition 
metadata: partition metadata is only related to" +
+        " data files");
+  }
+
+  @Override
+  public Map<String, String> loadPartitionMetadata(InternalRow ident) throws 
UnsupportedOperationException {
+    throw new UnsupportedOperationException("Cannot load partition metadata: 
not implemented");
+  }
+
+  @Override
+  public InternalRow[] listPartitionIdentifiers(String[] names, InternalRow 
ident) {
+    StructType partitionSchema = partitionSchema();
+    if (partitionSchema.isEmpty()) {

Review comment:
       V1 Void Transforms strike again here, Let's make sure we are correctly 
returning "empty" from partitionSchema when we get those void's.

##########
File path: 
spark/v3.2/spark/src/main/java/org/apache/iceberg/spark/source/SparkTable.java
##########
@@ -298,6 +311,103 @@ public void deleteWhere(Filter[] filters) {
     }
   }
 
+  @Override
+  public StructType partitionSchema() {
+    if (lazyPartitionSchema == null) {
+      Table table = table();
+      PartitionsTable partitionsTable =
+          (PartitionsTable) 
MetadataTableUtils.createMetadataTableInstance(table, 
MetadataTableType.PARTITIONS);
+      Types.NestedField partition = 
partitionsTable.schema().findField("partition");
+      if (partition != null) {
+        this.lazyPartitionSchema = (StructType) 
SparkSchemaUtil.convert(partition.type());
+      } else {
+        this.lazyPartitionSchema = new StructType();
+      }
+    }
+
+    return lazyPartitionSchema;
+  }
+
+  @Override
+  public void createPartition(InternalRow ident, Map<String, String> 
properties)
+      throws UnsupportedOperationException {
+    throw new UnsupportedOperationException("Cannot create partition: 
partitions exist only when there are rows");

Review comment:
       I find this a little confusing. Perhaps "partitions are created 
implicitly when inserting new rows into iceberg tables"?

##########
File path: 
spark/v3.2/spark/src/test/java/org/apache/iceberg/spark/sql/TestPartitionSQL.java
##########
@@ -0,0 +1,150 @@
+/*
+ * 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.spark.sql;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.AssertHelpers;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
+import org.apache.iceberg.spark.SparkCatalogTestBase;
+import org.apache.spark.sql.AnalysisException;
+import org.junit.After;
+import org.junit.Test;
+
+public class TestPartitionSQL extends SparkCatalogTestBase {
+
+  public TestPartitionSQL(String catalogName, String implementation, 
Map<String, String> config) {
+    super(catalogName, implementation, config);
+  }
+
+  @After
+  public void removeTables() {
+    sql("DROP TABLE IF EXISTS %s", tableName);
+  }
+

Review comment:
       let's add in a few tests for showing partitions of a table which has had 
it's partitioning altered.
   
   Specifically we should hit
   
   1. A table which was partitioned but is now no longer partitioned 
(voidTransforms)
   2. Adding a partition column
   3. Changing a partition column type with a compatible transform, going from 
hours -> days 
   
   Any thing else you can think of here

##########
File path: 
spark/v3.2/spark/src/main/java/org/apache/iceberg/spark/source/SparkTable.java
##########
@@ -298,6 +311,103 @@ public void deleteWhere(Filter[] filters) {
     }
   }
 
+  @Override
+  public StructType partitionSchema() {
+    if (lazyPartitionSchema == null) {
+      Table table = table();
+      PartitionsTable partitionsTable =
+          (PartitionsTable) 
MetadataTableUtils.createMetadataTableInstance(table, 
MetadataTableType.PARTITIONS);
+      Types.NestedField partition = 
partitionsTable.schema().findField("partition");
+      if (partition != null) {
+        this.lazyPartitionSchema = (StructType) 
SparkSchemaUtil.convert(partition.type());
+      } else {
+        this.lazyPartitionSchema = new StructType();
+      }
+    }
+
+    return lazyPartitionSchema;
+  }
+
+  @Override
+  public void createPartition(InternalRow ident, Map<String, String> 
properties)
+      throws UnsupportedOperationException {
+    throw new UnsupportedOperationException("Cannot create partition: 
partitions exist only when there are rows");
+  }
+
+  @Override
+  public boolean dropPartition(InternalRow ident) {
+    throw new UnsupportedOperationException("Cannot drop partition: not 
implemented");
+  }
+
+  @Override
+  public void replacePartitionMetadata(InternalRow ident, Map<String, String> 
properties)
+      throws UnsupportedOperationException {
+    throw new UnsupportedOperationException("Cannot replace partition 
metadata: partition metadata is only related to" +
+        " data files");
+  }
+
+  @Override
+  public Map<String, String> loadPartitionMetadata(InternalRow ident) throws 
UnsupportedOperationException {
+    throw new UnsupportedOperationException("Cannot load partition metadata: 
not implemented");

Review comment:
       Same as above




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