Hi All,

Is there a way to validate the syntax of raw spark SQL query?

for example, I would like to know if there is any isValid API call spark
provides?

val query = "select * from table"if(isValid(query)) {
    sparkSession.sql(query) } else {
    log.error("Invalid Syntax")}

I tried the following

val query = "select * morf table" // Invalid queryval parser =
spark.sessionState.sqlParsertry{
    parser.parseExpression(query)} catch (ParseException ex) {
    throw new Exception(ex); //Exception not getting
thrown}Dataset<>Row df = sparkSession.sql(query) // Exception gets
thrown here
df.writeStream.format("console").start()

Question: parser.parseExpression is not catching the invalid syntax before
I hit the sparkSession.sql. Other words it is not being helpful in the
above code. any reason? My whole goal is to catch syntax errors before I
pass it on to sparkSession.sql

Reply via email to