Search in sources :

Example 1 with SqlAbstractParserImpl

use of org.apache.calcite.sql.parser.SqlAbstractParserImpl in project flink by apache.

the class CalciteParser method createFlinkParser.

/**
 * Equivalent to {@link SqlParser#create(Reader, SqlParser.Config)}. The only difference is we
 * do not wrap the {@link FlinkSqlParserImpl} with {@link SqlParser}.
 *
 * <p>It is so that we can access specific parsing methods not accessible through the {@code
 * SqlParser}.
 */
private SqlAbstractParserImpl createFlinkParser(String expr) {
    SourceStringReader reader = new SourceStringReader(expr);
    SqlAbstractParserImpl parser = config.parserFactory().getParser(reader);
    parser.setTabSize(1);
    parser.setQuotedCasing(config.quotedCasing());
    parser.setUnquotedCasing(config.unquotedCasing());
    parser.setIdentifierMaxLength(config.identifierMaxLength());
    parser.setConformance(config.conformance());
    switch(config.quoting()) {
        case DOUBLE_QUOTE:
            parser.switchTo(SqlAbstractParserImpl.LexicalState.DQID);
            break;
        case BACK_TICK:
            parser.switchTo(SqlAbstractParserImpl.LexicalState.BTID);
            break;
        case BRACKET:
            parser.switchTo(SqlAbstractParserImpl.LexicalState.DEFAULT);
            break;
    }
    return parser;
}
Also used : SourceStringReader(org.apache.calcite.util.SourceStringReader) SqlAbstractParserImpl(org.apache.calcite.sql.parser.SqlAbstractParserImpl)

Aggregations

SqlAbstractParserImpl (org.apache.calcite.sql.parser.SqlAbstractParserImpl)1 SourceStringReader (org.apache.calcite.util.SourceStringReader)1