Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-49866][SQL] Improve the error message for describe table with partition columns #48338

Closed
Show file tree
Hide file tree
Changes from 4 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
6 changes: 6 additions & 0 deletions common/utils/src/main/resources/error/error-conditions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3795,6 +3795,12 @@
],
"sqlState" : "428FT"
},
"PARTITION_COLUMN_NOT_FOUND_IN_SCHEMA" : {
"message" : [
"Partition column <column> not found in schema <schema>. Please provide the existing column for partitioning."
],
"sqlState" : "42000"
},
"PATH_ALREADY_EXISTS" : {
"message" : [
"Path <outputPath> already exists. Set mode as \"overwrite\" to overwrite the existing path."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2852,4 +2852,16 @@ private[sql] object QueryExecutionErrors extends QueryErrorsBase with ExecutionE
)
)
}

def partitionColumnNotFoundInTheTableSchemaError(
column: Seq[String],
schema: String): SparkRuntimeException = {
new SparkRuntimeException(
errorClass = "PARTITION_COLUMN_NOT_FOUND_IN_SCHEMA",
messageParameters = Map(
"column" -> toSQLId(column),
"schema" -> toSQLType(schema)
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import org.apache.spark.sql.catalyst.util.{quoteIfNeeded, ResolveDefaultColumns}
import org.apache.spark.sql.connector.catalog.{CatalogV2Util, SupportsMetadataColumns, SupportsRead, Table, TableCatalog}
import org.apache.spark.sql.connector.expressions.{ClusterByTransform, IdentityTransform}
import org.apache.spark.sql.connector.read.SupportsReportStatistics
import org.apache.spark.sql.errors.DataTypeErrors.{toSQLId, toSQLType}
import org.apache.spark.sql.errors.QueryExecutionErrors
import org.apache.spark.sql.util.CaseInsensitiveStringMap
import org.apache.spark.util.ArrayImplicits._

Expand Down Expand Up @@ -156,9 +158,12 @@ case class DescribeTableExec(
.map(_.asInstanceOf[IdentityTransform].ref.fieldNames())
.map { fieldNames =>
val nestedField = table.schema.findNestedField(fieldNames.toImmutableArraySeq)
assert(nestedField.isDefined,
s"Not found the partition column ${fieldNames.map(quoteIfNeeded).mkString(".")} " +
s"in the table schema ${table.schema().catalogString}.")
if (nestedField.isEmpty) {
throw QueryExecutionErrors.partitionColumnNotFoundInTheTableSchemaError(
fieldNames.toSeq,
table.schema().catalogString
)
}
nestedField.get
}.map { case (path, field) =>
toCatalystRow(
Expand Down