HyukjinKwon commented on code in PR #44507:
URL: https://github.com/apache/spark/pull/44507#discussion_r1436983679


##########
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 feel like we should probably scope this into runtime datasources (can be 
overwritten), and static datasources (cannot be overwritten). This change 
should probably be fine for now though.



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