You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "allisonwang-db (via GitHub)" <gi...@apache.org> on 2024/01/03 09:54:58 UTC

Re: [PR] [SPARK-46522][PYTHON] Block Python data source registration with name conflicts [spark]

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


##########
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:
   The rule I am considering is that:
   - If the name of any user-defined data source conflicts with a built-in data source or an existing **Java/Scala** data source that can be loaded from the classpath, an exception will be thrown.
   - Otherwise, data sources can be overridden.
   
   For static Python data sources, should we allow them to be overridden?



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org