return new SqlParseException( ex.getMessage(), pos, expectedTokenSequences, tokenImage, ex);
} catch (SqlParseException e) { logger.debug("fail to do schema completion on the pushdown sql, ignore it.", e.getMessage());
/** * 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; } }
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(); actualMessage = actualException.getMessage();
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); } }
} catch (SqlParseException parseException) { final String[] tokenImages = parseException.getTokenImages(); if (tokenSet.isEmpty()) { for (String token : tokenImages) { parseException.getExpectedTokenSequences(); for (final int[] tokens : expectedTokenSequences) { assert tokens.length == 1;
return parseQuery(sql); } catch (SqlParseException e) { for (String tokenName : e.getExpectedTokenNames()) {
/** * 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; } }
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(); actualMessage = actualException.getMessage();
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); } }
} catch (SqlParseException parseException) { final String[] tokenImages = parseException.getTokenImages(); if (tokenSet.isEmpty()) { for (String token : tokenImages) { parseException.getExpectedTokenSequences(); for (final int[] tokens : expectedTokenSequences) { assert tokens.length == 1;
return parseQuery(sql); } catch (SqlParseException e) { for (String tokenName : e.getExpectedTokenNames()) {
/** * Per {@link java.io.Serializable} API, provides a replacement object to be * written during serialization. * * <p>SqlParseException is serializable but is not available on the client. * This implementation converts this SqlParseException into a vanilla * {@link RuntimeException} with the same message. */ private Object writeReplace() { return new RuntimeException( getClass().getName() + ": " + getMessage()); } }
return new SqlParseException( ex.getMessage(), pos, expectedTokenSequences, tokenImage, ex);
e.getPos() == null ? new SqlParserPos(-1, -1) : e.getPos(), ParserErrors.INST.parParseContextError(e.getMessage()), e);
/** * Per {@link java.io.Serializable} API, provides a replacement object to be * written during serialization. * * <p>SqlParseException is serializable but is not available on the client. * This implementation converts this SqlParseException into a vanilla * {@link RuntimeException} with the same message. */ private Object writeReplace() { return new RuntimeException( getClass().getName() + ": " + getMessage()); } }
return new SqlParseException( ex.getMessage(), pos, expectedTokenSequences, tokenImage, ex);
/** * Parse table names. * * @param sql sql string * @return table names */ public static List<String> parseTableName(String sql) { TableNameCollector collector = new TableNameCollector(); try { return new ArrayList<>(collector.parseTableName(sql)); } catch (SqlParseException ex) { throw new RuntimeException(ex.getMessage()); } }
return new SqlParseException( ex.getMessage(), pos, expectedTokenSequences, tokenImage, ex);
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); } }