cloud-fan commented on a change in pull request #23208: [SPARK-25530][SQL] data source v2 API refactor (batch write) URL: https://github.com/apache/spark/pull/23208#discussion_r246627698
########## File path: sql/core/src/main/java/org/apache/spark/sql/sources/v2/SupportsWrite.java ########## @@ -0,0 +1,43 @@ +/* + * 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.sources.v2; + +import org.apache.spark.sql.sources.v2.writer.BatchWrite; +import org.apache.spark.sql.sources.v2.writer.WriteBuilder; +import org.apache.spark.sql.types.StructType; + +/** + * An internal base interface of mix-in interfaces for writable {@link Table}. This adds + * {@link #newWriteBuilder(String, StructType, DataSourceOptions)} that is used to create a write + * for batch or streaming. + */ +interface SupportsWrite extends Table { + + /** + * Returns a {@link WriteBuilder} which can be used to create {@link BatchWrite}. Spark will call + * this method to configure each data source write. + * + * @param queryId A unique string of the writing query. It's possible that there are many + * writing queries running at the same time, or a query is restarted and resumed. + * {@link BatchWrite} can use this id to identify the query. + * @param schema The schema of the data to write. + * @param options The options for writing, which is an immutable case-insensitive + * string-to-string map. + */ + WriteBuilder newWriteBuilder(String queryId, StructType schema, DataSourceOptions options); Review comment: This is consistent with the read API, `newScanBuilder(DataSourceOptions options)` I don't see a clear win of putting `withQueryId`, `withSchema` and `withOptions` in `WriteBuilder`. If we want to add more things in the future, we should create new mixin traits for `WriteBuilder`, instead of adding more methods to the base `WriteBuilder`. Also, we can't remove methods in `WriteBuilder` later on, as it's a breaking change, even if the method has a default implementation. cc @rxin @rdblue @gatorsmile ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
