-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[SPARK-26811][SQL] Add capabilities to v2.Table #24012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,16 +20,15 @@ | |
import org.apache.spark.annotation.Evolving; | ||
import org.apache.spark.sql.types.StructType; | ||
|
||
import java.util.Set; | ||
|
||
/** | ||
* An interface representing a logical structured data set of a data source. For example, the | ||
* implementation can be a directory on the file system, a topic of Kafka, or a table in the | ||
* catalog, etc. | ||
* <p> | ||
* This interface can mixin the following interfaces to support different operations: | ||
* </p> | ||
* <ul> | ||
* <li>{@link SupportsBatchRead}: this table can be read in batch queries.</li> | ||
* </ul> | ||
* This interface can mixin the following interfaces to support different operations, like | ||
* {@code SupportsRead}. | ||
*/ | ||
@Evolving | ||
public interface Table { | ||
|
@@ -45,4 +44,9 @@ public interface Table { | |
* empty schema can be returned here. | ||
*/ | ||
StructType schema(); | ||
|
||
/** | ||
* Returns the set of capabilities for this table. | ||
*/ | ||
Set<TableCapability> capabilities(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we will have tons of capabilities, maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's a good idea to use an array when the storage should be a set, just because it is necessary to call |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* 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.annotation.Experimental; | ||
|
||
/** | ||
* Capabilities that can be provided by a {@link Table} implementation. | ||
* <p> | ||
* Tables use {@link Table#capabilities()} to return a set of capabilities. Each capability signals | ||
* to Spark that the table supports a feature identified by the capability. For example, returning | ||
* {@code BATCH_READ} allows Spark to read from the table using a batch scan. | ||
*/ | ||
@Experimental | ||
public enum TableCapability { | ||
/** | ||
* Signals that the table supports reads in batch execution mode. | ||
*/ | ||
BATCH_READ, | ||
|
||
/** | ||
* Signals that the table supports append writes in batch execution mode. | ||
* <p> | ||
* Tables that return this capability must support appending data and may also support additional | ||
* write modes, like {@link #TRUNCATE}, {@link #OVERWRITE_BY_FILTER}, and | ||
* {@link #OVERWRITE_DYNAMIC}. | ||
*/ | ||
BATCH_WRITE, | ||
|
||
/** | ||
* Signals that the table can be truncated in a write operation. | ||
* <p> | ||
* Truncating a table removes all existing rows. | ||
* <p> | ||
* See {@link org.apache.spark.sql.sources.v2.writer.SupportsTruncate}. | ||
*/ | ||
TRUNCATE, | ||
|
||
/** | ||
* Signals that the table can replace existing data that matches a filter with appended data in | ||
* a write operation. | ||
* <p> | ||
* See {@link org.apache.spark.sql.sources.v2.writer.SupportsOverwrite}. | ||
*/ | ||
OVERWRITE_BY_FILTER, | ||
|
||
/** | ||
* Signals that the table can dynamically replace existing data partitions with appended data in | ||
* a write operation. | ||
* <p> | ||
* See {@link org.apache.spark.sql.sources.v2.writer.SupportsDynamicOverwrite}. | ||
*/ | ||
OVERWRITE_DYNAMIC | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we remove this interface as well? We can move
newScanBuilder
to table and throw exception by default. Tables that reports batch/stream scan capability should overwritenewScanBuilder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like having this because it maintains separation between the read/write API and the catalog API. We could update the read and write API later or add a new one by adding a different read trait, without changing how catalogs and tables work. So I think it is worth keeping
SupportsRead
andSupportsWrite
.