本文整理汇总了Java中org.apache.calcite.sql.parser.SqlParser.parseQuery方法的典型用法代码示例。如果您正苦于以下问题:Java SqlParser.parseQuery方法的具体用法?Java SqlParser.parseQuery怎么用?Java SqlParser.parseQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.calcite.sql.parser.SqlParser
的用法示例。
在下文中一共展示了SqlParser.parseQuery方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: stripNamespace
import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
/**
* Strips the dataSource name from the query
* @param query
* @param dataSource
* @return
* @throws QuarkException
*/
private String stripNamespace(final String query,
final DataSourceSchema dataSource)
throws QuarkException {
String result = query.replace("\n", " ");
if (dataSource != null) {
try {
final SqlParser parser = getSqlParser(query);
SqlNode node = parser.parseQuery();
result = stripNamespace(node, dataSource.getName(),
dataSource.getDataSource().getSqlDialect());
} catch (Exception e) {
LOG.warn("Exception while parsing the input query: " + e.getMessage());
}
}
return result;
}
示例2: expandView
import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
@Override public RelRoot expandView(RelDataType rowType, String queryString,
List<String> schemaPath, List<String> viewPath) {
expansionDepth++;
SqlParser parser = prepare.createParser(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 CatalogReader catalogReader =
this.catalogReader.withSchemaPath(schemaPath);
SqlValidator validator = createSqlValidator(catalogReader);
SqlNode sqlNode1 = validator.validate(sqlNode);
final SqlToRelConverter.Config config = SqlToRelConverter.configBuilder()
.withTrimUnusedFields(true).build();
SqlToRelConverter sqlToRelConverter =
getSqlToRelConverter(validator, catalogReader, config);
RelRoot root =
sqlToRelConverter.convertQuery(sqlNode1, true, false);
--expansionDepth;
return root;
}
示例3: expandView
import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
@Override public RelRoot expandView(RelDataType rowType, String queryString,
List<String> schemaPath, List<String> viewPath) {
expansionDepth++;
SqlParser parser = prepare.createParser(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 CatalogReader catalogReader =
this.catalogReader.withSchemaPath(schemaPath);
SqlValidator validator = createSqlValidator(catalogReader);
SqlNode sqlNode1 = validator.validate(sqlNode);
final SqlToRelConverter.Config config = SqlToRelConverter.configBuilder()
.withTrimUnusedFields(true).build();
SqlToRelConverter sqlToRelConverter =
getSqlToRelConverter(validator, catalogReader, config);
RelRoot root =
sqlToRelConverter.convertQuery(sqlNode1, true, false);
--expansionDepth;
return root;
}
示例4: checkSqlParsing
import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
public static void checkSqlParsing(String sql, Properties info, String expectedSql,
SqlDialect dialect)
throws QuarkException, SqlParseException {
SqlQueryParser parser = new SqlQueryParser(info);
SqlParser sqlParser = parser.getSqlParser(sql);
SqlNode sqlNode = sqlParser.parseQuery();
String finalQuery = sqlNode.toSqlString(dialect).getSql();
assertEquals(expectedSql, finalQuery.replace("\n", " "));
}
示例5: expandView
import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
@Override public RelRoot expandView(RelDataType rowType, String queryString,
List<String> schemaPath, List<String> viewPath) {
SqlParser parser = SqlParser.create(queryString, parserConfig);
SqlNode sqlNode;
try {
sqlNode = parser.parseQuery();
} catch (SqlParseException e) {
throw new RuntimeException("parse failed", e);
}
final SqlConformance conformance = conformance();
final CalciteCatalogReader catalogReader =
createCatalogReader().withSchemaPath(schemaPath);
final SqlValidator validator =
new CalciteSqlValidator(operatorTable, catalogReader, typeFactory,
conformance);
validator.setIdentifierExpansion(true);
final SqlNode validatedSqlNode = validator.validate(sqlNode);
final RexBuilder rexBuilder = createRexBuilder();
final RelOptCluster cluster = RelOptCluster.create(planner, rexBuilder);
final SqlToRelConverter.Config config = SqlToRelConverter
.configBuilder()
.withConfig(sqlToRelConverterConfig)
.withTrimUnusedFields(false)
.withConvertTableAccess(false)
.build();
final SqlToRelConverter sqlToRelConverter =
new SqlToRelConverter(new ViewExpanderImpl(), validator,
catalogReader, cluster, convertletTable, config);
root = sqlToRelConverter.convertQuery(validatedSqlNode, true, false);
root = root.withRel(sqlToRelConverter.flattenTypes(root.rel, true));
root = root.withRel(RelDecorrelator.decorrelateQuery(root.rel));
return PlannerImpl.this.root;
}
示例6: parse
import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
public static SqlNode parse(String sql) throws SqlParseException {
SqlParser.ConfigBuilder parserBuilder = SqlParser.configBuilder();
SqlParser sqlParser = SqlParser.create(sql, parserBuilder.build());
return sqlParser.parseQuery();
}
示例7: parseQuery
import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
public SqlNode parseQuery(String sql) throws SqlParseException {
SqlParser parser = factory.createParser(factory, sql);
return parser.parseQuery();
}
示例8: parseQuery
import org.apache.calcite.sql.parser.SqlParser; //导入方法依赖的package包/类
public SqlNode parseQuery(String sql) throws Exception {
SqlParser parser = SqlParser.create(sql);
return parser.parseQuery();
}