rdblue commented on a change in pull request #28617: URL: https://github.com/apache/spark/pull/28617#discussion_r459657638
########## File path: sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/SupportsPartitions.java ########## @@ -0,0 +1,105 @@ +/* + * 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.spark.sql.connector.catalog; + +import java.util.Map; + +import org.apache.spark.annotation.Experimental; + +/** + * Catalog methods for working with Partitions. + */ +@Experimental +public interface SupportsPartitions extends TableCatalog { + + /** + * Create partitions in an existing table, assuming it exists. + * + * @param ident a table identifier + * @param partitions transforms to use for partitioning data in the table + * @param ignoreIfExists + */ + void createPartitions( + Identifier ident, + TablePartition[] partitions, + Boolean ignoreIfExists); + + /** + * Drop partitions from a table, assuming they exist. + * + * @param ident a table identifier + * @param partitions a list of string map for existing partitions + * @param ignoreIfNotExists + */ + void dropPartitions( + Identifier ident, + Map<String, String>[] partitions, Review comment: I think we need to decide how to pass the data that identifies a partition. There have been a _lot_ of problems over the years working with Hive partitions because values are coerced to and from String. Often, people get the conversions slightly wrong. I think a better approach is to use a row of values to pass partition data between Spark and a source. We already pass typed rows in the read and write APIs, so it would be reasonable to do so here as well. One benefit of using a typed row to represent partition data is that we can directly use a `listPartitions` call for metadata queries. This would also align more closely with how Spark handles partitions internally. From PartitioningUtils: ``` /** * Holds a directory in a partitioned collection of files as well as the partition values * in the form of a Row. Before scanning, the files at `path` need to be enumerated. */ case class PartitionPath(values: InternalRow, path: Path) case class PartitionSpec( partitionColumns: StructType, partitions: Seq[PartitionPath]) ``` A table that implements `SupportsPartitions` could return a `partitionType(): StructType` that describes the partition rows it accepts and produces. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
