本文整理汇总了Java中org.apache.calcite.sql.parser.SqlParser.parseStmt方法的典型用法代码示例。如果您正苦于以下问题:Java SqlParser.parseStmt方法的具体用法?Java SqlParser.parseStmt怎么用?Java SqlParser.parseStmt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.calcite.sql.parser.SqlParser
的用法示例。
在下文中一共展示了SqlParser.parseStmt方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getParser
import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
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);
}
}
示例2: parse_
import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
/** Shared implementation for {@link #parse}, {@link #convert} and
* {@link #analyzeView}. */
private ParseResult parse_(Context context, String sql, boolean convert,
boolean analyze, boolean fail) {
final JavaTypeFactory typeFactory = context.getTypeFactory();
CalciteCatalogReader catalogReader =
new CalciteCatalogReader(
context.getRootSchema(),
context.config().caseSensitive(),
context.getDefaultSchemaPath(),
typeFactory);
SqlParser parser = createParser(sql);
SqlNode sqlNode;
try {
sqlNode = parser.parseStmt();
} catch (SqlParseException e) {
throw new RuntimeException("parse failed", e);
}
final SqlValidator validator = createSqlValidator(context, catalogReader);
SqlNode sqlNode1 = validator.validate(sqlNode);
if (convert) {
return convert_(
context, sql, analyze, fail, catalogReader, validator, sqlNode1);
}
return new ParseResult(this, validator, sql, sqlNode1,
validator.getValidatedNodeType(sqlNode1));
}
示例3: parse_
import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
/** Shared implementation for {@link #parse}, {@link #convert} and
* {@link #analyzeView}. */
private ParseResult parse_(Context context, String sql, boolean convert,
boolean analyze, boolean fail) {
final JavaTypeFactory typeFactory = context.getTypeFactory();
CalciteCatalogReader catalogReader =
new CalciteCatalogReader(
context.getRootSchema(),
context.getDefaultSchemaPath(),
typeFactory,
context.config());
SqlParser parser = createParser(sql);
SqlNode sqlNode;
try {
sqlNode = parser.parseStmt();
} catch (SqlParseException e) {
throw new RuntimeException("parse failed", e);
}
final SqlValidator validator = createSqlValidator(context, catalogReader);
SqlNode sqlNode1 = validator.validate(sqlNode);
if (convert) {
return convert_(
context, sql, analyze, fail, catalogReader, validator, sqlNode1);
}
return new ParseResult(this, validator, sql, sqlNode1,
validator.getValidatedNodeType(sqlNode1));
}
示例4: testUpdateSql
import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
@Test
public void testUpdateSql() throws Exception {
final String sql = "select foo, bar as b from tbl";
SqlParser parser = SqlParser.create(sql, new ParserConfig(Quoting.DOUBLE_QUOTE, 128));
final SqlNode sqlNode = parser.parseStmt();
final JavaTypeFactory typeFactory = new JavaTypeFactoryImpl();
final RelDataType rowType = new RelRecordType(Arrays.<RelDataTypeField>asList(
new RelDataTypeFieldImpl("foo", 0, typeFactory.createSqlType(SqlTypeName.INTEGER)),
new RelDataTypeFieldImpl("b", 0, typeFactory.createSqlType(SqlTypeName.INTEGER))
));
TransformActor actor = new TransformActor(state, false, "test_user", null) {
@Override
protected QueryMetadata getMetadata(SqlQuery query) {
return new QueryMetadata(null, null, null, null, sqlNode, rowType, null, null, null, null, BatchSchema.fromCalciteRowType(rowType));
}
@Override
protected boolean hasMetadata() {
return true;
}
};
TransformResult result = new TransformUpdateSQL(sql).accept(actor);
VirtualDatasetState newState = result.getNewState();
assertEquals(2, newState.getColumnsList().size());
assertEquals("foo", newState.getColumnsList().get(0).getName());
assertEquals(new ExpColumnReference("foo").wrap(), newState.getColumnsList().get(0).getValue());
assertEquals("b", newState.getColumnsList().get(1).getName());
assertEquals(new ExpColumnReference("bar").wrap(), newState.getColumnsList().get(1).getValue());
}
示例5: parse
import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
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);
}
}
示例6: parseSql
import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private T parseSql(String sql) throws SQLException {
logger.debug("[parseSql]");
try {
SqlParser sqlParser = SqlParser.create(sql, SqlParser.configBuilder()
.setParserFactory(SqlParserImpl.FACTORY)
.setUnquotedCasing(Casing.TO_LOWER)
.setQuoting(Quoting.DOUBLE_QUOTE)
.build());
return (T) sqlParser.parseStmt();
} catch (SqlParseException exc) {
throw new SQLException("Could not parse sql: " + sql, exc);
}
}
示例7: populate
import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
/** 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 = SqlParser.create(materialization.sql);
SqlNode node;
try {
node = parser.parseStmt();
} catch (SqlParseException e) {
throw new RuntimeException("parse failed", e);
}
final SqlToRelConverter.Config config = SqlToRelConverter.configBuilder()
.withTrimUnusedFields(true).build();
SqlToRelConverter sqlToRelConverter2 =
getSqlToRelConverter(getSqlValidator(), catalogReader, config);
materialization.queryRel =
sqlToRelConverter2.convertQuery(node, true, true).rel;
// Identify and substitute a StarTable in queryRel.
//
// It is possible that no StarTables match. That is OK, but the
// materialization patterns that are recognized will not be as rich.
//
// It is possible that more than one StarTable matches. TBD: should we
// take the best (whatever that means), or all of them?
useStar(schema, materialization);
RelOptTable table =
this.catalogReader.getTable(materialization.materializedTable.path());
materialization.tableRel = sqlToRelConverter2.toRel(table);
}
示例8: parse
import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
public SqlNode parse(final String sql) throws SqlParseException {
switch (state) {
case STATE_0_CLOSED:
case STATE_1_RESET:
ready();
}
ensure(State.STATE_2_READY);
SqlParser parser = SqlParser.create(sql, parserConfig);
SqlNode sqlNode = parser.parseStmt();
state = State.STATE_3_PARSED;
return sqlNode;
}
示例9: parse
import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
private SqlNode parse(String toParse) throws SqlParseException{
ParserConfig config = new ParserConfig(Quoting.DOUBLE_QUOTE, 255);
SqlParser parser = SqlParser.create(toParse, config);
return parser.parseStmt();
}
示例10: parseQuery
import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
/**
* 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 = SqlParser.create(sql);
return parser.parseStmt();
}