I tried calcite SQL parser on version 1.32.0 and 1.36.0. I used double quote(") as literal quote string in spark sql expression, and set the parameter on my parser config, but it threw a sql parse exception: org.apache.calcite.sql.parser.impl.ParseException: Encountered """ at line 1, column 26. Was expecting one of: "ABS" ... "ARRAY" ... "AVG" ... I am not sure if this is bug, because double quote for literal string is not a rare case.
Here is my test case:
public static void main(String[] args) throws Exception {
String sqlQuery = "case when `Area` in ( \"Region1\", \"Region2\", \"Region3\" ) then `Sales` else null end";
//create spark dialect
SqlDialect.Context context = SqlDialect.EMPTY_CONTEXT
.withDatabaseProduct(SqlDialect.DatabaseProduct.SPARK)
.withUnquotedCasing(Casing.UNCHANGED)
.withNullCollation(NullCollation.LOW)
.withIdentifierQuoteString("`")
.withLiteralQuoteString("\"");
SqlDialect sparkDialect = new SparkSqlDialect(context);
SqlParser.Config config = sparkDialect.configureParser(SqlParser.config());
// Create an SQL parser
SqlParser parser = SqlParser.create(sqlQuery, config);
// Parse the query into an AST. Here the exception occurred
SqlNode sqlNode = parser.parseExpression();
}
If it is not an issue of calcite sql parser, please propose a proper way of parsing the sql expression