This is an automated email from the ASF dual-hosted git repository. maxgekk pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push: new 834841ef5da [SPARK-38733][SQL][TESTS] Test the error class: INCOMPATIBLE_DATASOURCE_REGISTER 834841ef5da is described below commit 834841ef5dab150f249d4171fddb474251beecac Author: panbingkun <pbk1...@gmail.com> AuthorDate: Wed May 4 14:59:12 2022 +0300 [SPARK-38733][SQL][TESTS] Test the error class: INCOMPATIBLE_DATASOURCE_REGISTER ## What changes were proposed in this pull request? This PR aims to add a test for the error class INCOMPATIBLE_DATASOURCE_REGISTER to `QueryExecutionErrorsSuite`. ### Why are the changes needed? The changes improve test coverage, and document expected error messages in tests. ### Does this PR introduce any user-facing change? No ### How was this patch tested? By running new test: ``` $ build/sbt "sql/testOnly *QueryExecutionErrorsSuite*" ``` Closes #36429 from panbingkun/SPARK-38733. Lead-authored-by: panbingkun <pbk1...@gmail.com> Co-authored-by: Maxim Gekk <max.g...@gmail.com> Signed-off-by: Max Gekk <max.g...@gmail.com> --- .../sql/errors/QueryExecutionErrorsSuite.scala | 33 ++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionErrorsSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionErrorsSuite.scala index baa731571f7..7a5592c148a 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionErrorsSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionErrorsSuite.scala @@ -18,13 +18,14 @@ package org.apache.spark.sql.errors import java.io.IOException -import java.util.Locale +import java.net.URL +import java.util.{Locale, ServiceConfigurationError} import org.apache.hadoop.fs.{LocalFileSystem, Path} import org.apache.hadoop.fs.permission.FsPermission import test.org.apache.spark.sql.connector.JavaSimpleWritableDataSource -import org.apache.spark.{SparkArithmeticException, SparkException, SparkIllegalArgumentException, SparkIllegalStateException, SparkRuntimeException, SparkSecurityException, SparkUnsupportedOperationException, SparkUpgradeException} +import org.apache.spark.{SparkArithmeticException, SparkClassNotFoundException, SparkException, SparkIllegalArgumentException, SparkIllegalStateException, SparkRuntimeException, SparkSecurityException, SparkUnsupportedOperationException, SparkUpgradeException} import org.apache.spark.sql.{AnalysisException, DataFrame, QueryTest, SaveMode} import org.apache.spark.sql.catalyst.util.BadRecordException import org.apache.spark.sql.connector.SimpleWritableDataSource @@ -485,6 +486,34 @@ class QueryExecutionErrorsSuite } } } + + test("INCOMPATIBLE_DATASOURCE_REGISTER: create table using an incompatible data source") { + val newClassLoader = new ClassLoader() { + + override def getResources(name: String): java.util.Enumeration[URL] = { + if (name.equals("META-INF/services/org.apache.spark.sql.sources.DataSourceRegister")) { + // scalastyle:off + throw new ServiceConfigurationError(s"Illegal configuration-file syntax: $name", + new NoClassDefFoundError("org.apache.spark.sql.sources.HadoopFsRelationProvider")) + // scalastyle:on throwerror + } else { + super.getResources(name) + } + } + } + + Utils.withContextClassLoader(newClassLoader) { + val e = intercept[SparkClassNotFoundException] { + sql("CREATE TABLE student (id INT, name STRING, age INT) USING org.apache.spark.sql.fake") + } + checkErrorClass( + exception = e, + errorClass = "INCOMPATIBLE_DATASOURCE_REGISTER", + msg = "Detected an incompatible DataSourceRegister. Please remove the incompatible library " + + "from classpath or upgrade it. Error: Illegal configuration-file syntax: " + + "META-INF/services/org.apache.spark.sql.sources.DataSourceRegister") + } + } } class FakeFileSystemSetPermission extends LocalFileSystem { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org