/** * Creates a call. * * @param funName Name of function * @param pos Position in source code * @param funcType Type of function * @param functionQualifier Qualifier * @param operands Operands to call * @return Call */ protected SqlCall createCall( SqlIdentifier funName, SqlParserPos pos, SqlFunctionCategory funcType, SqlLiteral functionQualifier, Iterable<? extends SqlNode> operands) { return createCall(funName, pos, funcType, functionQualifier, Iterables.toArray(operands, SqlNode.class)); }
/** * Get the parser metadata. * * @return {@link SqlAbstractParserImpl.Metadata} implementation of * underlying parser. */ public SqlAbstractParserImpl.Metadata getMetadata() { return parser.getMetadata(); }
/** * Parses a SQL expression. * * @throws SqlParseException if there is a parse error */ public SqlNode parseExpression() throws SqlParseException { try { return parser.parseSqlExpressionEof(); } catch (Throwable ex) { if (ex instanceof CalciteContextException) { final String originalSql = parser.getOriginalSql(); if (originalSql != null) { ((CalciteContextException) ex).setOriginalStatement(originalSql); } } throw parser.normalizeException(ex); } }
/** * Parses a <code>SELECT</code> statement. * * @return A {@link org.apache.calcite.sql.SqlSelect} for a regular <code> * SELECT</code> statement; a {@link org.apache.calcite.sql.SqlBinaryOperator} * for a <code>UNION</code>, <code>INTERSECT</code>, or <code>EXCEPT</code>. * @throws SqlParseException if there is a parse error */ public SqlNode parseQuery() throws SqlParseException { try { return parser.parseSqlStmtEof(); } catch (Throwable ex) { if (ex instanceof CalciteContextException) { final String originalSql = parser.getOriginalSql(); if (originalSql != null) { ((CalciteContextException) ex).setOriginalStatement(originalSql); } } throw parser.normalizeException(ex); } }
/** * Parses a SQL expression. * * @throws SqlParseException if there is a parse error */ public SqlNode parseExpression() throws SqlParseException { try { return parser.parseSqlExpressionEof(); } catch (Throwable ex) { if ((ex instanceof CalciteContextException) && (originalInput != null)) { ((CalciteContextException) ex).setOriginalStatement( originalInput); } throw parser.normalizeException(ex); } }
private SqlParser(String s, SqlAbstractParserImpl parser, Config config) { this.originalInput = s; this.parser = parser; parser.setOriginalSql(s); parser.setTabSize(1); parser.setQuotedCasing(config.quotedCasing()); parser.setUnquotedCasing(config.unquotedCasing()); parser.setIdentifierMaxLength(config.identifierMaxLength()); parser.setConformance(config.conformance()); switch (config.quoting()) { case DOUBLE_QUOTE: parser.switchTo("DQID"); break; case BACK_TICK: parser.switchTo("BTID"); break; case BRACKET: parser.switchTo("DEFAULT"); break; } }
@Override public SqlAbstractParserImpl getParser(Reader stream) { SqlAbstractParserImpl parserImpl = new ParserWithCompoundIdConverter(stream); parserImpl.setIdentifierMaxLength(PlannerSettings.DEFAULT_IDENTIFIER_MAX_LENGTH); return parserImpl; } };
/** * Parses a <code>SELECT</code> statement. * * @return A {@link org.apache.calcite.sql.SqlSelect} for a regular <code> * SELECT</code> statement; a {@link org.apache.calcite.sql.SqlBinaryOperator} * for a <code>UNION</code>, <code>INTERSECT</code>, or <code>EXCEPT</code>. * @throws SqlParseException if there is a parse error */ public SqlNode parseQuery() throws SqlParseException { try { return parser.parseSqlStmtEof(); } catch (Throwable ex) { if ((ex instanceof CalciteContextException) && (originalInput != null)) { ((CalciteContextException) ex).setOriginalStatement( originalInput); } throw parser.normalizeException(ex); } }
/** * Parses a <code>SELECT</code> statement and reuses parser. * * @param sql sql to parse * @return A {@link org.apache.calcite.sql.SqlSelect} for a regular <code> * SELECT</code> statement; a {@link org.apache.calcite.sql.SqlBinaryOperator} * for a <code>UNION</code>, <code>INTERSECT</code>, or <code>EXCEPT</code>. * @throws SqlParseException if there is a parse error */ public SqlNode parseQuery(String sql) throws SqlParseException { parser.ReInit(new StringReader(sql)); return parseQuery(); }
/** Adds the position of the last token emitted by a parser to the list, * and returns this Span. */ public Span add(SqlAbstractParserImpl parser) { try { final SqlParserPos pos = parser.getPos(); return add(pos); } catch (Exception e) { // getPos does not really throw an exception throw new AssertionError(e); } }
private void ensureReservedAndKeyWords() { if (reservedWordsSet != null) { return; } Collection<String> c = SqlAbstractParserImpl.getSql92ReservedWords(); List<String> l = Arrays.asList( getParserMetadata().getJdbcKeywords().split(",")); List<String> al = new ArrayList<>(); al.addAll(c); al.addAll(l); reservedWordsList = al; reservedWordsSet = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); reservedWordsSet.addAll(reservedWordsList); }
/** * Uses reflection to invoke a method on this parser. The method must be * public and have no parameters. * * @param parserImpl Parser * @param name Name of method. For example "ReservedFunctionName". * @return Result of calling method */ private Object virtualCall( SqlAbstractParserImpl parserImpl, String name) throws Throwable { Class<?> clazz = parserImpl.getClass(); try { final Method method = clazz.getMethod(name, (Class[]) null); return method.invoke(parserImpl, (Object[]) null); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); throw parserImpl.normalizeException(cause); } }
private SqlParser(SqlAbstractParserImpl parser, Config config) { this.parser = parser; parser.setTabSize(1); parser.setQuotedCasing(config.quotedCasing()); parser.setUnquotedCasing(config.unquotedCasing()); parser.setIdentifierMaxLength(config.identifierMaxLength()); parser.setConformance(config.conformance()); switch (config.quoting()) { case DOUBLE_QUOTE: parser.switchTo("DQID"); break; case BACK_TICK: parser.switchTo("BTID"); break; case BRACKET: parser.switchTo("DEFAULT"); break; } }
public SqlAbstractParserImpl getParser(Reader stream) { SqlAbstractParserImpl parserImpl = new DrillParserWithCompoundIdConverter(stream); parserImpl.setIdentifierMaxLength(PlannerSettings.DEFAULT_IDENTIFIER_MAX_LENGTH); return parserImpl; } };
/** * Parses a <code>SELECT</code> statement and reuses parser. * * @param sql sql to parse * @return A {@link org.apache.calcite.sql.SqlSelect} for a regular <code> * SELECT</code> statement; a {@link org.apache.calcite.sql.SqlBinaryOperator} * for a <code>UNION</code>, <code>INTERSECT</code>, or <code>EXCEPT</code>. * @throws SqlParseException if there is a parse error */ public SqlNode parseQuery(String sql) throws SqlParseException { parser.ReInit(new StringReader(sql)); return parseQuery(); }
/** Adds the position of the last token emitted by a parser to the list, * and returns this Span. */ public Span add(SqlAbstractParserImpl parser) { try { final SqlParserPos pos = parser.getPos(); return add(pos); } catch (Exception e) { // getPos does not really throw an exception throw new AssertionError(e); } }
private void ensureReservedAndKeyWords() { if (reservedWordsSet != null) { return; } Collection<String> c = SqlAbstractParserImpl.getSql92ReservedWords(); List<String> l = Arrays.asList( getParserMetadata().getJdbcKeywords().split(",")); List<String> al = new ArrayList<>(); al.addAll(c); al.addAll(l); reservedWordsList = al; reservedWordsSet = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); reservedWordsSet.addAll(reservedWordsList); }
/** * Uses reflection to invoke a method on this parser. The method must be * public and have no parameters. * * @param parserImpl Parser * @param name Name of method. For example "ReservedFunctionName". * @return Result of calling method */ private Object virtualCall( SqlAbstractParserImpl parserImpl, String name) throws Throwable { Class<?> clazz = parserImpl.getClass(); try { final Method method = clazz.getMethod(name, (Class[]) null); return method.invoke(parserImpl, (Object[]) null); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); throw parserImpl.normalizeException(cause); } }
Set<String> keywords, String name) { parserImpl.ReInit(new StringReader("1")); try { Object o = virtualCall(parserImpl, name);
/** * Get the parser metadata. * * @return {@link SqlAbstractParserImpl.Metadata} implementation of * underlying parser. */ public SqlAbstractParserImpl.Metadata getMetadata() { return parser.getMetadata(); }