Skip to content

Commit

Permalink
add low priority error
Browse files Browse the repository at this point in the history
  • Loading branch information
anchovYu committed Aug 17, 2024
1 parent 8566bc6 commit e5f6fbb
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog with QueryErrorsB
val DATA_TYPE_MISMATCH_ERROR = TreeNodeTag[Unit]("dataTypeMismatchError")
val INVALID_FORMAT_ERROR = TreeNodeTag[Unit]("invalidFormatError")

// Error that has a lower priority, that are not thrown immediately on triggering, e.g. certain
// internal errors. These errors are thrown at the end of the whole check analysis process.
var lowPriorityError: Option[() => Unit] = None

/**
* Fails the analysis at the point where a specific tree node was parsed using a provided
* error class and message parameters.
Expand Down Expand Up @@ -114,10 +118,19 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog with QueryErrorsB
private def checkNotContainingLCA(exprs: Seq[Expression], plan: LogicalPlan): Unit = {
exprs.foreach(_.transformDownWithPruning(_.containsPattern(LATERAL_COLUMN_ALIAS_REFERENCE)) {
case lcaRef: LateralColumnAliasReference =>
throw SparkException.internalError("Resolved plan should not contain any " +
s"LateralColumnAliasReference.\nDebugging information: plan:\n$plan",
context = lcaRef.origin.getQueryContext,
summary = lcaRef.origin.context.summary)
// this should be a low priority internal error that is thrown when no other error occurs
if (lowPriorityError.isEmpty) {
lowPriorityError = Some(
() =>
throw SparkException.internalError(
"Resolved plan should not contain any " +
s"LateralColumnAliasReference.\nDebugging information: plan:\n$plan",
context = lcaRef.origin.getQueryContext,
summary = lcaRef.origin.context.summary
)
)
}
lcaRef
})
}

Expand Down Expand Up @@ -176,6 +189,7 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog with QueryErrorsB
}
try {
checkAnalysis0(inlinedPlan)
lowPriorityError.foreach(_.apply())
} catch {
case e: AnalysisException =>
throw new ExtendedAnalysisException(e, inlinedPlan)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1319,4 +1319,31 @@ class LateralColumnAliasSuite extends LateralColumnAliasSuiteBase {
Row(2) :: Nil
)
}

test("LCA internal error should have lower priority") {
// in this query, the 'order by Freq DESC' error should be the top error surfaced to users
checkError(
exception = intercept[AnalysisException] {
sql(
"""
|WITH group_counts AS (
| SELECT id, count(*) as Freq, CASE WHEN Freq <= 10 THEN "1" ELSE "2" END AS Group
| FROM values (123) as data(id)
| GROUP BY id
|)
|SELECT Group, count(*) * 100.0 / (select count(*) from group_counts) AS Percentage
|FROM group_counts
|Group BY Group
|ORDER BY Freq DESC;
|""".stripMargin
)
},
errorClass = "UNRESOLVED_COLUMN.WITH_SUGGESTION",
sqlState = "42703",
parameters = Map(
"objectName" -> "`Freq`",
"proposal" -> "`Percentage`, `group_counts`.`Group`"
)
)
}
}

0 comments on commit e5f6fbb

Please sign in to comment.