Java Code Examples for org.apache.calcite.sql.parser.SqlParseException#getMessage()

The following examples show how to use org.apache.calcite.sql.parser.SqlParseException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SqlAdvisor.java    From Bats with Apache License 2.0 6 votes vote down vote up
/**
 * Attempts to parse a SQL statement and adds to the errorList if any syntax
 * error is found. This implementation uses {@link SqlParser}. Subclass can
 * re-implement this with a different parser implementation
 *
 * @param sql       A user-input sql statement to be parsed
 * @param errorList A {@link List} of error to be added to
 * @return {@link SqlNode } that is root of the parse tree, null if the sql
 * is not valid
 */
protected SqlNode collectParserError(
    String sql,
    List<ValidateErrorInfo> errorList) {
  try {
    return parseQuery(sql);
  } catch (SqlParseException e) {
    ValidateErrorInfo errInfo =
        new ValidateErrorInfo(
            e.getPos(),
            e.getMessage());

    // parser only returns 1 exception now
    errorList.add(errInfo);
    return null;
  }
}
 
Example 2
Source File: ParserFactory.java    From quark with Apache License 2.0 6 votes vote down vote up
public Parser getParser(String sql, Properties info)
    throws SQLException {
  SqlParser parser = SqlParser.create(sql,
      SqlParser.configBuilder()
          .setQuotedCasing(Casing.UNCHANGED)
          .setUnquotedCasing(Casing.UNCHANGED)
          .setQuoting(Quoting.DOUBLE_QUOTE)
          .setParserFactory(QuarkParserImpl.FACTORY)
          .build());
  SqlNode sqlNode;
  try {
    sqlNode = parser.parseStmt();
  } catch (SqlParseException e) {
    throw new RuntimeException(
        "parse failed: " + e.getMessage(), e);
  }
  if (sqlNode.getKind().equals(SqlKind.OTHER_DDL)) {
    return new DDLParser();
  } else  {
    return getSqlQueryParser(info);
  }
}
 
Example 3
Source File: SqlAdvisor.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Attempts to parse a SQL statement and adds to the errorList if any syntax
 * error is found. This implementation uses {@link SqlParser}. Subclass can
 * re-implement this with a different parser implementation
 *
 * @param sql       A user-input sql statement to be parsed
 * @param errorList A {@link List} of error to be added to
 * @return {@link SqlNode } that is root of the parse tree, null if the sql
 * is not valid
 */
protected SqlNode collectParserError(
    String sql,
    List<ValidateErrorInfo> errorList) {
  try {
    return parseQuery(sql);
  } catch (SqlParseException e) {
    ValidateErrorInfo errInfo =
        new ValidateErrorInfo(
            e.getPos(),
            e.getMessage());

    // parser only returns 1 exception now
    errorList.add(errInfo);
    return null;
  }
}
 
Example 4
Source File: AbstractSqlTester.java    From calcite with Apache License 2.0 6 votes vote down vote up
protected void checkParseEx(Throwable e, String expectedMsgPattern, String sql) {
  try {
    throw e;
  } catch (SqlParseException spe) {
    String errMessage = spe.getMessage();
    if (expectedMsgPattern == null) {
      throw new RuntimeException("Error while parsing query:" + sql, spe);
    } else if (errMessage == null
        || !errMessage.matches(expectedMsgPattern)) {
      throw new RuntimeException("Error did not match expected ["
          + expectedMsgPattern + "] while parsing query ["
          + sql + "]", spe);
    }
  } catch (Throwable t) {
    throw new RuntimeException("Error while parsing query: " + sql, t);
  }
}
 
Example 5
Source File: CalciteParser.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Parses a SQL statement into a {@link SqlNode}. The {@link SqlNode} is not yet validated.
 *
 * @param sql a sql string to parse
 * @return a parsed sql node
 * @throws SqlParserException if an exception is thrown when parsing the statement
 */
public SqlNode parse(String sql) {
	try {
		SqlParser parser = SqlParser.create(sql, config);
		return parser.parseStmt();
	} catch (SqlParseException e) {
		throw new SqlParserException("SQL parse failed. " + e.getMessage(), e);
	}
}
 
Example 6
Source File: CalciteParser.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Parses a SQL statement into a {@link SqlNode}. The {@link SqlNode} is not yet validated.
 *
 * @param sql a sql string to parse
 * @return a parsed sql node
 * @throws SqlParserException if an exception is thrown when parsing the statement
 */
public SqlNode parse(String sql) {
	try {
		SqlParser parser = SqlParser.create(sql, config);
		return parser.parseStmt();
	} catch (SqlParseException e) {
		throw new SqlParserException("SQL parse failed. " + e.getMessage(), e);
	}
}