/** * Returns the underlying Parser implementation class. * * <p>To use a different parser (recognizing a different dialect of SQL), * derived class should override. * * @return a {@link SqlAbstractParserImpl} instance */ protected SqlAbstractParserImpl getParserImpl() { SqlParser parser = new SqlParser(new StringReader("")); return parser.getParserImpl(); }
/** * Wrapper function to parse a SQL query (SELECT or VALUES, but not INSERT, * UPDATE, DELETE, CREATE, DROP etc.), throwing a {@link SqlParseException} * if the statement is not syntactically valid. * * @param sql SQL statement * * @return parse tree * * @throws SqlParseException if not syntactically valid */ protected SqlNode parseQuery(String sql) throws SqlParseException { SqlParser parser = new SqlParser(sql); return parser.parseStmt(); }
/** * Creates a <code>SqlParser</code> to parse the given string using the * parser implementation created from given {@link SqlParserImplFactory} * with given quoting syntax and casing policies for identifiers. * * @param parserFactory {@link SqlParserImplFactory} to get the parser * implementation. * @param s An SQL statement or expression to parse. * @param quoting Syntax for quoting identifiers in SQL statements. * @param unquotedCasing Policy for converting case of <i>unquoted</i> * identifiers. * @param quotedCasing Policy for converting case of <i>quoted</i> * identifiers. * @return A <code>SqlParser</code> object. */ public static SqlParser create(SqlParserImplFactory parserFactory, String s, Quoting quoting, Casing unquotedCasing, Casing quotedCasing) { SqlAbstractParserImpl parser = parserFactory.getParser( new StringReader(s)); return new SqlParser(s, parser, quoting, unquotedCasing, quotedCasing); }
public SqlNode parseQuery(String sql) throws SqlParseException { SqlParser parser = new SqlParser(sql); return parser.parseQuery(); }
protected SqlNode parseExpression(String sql) throws SqlParseException { return new SqlParser(sql).parseExpression(); }
protected SqlNode parseStmt(String sql) throws SqlParseException { return new SqlParser(sql).parseStmt(); }
public SqlNode parseQuery(String sql) throws Exception { SqlParser parser = new SqlParser(sql); SqlNode sqlNode = parser.parseQuery(); return sqlNode; }
protected SqlParserImpl getParserImpl() { return new SqlParser("").getParserImpl(); }
/** * Parses a SQL query. To use a different parser, override this method. */ protected SqlNode parseQuery(String sql) { SqlNode node; try { node = new SqlParser(sql).parseQuery(); } catch (SqlParseException e) { String message = "Received error while parsing SQL '" + sql + "'; error is:" + NL + e.toString(); throw new AssertionError(message); } return node; }
@Override public RelNode expandView( RelDataType rowType, String queryString, List<String> schemaPath) { expansionDepth++; SqlParser parser = new SqlParser(queryString); SqlNode sqlNode; try { sqlNode = parser.parseQuery(); } catch (SqlParseException e) { throw new RuntimeException("parse failed", e); } // View may have different schema path than current connection. final OptiqCatalogReader catalogReader = new OptiqCatalogReader( ((OptiqCatalogReader) this.catalogReader).rootSchema, schemaPath, ((OptiqCatalogReader) this.catalogReader).typeFactory); SqlValidator validator = createSqlValidator(catalogReader); SqlNode sqlNode1 = validator.validate(sqlNode); SqlToRelConverter sqlToRelConverter = getSqlToRelConverter(validator, catalogReader); RelNode relNode = sqlToRelConverter.convertQuery(sqlNode1, true, false); --expansionDepth; return relNode; }
/** Populates a materialization record, converting a table path * (essentially a list of strings, like ["hr", "sales"]) into a table object * that can be used in the planning process. */ void populate(Materialization materialization) { SqlParser parser = new SqlParser(materialization.sql); SqlNode node; try { node = parser.parseStmt(); } catch (SqlParseException e) { throw new RuntimeException("parse failed", e); } SqlToRelConverter sqlToRelConverter2 = getSqlToRelConverter(getSqlValidator(), catalogReader); materialization.queryRel = sqlToRelConverter2.convertQuery(node, true, true); RelOptTable table = catalogReader.getTable(materialization.materializedTable.path()); materialization.tableRel = table.toRel(sqlToRelConverter2.makeToRelContext()); } }
public ParseResult parse( Context context, String sql) { final JavaTypeFactory typeFactory = context.getTypeFactory(); OptiqCatalogReader catalogReader = new OptiqCatalogReader( context.getRootSchema(), context.getDefaultSchemaPath(), typeFactory); SqlParser parser = new SqlParser(sql); SqlNode sqlNode; try { sqlNode = parser.parseStmt(); } catch (SqlParseException e) { throw new RuntimeException("parse failed", e); } final SqlValidator validator = new OptiqSqlValidator( SqlStdOperatorTable.instance(), catalogReader, typeFactory); SqlNode sqlNode1 = validator.validate(sqlNode); return new ParseResult( sql, sqlNode1, validator.getValidatedNodeType(sqlNode1)); }
if (sql != null) { assert queryable == null; SqlParser parser = new SqlParser(sql); SqlNode sqlNode; try {