} catch (SqlParseException e) { logger.debug("fail to do schema completion on the pushdown sql, ignore it.", e.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()); } }
/** * 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()); } }
/** * 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()); } }
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); } }
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); } }
/** * 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; } }
private static List<String> parseTableName(String sql) { TableNameCollector collector = new TableNameCollector(); try { return collector.parseTableName(sql) .stream() .collect(Collectors.toList()); } catch (SqlParseException ex) { throw new RuntimeException(ex.getMessage()); } }
private static List<String> parseTableName(String sql) { TableNameCollector collector = new TableNameCollector(); try { return collector.parseTableName(sql) .stream() .collect(Collectors.toList()); } catch (SqlParseException ex) { throw new RuntimeException(ex.getMessage()); } }
private RelNode buildLogicalPlan(String sql) { Planner planner = Frameworks.getPlanner(config); try { SqlNode parsed = planner.parse(sql); SqlNode validated = planner.validate(parsed); return planner.rel(validated).rel; } catch (SqlParseException ex) { throw new ParseException("Error When Parsing Origin SQL: " + ex.getMessage(), ex); } catch (ValidationException | RelConversionException ev) { throw new ParseException("Error When Validating: " + ev.getMessage(), ev); } catch (Throwable ex) { throw new ParseException( "Unknown Parse Exception, Concrete Message is: " + ex.getMessage()); } }
@Override public RelNode convert(String sql) { SqlWorker.PlannerProgram plannerProgram = SqlWorker.PlannerProgram.EnumerableProgram; Planner planner = config.getPlanner(); try { Class.forName("org.apache.calcite.jdbc.Driver"); planner.close(); planner.reset(); final SqlNode sqlNode = planner.parse(sql); final SqlNode validatedNode = planner.validate(sqlNode); final RelNode convertedNode = planner.convert(validatedNode); return planner.transform(plannerProgram.getIndex(), convertedNode.getTraitSet().plus(EnumerableConvention.INSTANCE).simplify(), convertedNode); } catch (ClassNotFoundException e) { throw new RuntimeException("Error loading calcite Driver: " + e.getMessage(), e); } catch (SqlParseException e) { throw new RuntimeException("SqlParsing failed: " + e.getMessage(), e); } catch (ValidationException e) { throw new RuntimeException("Sql Validation failed: " + e.getMessage(), e); } catch (RelConversionException e) { throw new RuntimeException("Sql to RelNode conversion or transformation failed: " + e.getMessage(), e); } } }
} catch (SqlParseException e) { logger.debug("fail to do schema completion on the pushdown sql, ignore it.", e.getMessage());
@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.")); } }
@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.")); } }
private RelNode buildLogicalPlan(String sql) { Planner planner = Frameworks.getPlanner(config); try { SqlNode parsed = planner.parse(sql); SqlNode validated = planner.validate(parsed); return planner.rel(validated).rel; } catch (SqlParseException ex) { throw new ParseException("Error When Parsing Origin SQL: " + ex.getMessage(), ex); } catch (ValidationException | RelConversionException ev) { throw new ParseException("Error When Validating: " + ev.getMessage(), ev); } catch (Throwable ex) { throw new ParseException("Unknown Parse Exception, Concrete Message is: " + ex.getMessage()); } }
ParserErrors.INST.parParseContextError(e.getMessage()), e);
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); } } }
} catch (SqlParseException e) { throw new RuntimeException( "parse failed: " + e.getMessage(), e);
} catch (SqlParseException e) { throw new RuntimeException( "parse failed: " + e.getMessage(), e);