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 2023/12/27 07:58:10 UTC
[PR] [SPARK-46522][PYTHON] Block Python data source registration with name conflicts [spark]
allisonwang-db opened a new pull request, #44507:
URL: https://github.com/apache/spark/pull/44507
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
4. Be sure to keep the PR description updated to reflect all changes.
5. Please write your PR title to summarize what this PR proposes.
6. If possible, provide a concise example to reproduce the issue for a faster review.
7. If you want to add a new configuration, please read the guideline first for naming configurations in
'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
8. If you want to add or modify an error type or message, please read the guideline first in
'core/src/main/resources/error/README.md'.
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
This PR prevents the registration of a Python data source if its name conflicts with either a built-in data source or a loadable custom Java/Scala data source.
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
To improve usability. For example, currently, users can register a data source that already exists, but they are unable to use it
```python
spark.dataSource.registerPython("json", MyDataSource) # OK
spark.read.format("json").load()
[FOUND_MULTIPLE_DATA_SOURCES] Detected multiple data sources with the name 'json'. Please check the data source isn't simultaneously registered and located in the classpath. SQLSTATE: 42710
```
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as the documentation fix.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
If no, write 'No'.
-->
No
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
-->
New unit tests
### Was this patch authored or co-authored using generative AI tooling?
<!--
If generative AI tooling has been used in the process of authoring this patch, please include the
phrase: 'Generated-by: ' followed by the name of the tool and its version.
If no, write 'No'.
Please refer to the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
-->
No
--
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
Re: [PR] [SPARK-46522][PYTHON] Block Python data source registration with name conflicts [spark]
Posted by "allisonwang-db (via GitHub)" <gi...@apache.org>.
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
Re: [PR] [SPARK-46522][PYTHON] Block Python data source registration with name conflicts [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon closed pull request #44507: [SPARK-46522][PYTHON] Block Python data source registration with name conflicts
URL: https://github.com/apache/spark/pull/44507
--
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
Re: [PR] [SPARK-46522][PYTHON] Block Python data source registration with name conflicts [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
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: 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
Re: [PR] [SPARK-46522][PYTHON] Block Python data source registration with name conflicts [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #44507:
URL: https://github.com/apache/spark/pull/44507#discussion_r1436985449
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/python/PythonDataSourceSuite.scala:
##########
@@ -229,6 +229,38 @@ class PythonDataSourceSuite extends QueryTest with SharedSparkSession {
}
}
+ test("data source name conflicts") {
+ assume(shouldTestPandasUDFs)
+ val dataSourceScript =
Review Comment:
We won't actually need this script. We could create an empty UserDefinedPythonDataSource. I am adding a util for this `PythonUtils.createPythonFunction` at https://github.com/apache/spark/pull/44504. I can followup once that's merged.
--
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
Re: [PR] [SPARK-46522][PYTHON] Block Python data source registration with name conflicts [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #44507:
URL: https://github.com/apache/spark/pull/44507#discussion_r1436986346
##########
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:
Maybe just call `SQLConf.get` for `conf`.
--
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
Re: [PR] [SPARK-46522][PYTHON] Block Python data source registration with name conflicts [spark]
Posted by "allisonwang-db (via GitHub)" <gi...@apache.org>.
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: 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
Re: [PR] [SPARK-46522][PYTHON] Block Python data source registration with name conflicts [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #44507:
URL: https://github.com/apache/spark/pull/44507#discussion_r1436986036
##########
sql/core/src/main/scala/org/apache/spark/sql/DataSourceRegistration.scala:
##########
@@ -28,7 +31,7 @@ import org.apache.spark.sql.execution.python.UserDefinedPythonDataSource
*/
@Evolving
private[sql] class DataSourceRegistration private[sql] (dataSourceManager: DataSourceManager)
- extends Logging {
+ extends Logging with SQLConfHelper {
Review Comment:
qq why do we need `SQLConfHelper`?
--
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
Re: [PR] [SPARK-46522][PYTHON] Block Python data source registration with name conflicts [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #44507:
URL: https://github.com/apache/spark/pull/44507#discussion_r1441246215
##########
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:
So I was thinking that statically registered ones cannot be overwritten but not sure which way is better.
--
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
Re: [PR] [SPARK-46522][PYTHON] Block Python data source registration with name conflicts [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #44507:
URL: https://github.com/apache/spark/pull/44507#discussion_r1444175715
##########
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 am fine with this for now but should probably make sure ^ change happen before Spark 4.0.
--
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
Re: [PR] [SPARK-46522][PYTHON] Block Python data source registration with name conflicts [spark]
Posted by "allisonwang-db (via GitHub)" <gi...@apache.org>.
allisonwang-db commented on code in PR #44507:
URL: https://github.com/apache/spark/pull/44507#discussion_r1444195840
##########
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:
Sounds good! Will add a TODO here.
--
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
Re: [PR] [SPARK-46522][PYTHON] Block Python data source registration with name conflicts [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #44507:
URL: https://github.com/apache/spark/pull/44507#discussion_r1436987063
##########
sql/core/src/main/scala/org/apache/spark/sql/DataSourceRegistration.scala:
##########
@@ -28,7 +31,7 @@ import org.apache.spark.sql.execution.python.UserDefinedPythonDataSource
*/
@Evolving
private[sql] class DataSourceRegistration private[sql] (dataSourceManager: DataSourceManager)
- extends Logging {
+ extends Logging with SQLConfHelper {
Review Comment:
Maybe just call `SQLConf.get` for `conf`.
##########
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:
Maybe just call `SQLConf.get` for `conf`.
--
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
Re: [PR] [SPARK-46522][PYTHON] Block Python data source registration with name conflicts [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #44507:
URL: https://github.com/apache/spark/pull/44507#discussion_r1436993480
##########
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:
Another concern is that when the name conflicts with statically registered sources..
--
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
Re: [PR] [SPARK-46522][PYTHON] Block Python data source registration with name conflicts [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
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: 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
Re: [PR] [SPARK-46522][PYTHON] Block Python data source registration with name conflicts [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on PR #44507:
URL: https://github.com/apache/spark/pull/44507#issuecomment-1880490248
Merged to master.
--
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