cloud-fan commented on a change in pull request #23086: [SPARK-25528][SQL] data
source v2 API refactor (batch read)
URL: https://github.com/apache/spark/pull/23086#discussion_r267927761
##########
File path: sql/core/src/main/scala/org/apache/spark/sql/DataFrameReader.scala
##########
@@ -194,20 +194,26 @@ class DataFrameReader private[sql](sparkSession:
SparkSession) extends Logging {
}
val cls = DataSource.lookupDataSource(source,
sparkSession.sessionState.conf)
- if (classOf[DataSourceV2].isAssignableFrom(cls)) {
- val ds = cls.getConstructor().newInstance().asInstanceOf[DataSourceV2]
- if (ds.isInstanceOf[BatchReadSupportProvider]) {
- val sessionOptions = DataSourceV2Utils.extractSessionConfigs(
- ds = ds, conf = sparkSession.sessionState.conf)
- val pathsOption = {
- val objectMapper = new ObjectMapper()
- DataSourceOptions.PATHS_KEY ->
objectMapper.writeValueAsString(paths.toArray)
- }
- Dataset.ofRows(sparkSession, DataSourceV2Relation.create(
- ds, sessionOptions ++ extraOptions.toMap + pathsOption,
- userSpecifiedSchema = userSpecifiedSchema))
- } else {
- loadV1Source(paths: _*)
+ if (classOf[TableProvider].isAssignableFrom(cls)) {
+ val provider =
cls.getConstructor().newInstance().asInstanceOf[TableProvider]
+ val sessionOptions = DataSourceV2Utils.extractSessionConfigs(
+ ds = provider, conf = sparkSession.sessionState.conf)
+ val pathsOption = {
+ val objectMapper = new ObjectMapper()
+ DataSourceOptions.PATHS_KEY ->
objectMapper.writeValueAsString(paths.toArray)
+ }
+ val finalOptions = sessionOptions ++ extraOptions.toMap + pathsOption
+ val dsOptions = new DataSourceOptions(finalOptions.asJava)
+ val table = userSpecifiedSchema match {
+ case Some(schema) => provider.getTable(dsOptions, schema)
+ case _ => provider.getTable(dsOptions)
+ }
+ table match {
+ case s: SupportsBatchRead =>
+ Dataset.ofRows(sparkSession, DataSourceV2Relation.create(
+ provider, s, finalOptions, userSpecifiedSchema =
userSpecifiedSchema))
+
+ case _ => loadV1Source(paths: _*)
Review comment:
things have changed now with the table capability API. Please check the new
code.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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]