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
[SPARK-29163][SQL] Simplify Hadoop Configuration access in DataSourcev2 #26005
Closed
holdenk
wants to merge
13
commits into
apache:master
from
holdenk:SPARK-29163-simplify-hadoop-conf-access-in-DSv2
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
cabe420
Add a BroadcastedHadoopConf for use in DSv2 sources
holdenk e610a2d
Fix up trait and rewrite parquet to use trait
holdenk c220838
Unify how we make the hadoop conf as well and add the json sourcwe
holdenk 990367b
Move ORC to use the shared trait
holdenk 870bb42
Move CSV over to broadcasted
holdenk f8a6c3a
Add to text source
holdenk e53d086
Generalize the hadoop broadcast beyond scans and simplify the impl a …
holdenk b072c6b
Style standardization of parquetscan
holdenk eb50303
Scan builder style fix
holdenk 2faf4fe
Simplify hook point for the hadoop conf generation a bit more
holdenk d184828
Make the hadoop confs protected per-feedback
holdenk fd847ff
Add back in the withHadoopConfRewrite to allow simpler overriding
holdenk aadd185
Rewrite the interface from Scala to Java :/
holdenk File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
...re/src/main/java/org/apache/spark/sql/execution/datasources/v2/BroadcastedHadoopConf.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,63 @@ | ||
/* | ||
* 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.execution.datasources.v2; | ||
|
||
|
||
import org.apache.hadoop.conf.Configuration; | ||
|
||
import org.apache.spark.SparkContext; | ||
import org.apache.spark.annotation.DeveloperApi; | ||
import org.apache.spark.broadcast.Broadcast; | ||
import org.apache.spark.sql.SparkSession; | ||
import org.apache.spark.sql.util.CaseInsensitiveStringMap; | ||
import org.apache.spark.util.SerializableConfiguration; | ||
|
||
import java.util.Map; | ||
|
||
import scala.reflect.ClassTag; | ||
/** | ||
* A helper interface to serialize and broadcast the Hadoop configuration for readers. | ||
*/ | ||
@DeveloperApi | ||
public interface BroadcastedHadoopConf { | ||
SparkSession sparkSession(); | ||
CaseInsensitiveStringMap options(); | ||
|
||
/** | ||
* Override this if you need to rewrite your Hadoop configuration differently | ||
*/ | ||
default Configuration withHadoopConfRewrite(Configuration hadoopConf) { | ||
return hadoopConf; | ||
} | ||
|
||
/** | ||
* Override this if you need to generate your Hadoop configuration differently | ||
*/ | ||
default Configuration hadoopConf() { | ||
// Hadoop Configurations are case sensitive. | ||
Map<String, String> caseSensitiveMap = options().asCaseSensitiveMap(); | ||
return withHadoopConfRewrite( | ||
sparkSession().sessionState().newHadoopConfWithOptions(caseSensitiveMap)); | ||
} | ||
|
||
default Broadcast<SerializableConfiguration> broadcastedConf() { | ||
SparkContext sc = sparkSession().sparkContext(); | ||
SerializableConfiguration config = new SerializableConfiguration(hadoopConf()); | ||
ClassTag<SerializableConfiguration> tag = ClassTag.apply(SerializableConfiguration.class); | ||
return sc.broadcast(config, tag); | ||
} | ||
} |
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
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
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
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.
I don't think that the data source should be responsible for providing a SparkSession. Spark has a session and configures the data source.
I think this interface should allow Spark to pass a broadcasted Hadoop Configuration to the source instead.
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 don't think I understand what you mean here, could you try and rephrase it? Sorry.
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.
To clarify: do you mean you want us to use reflection for something implementing this interface inside of the DSv2 code path? Or do you mean something else?
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.
Data sources aren't passed a Spark session, so it doesn't make sense that this interface requires the source to provide one. If we think sources need access to a Spark session, then we should add an interface that sets the session directly. (I know the built-in sources have one, but that's because those are v1 sources that have been slightly modified to fit into v2.)
The benefit of having an interface like this is to avoid needing the Spark session. That's currently done by accessing the Spark session from the environment (e.g.
SparkSession.builder.getOrCreate()
) and we want to avoid making sources do that.That's why I think the way this works should be to set a broadcasted configuration on a
Table
implementation that extends this interface using a method likesetBroadcastedConf
.I'm on ASF slack if you'd like to talk about this more directly.
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.
Ok so we did a quick chat. It’s possible that this and one other small use case are the only reasons the sources currently have a Spark Session inside of them and the design goal
of DSv2 was to get rid of that. So I’ll see if this can be avoided, but if it’s more than broadcasting the Hadoop conf and case sensitive options then I’ll switch the API to just pass in a Spark session and we can stick with this API. Does that sound like a reasonable summary @rdblue?