/** * 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; } }
/** * 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; } }
public static UserException.Builder parseError(String query, SqlParseException ex) { final SqlParserPos pos = ex.getPos(); if (pos == null) { return UserException .parseError(ex) .addContext(SQL_QUERY_CONTEXT, query); } else { // Calcite convention is to return column and line numbers as 1-based inclusive positions. return addParseContext(UserException.parseError(ex), query, pos); } }
public SqlNode parse(String sql) { try { SqlParser parser = SqlParser.create(sql, parserConfig); return parser.parseStmt(); } catch (SqlParseException e) { UserException.Builder builder = UserException .parseError(e) .addContext("SQL Query", formatSQLParsingError(sql, e.getPos())); if (isInnerQuery) { builder.message("Failure parsing a view your query is dependent upon."); } throw builder.build(logger); } }
for (Throwable x = ex; x != null; x = x.getCause()) { if ((x instanceof SqlParseException) && (((SqlParseException) x).getPos() != null)) { spe = (SqlParseException) x; break; actualLine = spe.getPos().getLineNum(); actualColumn = spe.getPos().getColumnNum(); actualEndLine = spe.getPos().getEndLineNum(); actualEndColumn = spe.getPos().getEndColumnNum(); if (spe.getCause() != null) { actualException = spe.getCause();
for (Throwable x = ex; x != null; x = x.getCause()) { if ((x instanceof SqlParseException) && (((SqlParseException) x).getPos() != null)) { spe = (SqlParseException) x; break; actualLine = spe.getPos().getLineNum(); actualColumn = spe.getPos().getColumnNum(); actualEndLine = spe.getPos().getEndLineNum(); actualEndColumn = spe.getPos().getEndColumnNum(); if (spe.getCause() != null) { actualException = spe.getCause();