holdenk commented on a change in pull request #33008: URL: https://github.com/apache/spark/pull/33008#discussion_r658183846
########## File path: sql/catalyst/src/main/java/org/apache/spark/sql/connector/write/Merge.java ########## @@ -0,0 +1,85 @@ +/* + * 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.write; + +import org.apache.spark.annotation.Experimental; +import org.apache.spark.sql.connector.expressions.NamedReference; +import org.apache.spark.sql.connector.read.Scan; +import org.apache.spark.sql.connector.read.ScanBuilder; + +/** + * A logical representation of a data source DELETE, UPDATE, or MERGE operation that requires + * rewriting data. + * + * @since 3.2.0 + */ +@Experimental +public interface Merge { + + /** + * The actual SQL operation being performed. + */ + enum Operation { + DELETE, UPDATE, MERGE + } + + /** + * Returns the description associated with this merge. + */ + default String description() { + return this.getClass().toString(); + } + + /** + * Returns the actual SQL operation being performed. + */ + Operation operation(); + + /** + * Returns a {@link ScanBuilder} to configure a {@link Scan} for this merge. + * <p> + * For sources that support row-level changes, there are no requirements for input scans, + * but sources that delete by group must be passed a complete replacement of groups. + * This means that scans must produce all rows in a delete group if any are returned. + * <p> + * For example, if a source can only replace partitions, all rows from a partition must + * be returned by the scan, even if a filter can narrow the set of changes to a single file + * in the partition. Similarly, a source that can swap individual files must produce all rows + * of matching files, not just the rows that may change. + */ + ScanBuilder scanBuilder(); Review comment: One question here is how we handle the situation where there is a mutation after the scan has completed. I'm assuming we leave this up to the catalog to handle but might be nice to call out here? ########## File path: sql/catalyst/src/main/java/org/apache/spark/sql/connector/write/SupportsDelta.java ########## @@ -0,0 +1,35 @@ +/* + * 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.write; + +import org.apache.spark.annotation.Experimental; +import org.apache.spark.sql.connector.expressions.NamedReference; + +/** + * A mix-in interface for {@link Merge}. Data sources can implement this interface to indicate + * they support row-level changes. + * + * @since 3.2.0 + */ +@Experimental +public interface SupportsDelta extends Merge { + /** + * Returns the row ID column references that should be used for row equality. + */ + NamedReference[] rowId(); Review comment: What about SQL interfaces where there is a combined key? -- 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]
