Skip to content

Commit

Permalink
[SPARK-38105][SQL] Use error classes in the parsing errors of joins
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?
Migrate the following errors in QueryParsingErrors onto use error classes:
1. joinCriteriaUnimplementedError => throw IllegalStateException instead, since it should never happen and not visible to users, introduced by improving exhaustivity in [PR](#30455)
2. naturalCrossJoinUnsupportedError => UNSUPPORTED_FEATURE

### Why are the changes needed?
Porting join parsing errors to new error framework.

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?
UT added.

Closes #35405 from ivoson/SPARK-38105.

Authored-by: Tengfei Huang <tengfei.h@gmail.com>
Signed-off-by: Max Gekk <max.gekk@gmail.com>
  • Loading branch information
ivoson authored and MaxGekk committed Feb 6, 2022
1 parent 0084a86 commit 0d56c94
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with SQLConfHelper with Logg
case Some(c) if c.booleanExpression != null =>
(baseJoinType, Option(expression(c.booleanExpression)))
case Some(c) =>
throw QueryParsingErrors.joinCriteriaUnimplementedError(c, ctx)
throw new IllegalStateException(s"Unimplemented joinCriteria: $c")
case None if join.NATURAL != null =>
if (join.LATERAL != null) {
throw QueryParsingErrors.lateralJoinWithNaturalJoinUnsupportedError(ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,8 @@ object QueryParsingErrors {
new ParseException(s"Cannot resolve window reference '$name'", ctx)
}

def joinCriteriaUnimplementedError(join: JoinCriteriaContext, ctx: RelationContext): Throwable = {
new ParseException(s"Unimplemented joinCriteria: $join", ctx)
}

def naturalCrossJoinUnsupportedError(ctx: RelationContext): Throwable = {
new ParseException("NATURAL CROSS JOIN is not supported", ctx)
new ParseException("UNSUPPORTED_FEATURE", Array("NATURAL CROSS JOIN."), ctx)
}

def emptyInputForTableSampleError(ctx: ParserRuleContext): Throwable = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,12 @@ class QueryParsingErrorsSuite extends QueryTest with SharedSparkSession {
message = "Invalid SQL syntax: LATERAL can only be used with subquery.")
}
}

test("UNSUPPORTED_FEATURE: NATURAL CROSS JOIN is not supported") {
validateParsingError(
sqlText = "SELECT * FROM a NATURAL CROSS JOIN b",
errorClass = "UNSUPPORTED_FEATURE",
sqlState = "0A000",
message = "The feature is not supported: NATURAL CROSS JOIN.")
}
}

0 comments on commit 0d56c94

Please sign in to comment.