-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-23952] remove type parameter in DataReaderFactory #21029
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
55 changes: 55 additions & 0 deletions
55
sql/core/src/main/java/org/apache/spark/sql/sources/v2/DataFormat.java
This file contains hidden or 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,55 @@ | ||
| /* | ||
| * 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.reader.DataReaderFactory; | ||
|
|
||
| /** | ||
| * An enum returned by {@link DataReaderFactory#dataFormat()}, representing the output data format of | ||
| * a data source scan. | ||
| * | ||
| * <ul> | ||
| * <li>{@link #ROW}</li> | ||
| * <li>{@link #UNSAFE_ROW}</li> | ||
| * <li>{@link #COLUMNAR_BATCH}</li> | ||
| * </ul> | ||
| * | ||
| * TODO: add INTERNAL_ROW | ||
| */ | ||
| public enum DataFormat { | ||
| /** | ||
| * Refers to {@link org.apache.spark.sql.Row}, which is very stable and guaranteed to be backward | ||
| * compatible. Spark needs to convert data of row format to the internal format, data source developers | ||
| * should consider using other formats for better performance. | ||
| */ | ||
| ROW, | ||
|
|
||
| /** | ||
| * Refers to {@link org.apache.spark.sql.catalyst.expressions.UnsafeRow}, which is an unstable and | ||
| * internal API. It's already the internal format in Spark, so there is no extra conversion needed. | ||
| */ | ||
| UNSAFE_ROW, | ||
|
|
||
| /** | ||
| * Refers to {@link org.apache.spark.sql.vectorized.ColumnarBatch}, which is a public but experimental | ||
| * API. It's already the internal format in Spark, so there is no extra conversion needed. This format | ||
| * is recommended over others as columnar format has other advantages like vectorization, to further | ||
| * speed up the data processing. | ||
| */ | ||
| COLUMNAR_BATCH | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -20,6 +20,10 @@ | |
| import java.io.Serializable; | ||
|
|
||
| import org.apache.spark.annotation.InterfaceStability; | ||
| import org.apache.spark.sql.Row; | ||
| import org.apache.spark.sql.catalyst.expressions.UnsafeRow; | ||
| import org.apache.spark.sql.sources.v2.DataFormat; | ||
| import org.apache.spark.sql.vectorized.ColumnarBatch; | ||
|
|
||
| /** | ||
| * A reader factory returned by {@link DataSourceReader#createDataReaderFactories()} and is | ||
|
|
@@ -32,7 +36,7 @@ | |
| * serializable and {@link DataReader} doesn't need to be. | ||
| */ | ||
| @InterfaceStability.Evolving | ||
| public interface DataReaderFactory<T> extends Serializable { | ||
| public interface DataReaderFactory extends Serializable { | ||
|
|
||
| /** | ||
| * The preferred locations where the data reader returned by this reader factory can run faster, | ||
|
|
@@ -52,10 +56,46 @@ default String[] preferredLocations() { | |
| } | ||
|
|
||
| /** | ||
| * Returns a data reader to do the actual reading work. | ||
| * The output data format of this factory's data reader. Spark will invoke the corresponding | ||
| * create data reader method w.r.t. the return value of this method: | ||
| * <ul> | ||
| * <li>{@link DataFormat#ROW}: {@link #createRowDataReader()}</li> | ||
| * <li>{@link DataFormat#UNSAFE_ROW}: {@link #createUnsafeRowDataReader()}</li> | ||
| * <li>@{@link DataFormat#COLUMNAR_BATCH}: {@link #createColumnarBatchDataReader()}</li> | ||
| * </ul> | ||
| */ | ||
| DataFormat dataFormat(); | ||
|
Contributor
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. If the data format is determined when the factory is created, then I don't see why it is necessary to change the API. This just makes it more confusing. |
||
|
|
||
| /** | ||
| * Returns a row-formatted data reader to do the actual reading work. | ||
| * | ||
| * If this method fails (by throwing an exception), the corresponding Spark task would fail and | ||
| * get retried until hitting the maximum retry times. | ||
| */ | ||
| default DataReader<Row> createRowDataReader() { | ||
| throw new IllegalStateException( | ||
| "createRowDataReader must be implemented if the data format is ROW."); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a unsafe-row-formatted data reader to do the actual reading work. | ||
| * | ||
| * If this method fails (by throwing an exception), the corresponding Spark task would fail and | ||
| * get retried until hitting the maximum retry times. | ||
| */ | ||
| DataReader<T> createDataReader(); | ||
| default DataReader<UnsafeRow> createUnsafeRowDataReader() { | ||
| throw new IllegalStateException( | ||
| "createUnsafeRowDataReader must be implemented if the data format is UNSAFE_ROW."); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a columnar-batch-formatted data reader to do the actual reading work. | ||
| * | ||
| * If this method fails (by throwing an exception), the corresponding Spark task would fail and | ||
| * get retried until hitting the maximum retry times. | ||
| */ | ||
| default DataReader<ColumnarBatch> createColumnarBatchDataReader() { | ||
| throw new IllegalStateException( | ||
| "createColumnarBatchDataReader must be implemented if the data format is COLUMNAR_BATCH."); | ||
| } | ||
| } | ||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why is this cast necessary?