Github user chenghao-intel commented on a diff in the pull request:
https://github.com/apache/spark/pull/7802#discussion_r36497565
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/ddl.scala ---
@@ -190,37 +194,31 @@ private[sql] class DDLParser(
}
}
-private[sql] object ResolvedDataSource {
+private[sql] object ResolvedDataSource extends Logging {
- private val builtinSources = Map(
- "jdbc" -> "org.apache.spark.sql.jdbc.DefaultSource",
- "json" -> "org.apache.spark.sql.json.DefaultSource",
- "parquet" -> "org.apache.spark.sql.parquet.DefaultSource",
- "orc" -> "org.apache.spark.sql.hive.orc.DefaultSource"
- )
+ /** Tries to load the particular class */
+ private def tryLoad(loader: ClassLoader, provider: String):
Option[Class[_]] = try {
+ Some(loader.loadClass(provider))
+ } catch {
+ case cnf: ClassNotFoundException => None
+ }
/** Given a provider name, look up the data source class definition. */
def lookupDataSource(provider: String): Class[_] = {
val loader = Utils.getContextOrSparkClassLoader
+ val serviceLoader = ServiceLoader.load(classOf[DataSourceRegister],
loader)
- if (builtinSources.contains(provider)) {
- return loader.loadClass(builtinSources(provider))
- }
-
- try {
- loader.loadClass(provider)
- } catch {
- case cnf: java.lang.ClassNotFoundException =>
- try {
- loader.loadClass(provider + ".DefaultSource")
- } catch {
- case cnf: java.lang.ClassNotFoundException =>
- if (provider.startsWith("org.apache.spark.sql.hive.orc")) {
- sys.error("The ORC data source must be used with Hive
support enabled.")
- } else {
- sys.error(s"Failed to load class for data source: $provider")
- }
- }
+ serviceLoader.iterator().filter(_.format() == provider).toList match {
--- End diff --
will that be more helpful if we it's case insensitive filtering?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]