本文整理汇总了Java中org.apache.calcite.sql.parser.SqlParser类的典型用法代码示例。如果您正苦于以下问题:Java SqlParser类的具体用法?Java SqlParser怎么用?Java SqlParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SqlParser类属于org.apache.calcite.sql.parser包,在下文中一共展示了SqlParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: trans
import org.apache.calcite.sql.parser.SqlParser; //导入依赖的package包/类
private String trans(String sql) throws Exception {
Properties info = new Properties();
info.setProperty("lex", "JAVA");
String jsonFile = SolrSqlTest.class.getClassLoader().getResource("solr.json").toString().replaceAll("file:/", "");
try {
Class.forName("org.apache.calcite.jdbc.Driver");
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
}
CalciteConnection connection = (CalciteConnection) DriverManager.getConnection("jdbc:calcite:model="+jsonFile, info);
final SchemaPlus schema = connection.getRootSchema().getSubSchema("solr");
connection.close();
ConfigBuilder builder = Frameworks.newConfigBuilder().defaultSchema(schema).parserConfig(SqlParser.configBuilder().setCaseSensitive(false).build());
FrameworkConfig config = builder.build();
Planner planner = Frameworks.getPlanner(config);
SqlNode sqlNode = planner.parse(sql);
SqlNode node = planner.validate(sqlNode);
RelRoot relRoot = planner.rel(node);
RelNode project = relRoot.project();
RexNode condition = ((Filter) ((Project) project).getInput()).getCondition();
return _trans.translate(condition).toSolrQueryString();
}
示例2: main
import org.apache.calcite.sql.parser.SqlParser; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
if (args.length != 1) {
throw new IllegalArgumentException("Usage: java {cp} " + SqlReservedKeywordGenerator.class.getName() +
" path/where/to/write/the/file");
}
final File outputFile = new File(args[0], RESERVED_KEYWORD_FILE_NAME);
System.out.println("Writing reserved SQL keywords to file: " + outputFile.getAbsolutePath());
try(PrintWriter outFile = new PrintWriter(new OutputStreamWriter(new FileOutputStream(outputFile), UTF_8))) {
outFile.printf("# AUTO-GENERATED LIST OF SQL RESERVED KEYWORDS (generated by %s)",
SqlReservedKeywordGenerator.class.getName());
outFile.println();
final SqlAbstractParserImpl.Metadata metadata = SqlParser.create("", new ParserConfig(Quoting.DOUBLE_QUOTE, 256)).getMetadata();
for (String s : metadata.getTokens()) {
if (metadata.isKeyword(s) && metadata.isReservedWord(s)) {
outFile.println(s);
}
}
}
}
示例3: prepare
import org.apache.calcite.sql.parser.SqlParser; //导入依赖的package包/类
@BeforeClass
public static void prepare() {
relDataType = TYPE_FACTORY.builder()
.add("order_id", SqlTypeName.BIGINT)
.add("site_id", SqlTypeName.INTEGER)
.add("price", SqlTypeName.DOUBLE)
.add("order_time", SqlTypeName.BIGINT).build();
beamRowType = CalciteUtils.toBeamRowType(relDataType);
record = new BeamRecord(beamRowType
, 1234567L, 0, 8.9, 1234567L);
SchemaPlus schema = Frameworks.createRootSchema(true);
final List<RelTraitDef> traitDefs = new ArrayList<>();
traitDefs.add(ConventionTraitDef.INSTANCE);
traitDefs.add(RelCollationTraitDef.INSTANCE);
FrameworkConfig config = Frameworks.newConfigBuilder()
.parserConfig(SqlParser.configBuilder().setLex(Lex.MYSQL).build()).defaultSchema(schema)
.traitDefs(traitDefs).context(Contexts.EMPTY_CONTEXT).ruleSets(BeamRuleSets.getRuleSets())
.costFactory(null).typeSystem(BeamRelDataTypeSystem.BEAM_REL_DATATYPE_SYSTEM).build();
relBuilder = RelBuilder.create(config);
}
示例4: addProperty
import org.apache.calcite.sql.parser.SqlParser; //导入依赖的package包/类
private ImmutableMap.Builder<DatabaseProperty, Object> addProperty(
ImmutableMap.Builder<DatabaseProperty, Object> builder,
DatabaseProperty p) {
switch (p) {
case GET_S_Q_L_KEYWORDS:
return builder.put(p,
SqlParser.create("").getMetadata().getJdbcKeywords());
case GET_NUMERIC_FUNCTIONS:
return builder.put(p, SqlJdbcFunctionCall.getNumericFunctions());
case GET_STRING_FUNCTIONS:
return builder.put(p, SqlJdbcFunctionCall.getStringFunctions());
case GET_SYSTEM_FUNCTIONS:
return builder.put(p, SqlJdbcFunctionCall.getSystemFunctions());
case GET_TIME_DATE_FUNCTIONS:
return builder.put(p, SqlJdbcFunctionCall.getTimeDateFunctions());
default:
return builder;
}
}
示例5: GremlinCompiler
import org.apache.calcite.sql.parser.SqlParser; //导入依赖的package包/类
public GremlinCompiler(Graph graph, SchemaConfig schemaConfig) {
this.graph = graph;
this.schemaConfig = schemaConfig;
final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
final List<RelTraitDef> traitDefs = new ArrayList<>();
traitDefs.add(ConventionTraitDef.INSTANCE);
traitDefs.add(RelCollationTraitDef.INSTANCE);
final SqlParser.Config parserConfig =
SqlParser.configBuilder().setLex(Lex.MYSQL).build();
frameworkConfig = Frameworks.newConfigBuilder()
.parserConfig(parserConfig)
.defaultSchema(rootSchema.add("gremlin", new GremlinSchema(graph, schemaConfig)))
.traitDefs(traitDefs)
.programs(Programs.sequence(Programs.ofRules(Programs.RULE_SET), Programs.CALC_PROGRAM))
.build();
}
示例6: createPlanner
import org.apache.calcite.sql.parser.SqlParser; //导入依赖的package包/类
private static Planner createPlanner() {
Connection connection;
SchemaPlus rootSchema;
try {
connection = DriverManager.getConnection("jdbc:calcite:");
CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
rootSchema = calciteConnection.getRootSchema();
} catch (SQLException e) {
throw new SamzaException(e);
}
final List<RelTraitDef> traitDefs = new ArrayList<>();
traitDefs.add(ConventionTraitDef.INSTANCE);
traitDefs.add(RelCollationTraitDef.INSTANCE);
FrameworkConfig frameworkConfig = Frameworks.newConfigBuilder()
.parserConfig(SqlParser.configBuilder().setLex(Lex.JAVA).build())
.defaultSchema(rootSchema)
.operatorTable(SqlStdOperatorTable.instance())
.traitDefs(traitDefs)
.context(Contexts.EMPTY_CONTEXT)
.costFactory(null)
.build();
return Frameworks.getPlanner(frameworkConfig);
}
示例7: addProperty
import org.apache.calcite.sql.parser.SqlParser; //导入依赖的package包/类
private ImmutableMap.Builder<DatabaseProperty, Object> addProperty(
ImmutableMap.Builder<DatabaseProperty, Object> builder,
DatabaseProperty p) {
switch (p) {
case GET_S_Q_L_KEYWORDS:
return builder.put(p,
SqlParser.create("").getMetadata().getJdbcKeywords());
case GET_NUMERIC_FUNCTIONS:
return builder.put(p, SqlJdbcFunctionCall.getNumericFunctions());
case GET_STRING_FUNCTIONS:
return builder.put(p, SqlJdbcFunctionCall.getStringFunctions());
case GET_SYSTEM_FUNCTIONS:
return builder.put(p, SqlJdbcFunctionCall.getSystemFunctions());
case GET_TIME_DATE_FUNCTIONS:
return builder.put(p, SqlJdbcFunctionCall.getTimeDateFunctions());
default:
return builder;
}
}
示例8: 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);
}
}
示例9: 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;
}
示例10: buildPlanner
import org.apache.calcite.sql.parser.SqlParser; //导入依赖的package包/类
private Planner buildPlanner(QueryContext context) {
final List<RelTraitDef> traitDefs = new ArrayList<RelTraitDef>();
traitDefs.add(ConventionTraitDef.INSTANCE);
traitDefs.add(RelCollationTraitDef.INSTANCE);
final ChainedSqlOperatorTable opTab =
new ChainedSqlOperatorTable(
ImmutableList.of(SqlStdOperatorTable.instance(),
HiveSqlOperatorTable.instance(), catalogReader));
FrameworkConfig config = Frameworks.newConfigBuilder() //
.parserConfig(SqlParser.configBuilder()
.setQuotedCasing(Casing.UNCHANGED)
.setUnquotedCasing(Casing.TO_UPPER)
.setQuoting(Quoting.DOUBLE_QUOTE)
.build()) //
.defaultSchema(context.getDefaultSchema()) //
.operatorTable(opTab) //
.traitDefs(traitDefs) //
.convertletTable(StandardConvertletTable.INSTANCE)//
.programs(getPrograms()) //
.typeSystem(RelDataTypeSystem.DEFAULT) //
.build();
return Frameworks.getPlanner(config);
}
示例11: 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));
}
示例12: 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;
}
示例13: config
import org.apache.calcite.sql.parser.SqlParser; //导入依赖的package包/类
public Frameworks.ConfigBuilder config() throws Exception {
final Holder<SchemaPlus> root = Holder.of(null);
CalciteAssert.model(TPCDS_MODEL)
.doWithConnection(
new Function<CalciteConnection, Object>() {
public Object apply(CalciteConnection input) {
root.set(input.getRootSchema().getSubSchema("TPCDS"));
return null;
}
});
return Frameworks.newConfigBuilder()
.parserConfig(SqlParser.Config.DEFAULT)
.defaultSchema(root.get())
.traitDefs((List<RelTraitDef>) null)
.programs(Programs.heuristicJoinOrder(Programs.RULE_SET, true, 2));
}
示例14: addProperty
import org.apache.calcite.sql.parser.SqlParser; //导入依赖的package包/类
private ImmutableMap.Builder<DatabaseProperty, Object> addProperty(
ImmutableMap.Builder<DatabaseProperty, Object> builder,
DatabaseProperty p) {
switch (p) {
case GET_S_Q_L_KEYWORDS:
return builder.put(p,
SqlParser.create("").getMetadata().getJdbcKeywords());
case GET_NUMERIC_FUNCTIONS:
return builder.put(p, SqlJdbcFunctionCall.getNumericFunctions());
case GET_STRING_FUNCTIONS:
return builder.put(p, SqlJdbcFunctionCall.getStringFunctions());
case GET_SYSTEM_FUNCTIONS:
return builder.put(p, SqlJdbcFunctionCall.getSystemFunctions());
case GET_TIME_DATE_FUNCTIONS:
return builder.put(p, SqlJdbcFunctionCall.getTimeDateFunctions());
default:
return builder;
}
}
示例15: 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));
}