HyukjinKwon commented on code in PR #44507:
URL: https://github.com/apache/spark/pull/44507#discussion_r1441245745
##########
sql/core/src/main/scala/org/apache/spark/sql/DataSourceRegistration.scala:
##########
@@ -43,6 +46,33 @@ private[sql] class DataSourceRegistration private[sql]
(dataSourceManager: DataS
| pythonExec: ${dataSource.dataSourceCls.pythonExec}
""".stripMargin)
+ checkDataSourceExists(name)
+
dataSourceManager.registerDataSource(name, dataSource)
}
+
+ /**
+ * Checks if the specified data source exists.
+ *
+ * This method allows for user-defined data sources to be registered even if
they
+ * have the same name as an existing data source in the registry. However,
if the
+ * data source can be successfully loaded and is not a user-defined one, an
error
+ * is thrown to prevent lookup errors with built-in or Scala/Java data
sources.
+ */
+ private def checkDataSourceExists(name: String): Unit = {
+ // Allow re-registration of user-defined data sources.
+ if (dataSourceManager.dataSourceExists(name)) return
+
+ try {
+ DataSource.lookupDataSource(name, conf)
Review Comment:
That makes sense in a way. But technically we can also overwrite Java/Scala
datasources once we allow runtime registration, and my concern is that it might
be somewhat inconsistent and difficult to understand how the overwrite works to
the end users. One way is just to allow overwrite always, or disallow at all.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]