Skip to content

Commit

Permalink
[SEDONA-716] Change the spark parser order to use delegate parser fir…
Browse files Browse the repository at this point in the history
…st (#1832)
  • Loading branch information
zhangfengcdt authored Feb 26, 2025
1 parent db6e8cf commit 5007131
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,22 @@ class SedonaSqlParser(delegate: ParserInterface) extends SparkSqlParser {
val parserBuilder = new SedonaSqlAstBuilder

/**
* Parse the SQL text and return the logical plan.
* Parse the SQL text and return the logical plan. This method first attempts to use the
* delegate parser to parse the SQL text. If the delegate parser fails (throws an exception), it
* falls back to using the Sedona SQL parser.
*
* @param sqlText
* The SQL text to be parsed.
* @return
* The parsed logical plan.
*/
override def parsePlan(sqlText: String): LogicalPlan =
try {
parse(sqlText) { parser =>
parserBuilder.visit(parser.singleStatement())
}.asInstanceOf[LogicalPlan]
delegate.parsePlan(sqlText)
} catch {
case _: Exception =>
delegate.parsePlan(sqlText)
parse(sqlText) { parser =>
parserBuilder.visit(parser.singleStatement())
}.asInstanceOf[LogicalPlan]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,22 @@ class SedonaSqlParser(delegate: ParserInterface) extends SparkSqlParser {
val parserBuilder = new SedonaSqlAstBuilder

/**
* Parse the SQL text and return the logical plan.
* Parse the SQL text and return the logical plan. This method first attempts to use the
* delegate parser to parse the SQL text. If the delegate parser fails (throws an exception), it
* falls back to using the Sedona SQL parser.
*
* @param sqlText
* The SQL text to be parsed.
* @return
* The parsed logical plan.
*/
override def parsePlan(sqlText: String): LogicalPlan =
try {
parse(sqlText) { parser =>
parserBuilder.visit(parser.singleStatement())
}.asInstanceOf[LogicalPlan]
delegate.parsePlan(sqlText)
} catch {
case _: Exception =>
delegate.parsePlan(sqlText)
parse(sqlText) { parser =>
parserBuilder.visit(parser.singleStatement())
}.asInstanceOf[LogicalPlan]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,22 @@ class SedonaSqlParser(delegate: ParserInterface) extends SparkSqlParser {
val parserBuilder = new SedonaSqlAstBuilder

/**
* Parse the SQL text and return the logical plan.
* Parse the SQL text and return the logical plan. This method first attempts to use the
* delegate parser to parse the SQL text. If the delegate parser fails (throws an exception), it
* falls back to using the Sedona SQL parser.
*
* @param sqlText
* The SQL text to be parsed.
* @return
* The parsed logical plan.
*/
override def parsePlan(sqlText: String): LogicalPlan =
try {
parse(sqlText) { parser =>
parserBuilder.visit(parser.singleStatement())
}.asInstanceOf[LogicalPlan]
delegate.parsePlan(sqlText)
} catch {
case _: Exception =>
delegate.parsePlan(sqlText)
parse(sqlText) { parser =>
parserBuilder.visit(parser.singleStatement())
}.asInstanceOf[LogicalPlan]
}
}

0 comments on commit 5007131

Please sign in to comment.