[SPARK-33599][SQL][FOLLOWUP] Group exception messages in catalyst/analysis
### What changes were proposed in this pull request? This PR follows up https://github.com/apache/spark/pull/30717 Maybe some contributors don't know the job and added some exception by the old way. ### Why are the changes needed? It will largely help with standardization of error messages and its maintenance. ### Does this PR introduce _any_ user-facing change? No. Error messages remain unchanged. ### How was this patch tested? No new tests - pass all original tests to make sure it doesn't break any existing behavior. Closes #31316 from beliefer/SPARK-33599-followup. Lead-authored-by: beliefer <beliefer@163.com> Co-authored-by: gengjiaan <gengjiaan@360.cn> Co-authored-by: Jiaan Geng <beliefer@163.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
This commit is contained in:
parent
714ff73d4a
commit
14934f42d0
|
@ -187,10 +187,9 @@ object ResolveHints {
|
|||
def createRepartitionByExpression(
|
||||
numPartitions: Option[Int], partitionExprs: Seq[Any]): RepartitionByExpression = {
|
||||
val sortOrders = partitionExprs.filter(_.isInstanceOf[SortOrder])
|
||||
if (sortOrders.nonEmpty) throw new IllegalArgumentException(
|
||||
s"""Invalid partitionExprs specified: $sortOrders
|
||||
|For range partitioning use REPARTITION_BY_RANGE instead.
|
||||
""".stripMargin)
|
||||
if (sortOrders.nonEmpty) {
|
||||
throw QueryCompilationErrors.invalidRepartitionExpressionsError(sortOrders)
|
||||
}
|
||||
val invalidParams = partitionExprs.filter(!_.isInstanceOf[UnresolvedAttribute])
|
||||
if (invalidParams.nonEmpty) {
|
||||
throw QueryCompilationErrors.invalidHintParameterError(hintName, invalidParams)
|
||||
|
|
|
@ -741,4 +741,17 @@ private[spark] object QueryCompilationErrors {
|
|||
new InvalidUDFClassException(s"No handler for UDAF '$name'. " +
|
||||
"Use sparkSession.udf.register(...) instead.")
|
||||
}
|
||||
|
||||
def databaseFromV1SessionCatalogNotSpecifiedError(): Throwable = {
|
||||
new AnalysisException("Database from v1 session catalog is not specified")
|
||||
}
|
||||
|
||||
def nestedDatabaseUnsupportedByV1SessionCatalogError(catalog: String): Throwable = {
|
||||
new AnalysisException(s"Nested databases are not supported by v1 session catalog: $catalog")
|
||||
}
|
||||
|
||||
def invalidRepartitionExpressionsError(sortOrders: Seq[Any]): Throwable = {
|
||||
new AnalysisException(s"Invalid partitionExprs specified: $sortOrders For range " +
|
||||
"partitioning use REPARTITION_BY_RANGE instead.")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.spark.sql.catalyst.analysis
|
|||
|
||||
import org.apache.log4j.Level
|
||||
|
||||
import org.apache.spark.sql.AnalysisException
|
||||
import org.apache.spark.sql.catalyst.dsl.expressions._
|
||||
import org.apache.spark.sql.catalyst.dsl.plans._
|
||||
import org.apache.spark.sql.catalyst.expressions.{Ascending, AttributeReference, Literal, SortOrder}
|
||||
|
@ -165,7 +166,7 @@ class ResolveHintsSuite extends AnalysisTest {
|
|||
RepartitionByExpression(
|
||||
Seq(AttributeReference("a", IntegerType)()), testRelation, None))
|
||||
|
||||
val e = intercept[IllegalArgumentException] {
|
||||
val e = intercept[AnalysisException] {
|
||||
checkAnalysis(
|
||||
UnresolvedHint("REPARTITION",
|
||||
Seq(SortOrder(AttributeReference("a", IntegerType)(), Ascending)),
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
package org.apache.spark.sql.catalyst.analysis
|
||||
|
||||
import org.apache.spark.sql.{AnalysisException, SaveMode}
|
||||
import org.apache.spark.sql.SaveMode
|
||||
import org.apache.spark.sql.catalyst.{FunctionIdentifier, TableIdentifier}
|
||||
import org.apache.spark.sql.catalyst.catalog.{BucketSpec, CatalogStorageFormat, CatalogTable, CatalogTableType, CatalogUtils}
|
||||
import org.apache.spark.sql.catalyst.expressions.{Alias, Attribute}
|
||||
|
@ -217,8 +217,8 @@ class ResolveSessionCatalog(val catalogManager: CatalogManager)
|
|||
case Alias(child, _) =>
|
||||
throw QueryCompilationErrors.commandNotSupportNestedColumnError(
|
||||
"DESC TABLE COLUMN", toPrettySQL(child))
|
||||
case other =>
|
||||
throw new AnalysisException(s"[BUG] unexpected column expression: $other")
|
||||
case _ =>
|
||||
throw new IllegalStateException(s"[BUG] unexpected column expression: $column")
|
||||
}
|
||||
|
||||
// For CREATE TABLE [AS SELECT], we should use the v1 command if the catalog is resolved to the
|
||||
|
@ -708,12 +708,12 @@ class ResolveSessionCatalog(val catalogManager: CatalogManager)
|
|||
def unapply(resolved: ResolvedNamespace): Option[String] = resolved match {
|
||||
case ResolvedNamespace(catalog, _) if !isSessionCatalog(catalog) => None
|
||||
case ResolvedNamespace(_, Seq()) =>
|
||||
throw new AnalysisException("Database from v1 session catalog is not specified")
|
||||
throw QueryCompilationErrors.databaseFromV1SessionCatalogNotSpecifiedError()
|
||||
case ResolvedNamespace(_, Seq(dbName)) => Some(dbName)
|
||||
case _ =>
|
||||
assert(resolved.namespace.length > 1)
|
||||
throw new AnalysisException("Nested databases are not supported by " +
|
||||
s"v1 session catalog: ${resolved.namespace.map(quoteIfNeeded).mkString(".")}")
|
||||
throw QueryCompilationErrors.nestedDatabaseUnsupportedByV1SessionCatalogError(
|
||||
resolved.namespace.map(quoteIfNeeded).mkString("."))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue