/** * 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; } }
return parseQuery(sql); } catch (SqlParseException e) { for (String tokenName : e.getExpectedTokenNames()) {
protected SqlNode parseStmtAndHandleEx(String sql) { final SqlNode sqlNode; try { sqlNode = parseStmt(sql); } catch (SqlParseException e) { e.printStackTrace(); String message = "Received error while parsing SQL '" + sql + "'; error is:\n" + e.toString(); throw new AssertionError(message); } return sqlNode; }
validator = getValidator(); } catch (SqlParseException e) { String errMessage = e.getMessage(); if (expectedMsgPattern == null) { e.printStackTrace(); throw new AssertionError( "Error while parsing query [" + sap.sql + "]"); || !errMessage.matches(expectedMsgPattern)) e.printStackTrace(); throw new AssertionError( "Error did not match expected ["
for (Throwable x = ex; x != null; x = x.getCause()) { if ((x instanceof SqlParseException) && (((SqlParseException) x).getPos() != null)) 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();
/** * 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()); } }
} 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;
protected SqlNode parseExpressionAndHandleEx(String sql) { final SqlNode sqlNode; try { sqlNode = parseExpression(sql); } catch (SqlParseException e) { String message = "Received error while parsing SQL '" + sql + "'; error is:\n" + e.toString(); throw new RuntimeException(message, e); } return sqlNode; }
return new SqlParseException( ex.getMessage(), pos, expectedTokenSequences, tokenImage, ex);
validator = getValidator(); } catch (SqlParseException e) { String errMessage = e.getMessage(); if (expectedMsgPattern == null) { e.printStackTrace(); throw new AssertionError( "Error while parsing query [" + sap.sql + "]"); (null == errMessage) || !errMessage.matches(expectedMsgPattern)) { e.printStackTrace(); throw new AssertionError( "Error did not match expected ["
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();
/** * 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()); } }
} 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;
protected SqlNode parseExpressionAndHandleEx(String sql) { final SqlNode sqlNode; try { sqlNode = parseExpression(sql); } catch (SqlParseException e) { String message = "Received error while parsing SQL '" + sql + "'; error is:\n" + e.toString(); throw new RuntimeException(message, e); } return sqlNode; }
return new SqlParseException( ex.getMessage(), pos, expectedTokenSequences, tokenImage, ex);
/** * 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; } }
@Test public void testParseFails() throws SqlParseException { Planner planner = getPlanner(null); try { SqlNode parse = planner.parse("select * * from \"emps\""); fail("expected error, got " + parse); } catch (SqlParseException e) { assertThat(e.getMessage(), containsString("Encountered \"*\" at line 1, column 10.")); } }
protected SqlNode parseStmtAndHandleEx(String sql) { final SqlNode sqlNode; try { sqlNode = parseStmt(sql); } catch (SqlParseException e) { e.printStackTrace(); String message = "Received error while parsing SQL '" + sql + "'; error is:\n" + e.toString(); throw new AssertionError(message); } return sqlNode; }
/** * Parses a SQL query. To use a different parser, override this method. */ protected SqlNode parseQuery(String sql) { SqlNode node; try { node = SqlParser.create(sql).parseQuery(); } catch (SqlParseException e) { String message = "Received error while parsing SQL '" + sql + "'; error is:" + NL + e.toString(); throw new AssertionError(message); } return node; }
return parseQuery(sql); } catch (SqlParseException e) { for (String tokenName : e.getExpectedTokenNames()) {