allisonwang-db commented on code in PR #44507:
URL: https://github.com/apache/spark/pull/44507#discussion_r1442635733


##########
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:
   I agree we should keep it consistent by blocking all statically registered 
data sources (we can change this based on user feedback in the future).
   Currently, it appears we can't differentiate between a statically registered 
Python data source and a dynamic one. Perhaps we could add a flag in the 
dataSourceBuilders to indicate whether it's static or dynamic. 
   



-- 
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]

Reply via email to