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

[HUDI-4309] Spark3.2 custom parser should not throw exception #5947

Merged
merged 3 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,16 @@ class TestTimeTravelTable extends HoodieSparkSqlTestBase {
}
}
}

test("Test Unsupported syntax can be parsed") {
if (HoodieSparkUtils.gteqSpark3_2) {
checkAnswer("select 1 distribute by 1")(Seq(1))
withTempDir { dir =>
val path = dir.toURI.getPath
spark.sql(s"insert overwrite local directory '$path' using parquet select 1")
// Requires enable hive support, so didn't test it
// spark.sql(s"insert overwrite local directory '$path' stored as orc select 1")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,23 @@ import org.apache.spark.sql.catalyst.{FunctionIdentifier, TableIdentifier}
import org.apache.spark.sql.types._
import org.apache.spark.sql.{AnalysisException, SparkSession}

import scala.util.control.NonFatal

class HoodieSpark3_2ExtendedSqlParser(session: SparkSession, delegate: ParserInterface)
extends ParserInterface with Logging {

private lazy val conf = session.sqlContext.conf
private lazy val builder = new HoodieSpark3_2ExtendedSqlAstBuilder(conf, delegate)

override def parsePlan(sqlText: String): LogicalPlan = parse(sqlText) { parser =>
builder.visit(parser.singleStatement()) match {
case plan: LogicalPlan => plan
case _=> delegate.parsePlan(sqlText)
try {
builder.visit(parser.singleStatement()) match {
case plan: LogicalPlan => plan
case _=> delegate.parsePlan(sqlText)
}
} catch {
case NonFatal(_) =>
cxzl25 marked this conversation as resolved.
Show resolved Hide resolved
delegate.parsePlan(sqlText)
}
}

Expand Down