Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions core/src/main/resources/error/error-classes.json
Original file line number Diff line number Diff line change
Expand Up @@ -1578,6 +1578,11 @@
],
"sqlState" : "0A000"
},
"UNSUPPORTED_DATASOURCE_FOR_DIRECT_QUERY" : {
"message" : [
"Unsupported data source type for direct query on files: <dataSourceType>"
]
},
"UNSUPPORTED_DATATYPE" : {
"message" : [
"Unsupported data type <typeName>."
Expand Down Expand Up @@ -5107,11 +5112,6 @@
"failed to evaluate expression <sqlExpr>: <msg>"
]
},
"_LEGACY_ERROR_TEMP_2332" : {
"message" : [
"<msg>"
]
},
"_LEGACY_ERROR_TEMP_2400" : {
"message" : [
"The <name> expression must evaluate to a constant value, but got <limitExpr>."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ class ResolveSQLOnFile(sparkSession: SparkSession) extends Rule[LogicalPlan] {
case e: Exception =>
// the provider is valid, but failed to create a logical plan
u.failAnalysis(
errorClass = "_LEGACY_ERROR_TEMP_2332",
messageParameters = Map("msg" -> e.getMessage),
cause = e)
errorClass = "UNSUPPORTED_DATASOURCE_FOR_DIRECT_QUERY",
messageParameters = Map("dataSourceType" -> u.multipartIdentifier.head),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not just assigning an error class name, but changing the error message as well. It's good to put the data source type in the error message, but I don't think we can simply ignore the original error message e.getMessage. @itholic can you fix it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix it before 3.5, as it's a regression

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, seems like the #42124 already fixes the bug from UNSUPPORTED_DATASOURCE_FOR_DIRECT_QUERY ??

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure? I don't see it passing the original error message.

cause = e
)
}
}
}
Expand Down
24 changes: 16 additions & 8 deletions sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1634,15 +1634,23 @@ class SQLQuerySuite extends QueryTest with SharedSparkSession with AdaptiveSpark
checkErrorTableNotFound(e, "`no_db`.`no_table`",
ExpectedContext("no_db.no_table", 14, 13 + "no_db.no_table".length))

e = intercept[AnalysisException] {
sql("select * from json.invalid_file")
}
assert(e.message.contains("Path does not exist"))
checkError(
exception = intercept[AnalysisException] {
sql("select * from json.invalid_file")
},
errorClass = "UNSUPPORTED_DATASOURCE_FOR_DIRECT_QUERY",
parameters = Map("dataSourceType" -> "json"),
context = ExpectedContext("json.invalid_file", 14, 30)
)

e = intercept[AnalysisException] {
sql(s"select id from `org.apache.spark.sql.hive.orc`.`file_path`")
}
assert(e.message.contains("Hive built-in ORC data source must be used with Hive support"))
checkError(
exception = intercept[AnalysisException] {
sql(s"select id from `org.apache.spark.sql.hive.orc`.`file_path`")
},
errorClass = "UNSUPPORTED_DATASOURCE_FOR_DIRECT_QUERY",
parameters = Map("dataSourceType" -> "org.apache.spark.sql.hive.orc"),
context = ExpectedContext("`org.apache.spark.sql.hive.orc`.`file_path`", 15, 57)
)

e = intercept[AnalysisException] {
sql(s"select id from `org.apache.spark.sql.sources.HadoopFsRelationProvider`.`file_path`")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1401,16 +1401,24 @@ abstract class SQLQuerySuiteBase extends QueryTest with SQLTestUtils with TestHi
withTempPath(f => {
spark.range(100).toDF.write.parquet(f.getCanonicalPath)

var e = intercept[AnalysisException] {
sql(s"select id from hive.`${f.getCanonicalPath}`")
}
assert(e.message.contains("Unsupported data source type for direct query on files: hive"))
checkError(
exception = intercept[AnalysisException] {
sql(s"select id from hive.`${f.getCanonicalPath}`")
},
errorClass = "UNSUPPORTED_DATASOURCE_FOR_DIRECT_QUERY",
parameters = Map("dataSourceType" -> "hive"),
context = ExpectedContext(s"hive.`${f.getCanonicalPath}`", 15, 104)
)

// data source type is case insensitive
e = intercept[AnalysisException] {
sql(s"select id from HIVE.`${f.getCanonicalPath}`")
}
assert(e.message.contains("Unsupported data source type for direct query on files: HIVE"))
checkError(
exception = intercept[AnalysisException] {
sql(s"select id from HIVE.`${f.getCanonicalPath}`")
},
errorClass = "UNSUPPORTED_DATASOURCE_FOR_DIRECT_QUERY",
parameters = Map("dataSourceType" -> "HIVE"),
context = ExpectedContext(s"HIVE.`${f.getCanonicalPath}`", 15, 104)
)
})
}

Expand Down