Skip to content

Commit 37f2966

Browse files
mihailoale-dbMaxGekk
authored andcommitted
[SPARK-49866][SQL] Improve the error message for describe table with partition columns
### What changes were proposed in this pull request? Provide more user facing error when partition column name can't be found in the table schema. ### Why are the changes needed? There's an issue where partition column sometimes doesn't match any from the table schema. When that happens we throw an assertion error which is not user friendly. Because of that we introduced new `QueryExecutionError` in order to make it more user facing. ### Does this PR introduce _any_ user-facing change? Yes, users will get more user friendly error message. ### Was this patch authored or co-authored using generative AI tooling? No Closes #48338 from mihailoale-db/mihailoale-db/fixdescribepartitioningmessage. Authored-by: Mihailo Aleksic <[email protected]> Signed-off-by: Max Gekk <[email protected]>
1 parent 3e69b40 commit 37f2966

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3802,6 +3802,12 @@
38023802
],
38033803
"sqlState" : "428FT"
38043804
},
3805+
"PARTITION_COLUMN_NOT_FOUND_IN_SCHEMA" : {
3806+
"message" : [
3807+
"Partition column <column> not found in schema <schema>. Please provide the existing column for partitioning."
3808+
],
3809+
"sqlState" : "42000"
3810+
},
38053811
"PATH_ALREADY_EXISTS" : {
38063812
"message" : [
38073813
"Path <outputPath> already exists. Set mode as \"overwrite\" to overwrite the existing path."

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2856,4 +2856,16 @@ private[sql] object QueryExecutionErrors extends QueryErrorsBase with ExecutionE
28562856
)
28572857
)
28582858
}
2859+
2860+
def partitionColumnNotFoundInTheTableSchemaError(
2861+
column: Seq[String],
2862+
schema: StructType): SparkRuntimeException = {
2863+
new SparkRuntimeException(
2864+
errorClass = "PARTITION_COLUMN_NOT_FOUND_IN_SCHEMA",
2865+
messageParameters = Map(
2866+
"column" -> toSQLId(column),
2867+
"schema" -> toSQLType(schema)
2868+
)
2869+
)
2870+
}
28592871
}

sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DescribeTableExec.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import org.apache.spark.sql.catalyst.util.{quoteIfNeeded, ResolveDefaultColumns}
2727
import org.apache.spark.sql.connector.catalog.{CatalogV2Util, SupportsMetadataColumns, SupportsRead, Table, TableCatalog}
2828
import org.apache.spark.sql.connector.expressions.{ClusterByTransform, IdentityTransform}
2929
import org.apache.spark.sql.connector.read.SupportsReportStatistics
30+
import org.apache.spark.sql.errors.QueryExecutionErrors
3031
import org.apache.spark.sql.util.CaseInsensitiveStringMap
3132
import org.apache.spark.util.ArrayImplicits._
3233

@@ -156,9 +157,12 @@ case class DescribeTableExec(
156157
.map(_.asInstanceOf[IdentityTransform].ref.fieldNames())
157158
.map { fieldNames =>
158159
val nestedField = table.schema.findNestedField(fieldNames.toImmutableArraySeq)
159-
assert(nestedField.isDefined,
160-
s"Not found the partition column ${fieldNames.map(quoteIfNeeded).mkString(".")} " +
161-
s"in the table schema ${table.schema().catalogString}.")
160+
if (nestedField.isEmpty) {
161+
throw QueryExecutionErrors.partitionColumnNotFoundInTheTableSchemaError(
162+
fieldNames.toSeq,
163+
table.schema()
164+
)
165+
}
162166
nestedField.get
163167
}.map { case (path, field) =>
164168
toCatalystRow(

0 commit comments

Comments
 (0)