-
Notifications
You must be signed in to change notification settings - Fork 28.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-29219][SQL] Introduce SupportsCatalogOptions for TableProvider
### What changes were proposed in this pull request? This PR introduces `SupportsCatalogOptions` as an interface for `TableProvider`. Through `SupportsCatalogOptions`, V2 DataSources can implement the two methods `extractIdentifier` and `extractCatalog` to support the creation, and existence check of tables without requiring a formal TableCatalog implementation. We currently don't support all SaveModes for DataSourceV2 in DataFrameWriter.save. The idea here is that eventually File based tables can be written with `DataFrameWriter.save(path)` will create a PathIdentifier where the name is `path`, and the V2SessionCatalog will be able to perform FileSystem checks at `path` to support ErrorIfExists and Ignore SaveModes. ### Why are the changes needed? To support all Save modes for V2 data sources with DataFrameWriter. Since we can now support table creation, we will be able to provide partitioning information when first creating the table as well. ### Does this PR introduce any user-facing change? Introduces a new interface ### How was this patch tested? Will add tests once interface is vetted. Closes #26913 from brkyvz/catalogOptions. Lead-authored-by: Burak Yavuz <brkyvz@gmail.com> Co-authored-by: Burak Yavuz <burak@databricks.com> Signed-off-by: Burak Yavuz <brkyvz@gmail.com>
- Loading branch information
Showing
7 changed files
with
406 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...catalyst/src/main/java/org/apache/spark/sql/connector/catalog/SupportsCatalogOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* 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 org.apache.spark.annotation.Evolving; | ||
import org.apache.spark.sql.util.CaseInsensitiveStringMap; | ||
|
||
/** | ||
* An interface, which TableProviders can implement, to support table existence checks and creation | ||
* through a catalog, without having to use table identifiers. For example, when file based data | ||
* sources use the `DataFrameWriter.save(path)` method, the option `path` can translate to a | ||
* PathIdentifier. A catalog can then use this PathIdentifier to check the existence of a table, or | ||
* whether a table can be created at a given directory. | ||
*/ | ||
@Evolving | ||
public interface SupportsCatalogOptions extends TableProvider { | ||
/** | ||
* Return a {@link Identifier} instance that can identify a table for a DataSource given | ||
* DataFrame[Reader|Writer] options. | ||
* | ||
* @param options the user-specified options that can identify a table, e.g. file path, Kafka | ||
* topic name, etc. It's an immutable case-insensitive string-to-string map. | ||
*/ | ||
Identifier extractIdentifier(CaseInsensitiveStringMap options); | ||
|
||
/** | ||
* Return the name of a catalog that can be used to check the existence of, load, and create | ||
* a table for this DataSource given the identifier that will be extracted by | ||
* {@link #extractIdentifier(CaseInsensitiveStringMap) extractIdentifier}. A `null` value can | ||
* be used to defer to the V2SessionCatalog. | ||
* | ||
* @param options the user-specified options that can identify a table, e.g. file path, Kafka | ||
* topic name, etc. It's an immutable case-insensitive string-to-string map. | ||
*/ | ||
default String extractCatalog(CaseInsensitiveStringMap options) { | ||
return CatalogManager.SESSION_CATALOG_NAME(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.