Skip to content

Commit 5ded9d8

Browse files
committed
[SPARK-54501][SQL] Improve error handling and messaging for Hive metastore partition filter failures
1 parent 7191a14 commit 5ded9d8

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

common/utils/src/main/resources/error/error-conditions.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2431,6 +2431,14 @@
24312431
],
24322432
"sqlState" : "XX000"
24332433
},
2434+
"INTERNAL_ERROR_HIVE_METASTORE_PARTITION_FILTER" : {
2435+
"message" : [
2436+
"Failed to get partition metadata by filter from Hive metastore.",
2437+
"To work around this issue, set '<hiveMetastorePartitionPruningFallbackOnException>' to true. Note that this may result in degraded performance as Spark will fetch all partition metadata instead of filtering at the metastore level.",
2438+
"To report this issue, visit: https://issues.apache.org/jira/browse/SPARK"
2439+
],
2440+
"sqlState" : "58030"
2441+
},
24342442
"INTERNAL_ERROR_MEMORY" : {
24352443
"message" : [
24362444
"<message>"
@@ -9021,11 +9029,6 @@
90219029
"Partition filter cannot have both `\"` and `'` characters."
90229030
]
90239031
},
9024-
"_LEGACY_ERROR_TEMP_2193" : {
9025-
"message" : [
9026-
"Caught Hive MetaException attempting to get partition metadata by filter from Hive. You can set the Spark configuration setting <hiveMetastorePartitionPruningFallbackOnException> to true to work around this problem, however this will result in degraded performance. Please report a bug: https://issues.apache.org/jira/browse/SPARK."
9027-
]
9028-
},
90299032
"_LEGACY_ERROR_TEMP_2194" : {
90309033
"message" : [
90319034
"Unsupported Hive Metastore version <version>. Please set <key> with a valid version."

sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1667,7 +1667,7 @@ private[sql] object QueryExecutionErrors extends QueryErrorsBase with ExecutionE
16671667

16681668
def getPartitionMetadataByFilterError(e: Exception): SparkRuntimeException = {
16691669
new SparkRuntimeException(
1670-
errorClass = "_LEGACY_ERROR_TEMP_2193",
1670+
errorClass = "INTERNAL_ERROR_HIVE_METASTORE_PARTITION_FILTER",
16711671
messageParameters = Map(
16721672
"hiveMetastorePartitionPruningFallbackOnException" ->
16731673
SQLConf.HIVE_METASTORE_PARTITION_PRUNING_FALLBACK_ON_EXCEPTION.key),

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/ExternalCatalogSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ abstract class ExternalCatalogSuite extends SparkFunSuite {
573573
// then be caught and converted to a RuntimeException with a descriptive message.
574574
case ex: RuntimeException if ex.getMessage.contains("MetaException") =>
575575
throw new AnalysisException(
576-
errorClass = "_LEGACY_ERROR_TEMP_2193",
576+
errorClass = "INTERNAL_ERROR_HIVE_METASTORE_PARTITION_FILTER",
577577
messageParameters = Map(
578578
"hiveMetastorePartitionPruningFallbackOnException" ->
579579
SQLConf.HIVE_METASTORE_PARTITION_PRUNING_FALLBACK_ON_EXCEPTION.key))

sql/hive/src/test/scala/org/apache/spark/sql/hive/client/HivePartitionFilteringSuite.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import org.apache.hadoop.hive.serde2.`lazy`.LazySimpleSerDe
2626
import org.apache.hadoop.mapred.TextInputFormat
2727
import org.scalatest.BeforeAndAfterAll
2828

29+
import org.apache.spark.SparkRuntimeException
2930
import org.apache.spark.sql.catalyst.TableIdentifier
3031
import org.apache.spark.sql.catalyst.catalog._
3132
import org.apache.spark.sql.catalyst.catalog.ExternalCatalogUtils.DEFAULT_PARTITION_NAME
@@ -142,11 +143,12 @@ class HivePartitionFilteringSuite(version: String)
142143

143144
test(s"getPartitionsByFilter should fail when $fallbackKey=false") {
144145
withSQLConf(fallbackKey -> "false") {
145-
val e = intercept[RuntimeException](
146+
val e = intercept[SparkRuntimeException](
146147
clientWithoutDirectSql.getPartitionsByFilter(
147148
clientWithoutDirectSql.getRawHiveTable("default", "test"),
148149
Seq(attr("ds") === 20170101)))
149-
assert(e.getMessage.contains("Caught Hive MetaException"))
150+
assert(e.getCondition == "INTERNAL_ERROR_HIVE_METASTORE_PARTITION_FILTER")
151+
assert(e.getMessage.contains("Failed to get partition metadata by filter"))
150152
}
151153
}
152154

0 commit comments

Comments
 (0)