本文整理汇总了Java中org.apache.calcite.config.Lex类的典型用法代码示例。如果您正苦于以下问题:Java Lex类的具体用法?Java Lex怎么用?Java Lex使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Lex类属于org.apache.calcite.config包,在下文中一共展示了Lex类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: prepare
import org.apache.calcite.config.Lex; //导入依赖的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);
}
示例2: GremlinCompiler
import org.apache.calcite.config.Lex; //导入依赖的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();
}
示例3: createPlanner
import org.apache.calcite.config.Lex; //导入依赖的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);
}
示例4: runProjectQueryWithLex
import org.apache.calcite.config.Lex; //导入依赖的package包/类
private static void runProjectQueryWithLex(Lex lex, String sql)
throws SqlParseException, ValidationException, RelConversionException {
Config javaLex = SqlParser.configBuilder().setLex(lex).build();
Planner planner = getPlanner(null, javaLex, Programs.ofRules(Programs.RULE_SET));
SqlNode parse = planner.parse(sql);
SqlNode validate = planner.validate(parse);
RelNode convert = planner.rel(validate).rel;
RelTraitSet traitSet =
planner.getEmptyTraitSet().replace(EnumerableConvention.INSTANCE);
RelNode transform = planner.transform(0, traitSet, convert);
assertThat(transform, instanceOf(EnumerableProject.class));
List<String> fieldNames = transform.getRowType().getFieldNames();
assertThat(fieldNames.size(), is(2));
if (lex.caseSensitive) {
assertThat(fieldNames.get(0), is("EMPID"));
assertThat(fieldNames.get(1), is("empid"));
} else {
assertThat(fieldNames.get(0) + "-" + fieldNames.get(1),
anyOf(is("EMPID-empid0"), is("EMPID0-empid")));
}
}
示例5: runDuplicateSortCheck
import org.apache.calcite.config.Lex; //导入依赖的package包/类
private void runDuplicateSortCheck(String sql, String plan) throws Exception {
RuleSet ruleSet =
RuleSets.ofList(
SortRemoveRule.INSTANCE,
EnumerableRules.ENUMERABLE_PROJECT_RULE,
EnumerableRules.ENUMERABLE_WINDOW_RULE,
EnumerableRules.ENUMERABLE_SORT_RULE,
ProjectToWindowRule.PROJECT);
Planner planner = getPlanner(null,
SqlParser.configBuilder().setLex(Lex.JAVA).build(),
Programs.of(ruleSet));
SqlNode parse = planner.parse(sql);
SqlNode validate = planner.validate(parse);
RelNode convert = planner.rel(validate).rel;
RelTraitSet traitSet = planner.getEmptyTraitSet()
.replace(EnumerableConvention.INSTANCE);
if (traitSet.getTrait(RelCollationTraitDef.INSTANCE) == null) {
// SortRemoveRule can only work if collation trait is enabled.
return;
}
RelNode transform = planner.transform(0, traitSet, convert);
assertThat(toString(transform), equalTo(plan));
}
示例6: checkTpchQuery
import org.apache.calcite.config.Lex; //导入依赖的package包/类
public String checkTpchQuery(String tpchTestQuery) throws Exception {
final SchemaPlus schema =
Frameworks.createRootSchema(true).add("tpch",
new ReflectiveSchema(new TpchSchema()));
final FrameworkConfig config = Frameworks.newConfigBuilder()
.parserConfig(SqlParser.configBuilder().setLex(Lex.MYSQL).build())
.defaultSchema(schema)
.programs(Programs.ofRules(Programs.RULE_SET))
.build();
String plan;
try (Planner p = Frameworks.getPlanner(config)) {
SqlNode n = p.parse(tpchTestQuery);
n = p.validate(n);
RelNode r = p.rel(n).project();
plan = RelOptUtil.toString(r);
}
return plan;
}
示例7: testCorrelatedScalarSubQuery
import org.apache.calcite.config.Lex; //导入依赖的package包/类
/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-685">[CALCITE-685]
* Correlated scalar sub-query in SELECT clause throws</a>. */
@Ignore("[CALCITE-685]")
@Test public void testCorrelatedScalarSubQuery() throws SQLException {
final String sql = "select e.department_id, sum(e.employee_id),\n"
+ " ( select sum(e2.employee_id)\n"
+ " from employee e2\n"
+ " where e.department_id = e2.department_id\n"
+ " )\n"
+ "from employee e\n"
+ "group by e.department_id\n";
final String explain = "EnumerableJoin(condition=[true], joinType=[left])\n"
+ " EnumerableAggregate(group=[{7}], EXPR$1=[$SUM0($0)])\n"
+ " EnumerableTableScan(table=[[foodmart2, employee]])\n"
+ " EnumerableAggregate(group=[{}], EXPR$0=[SUM($0)])\n"
+ " EnumerableCalc(expr#0..16=[{inputs}], expr#17=[$cor0], expr#18=[$t17.department_id], expr#19=[=($t18, $t7)], employee_id=[$t0], department_id=[$t7], $condition=[$t19])\n"
+ " EnumerableTableScan(table=[[foodmart2, employee]])\n";
CalciteAssert.that()
.with(CalciteAssert.Config.FOODMART_CLONE)
.with(Lex.JAVA)
.query(sql)
.explainContains(explain)
.returnsCount(0);
}
示例8: testLexCaseInsensitive
import org.apache.calcite.config.Lex; //导入依赖的package包/类
/** Tests case-insensitive resolution of schema and table names. */
@Test public void testLexCaseInsensitive() {
final CalciteAssert.AssertThat with =
CalciteAssert.that().with(Lex.MYSQL);
with.query("select COUNT(*) as c from metaData.tAbles")
.returns("c=2\n");
with.query("select COUNT(*) as c from `metaData`.`tAbles`")
.returns("c=2\n");
// case-sensitive gives error
final CalciteAssert.AssertThat with2 =
CalciteAssert.that().with(Lex.JAVA);
with2.query("select COUNT(*) as c from `metaData`.`tAbles`")
.throws_("Object 'metaData' not found; did you mean 'metadata'?");
with2.query("select COUNT(*) as c from `metaData`.`TABLES`")
.throws_("Object 'metaData' not found; did you mean 'metadata'?");
with2.query("select COUNT(*) as c from `metaData`.`tables`")
.throws_("Object 'metaData' not found; did you mean 'metadata'?");
with2.query("select COUNT(*) as c from `metaData`.`nonExistent`")
.throws_("Object 'metaData' not found; did you mean 'metadata'?");
with2.query("select COUNT(*) as c from `metadata`.`tAbles`")
.throws_("Object 'tAbles' not found within 'metadata'; did you mean 'TABLES'?");
}
示例9: testUnquotedCaseSensitiveSubQueryMySql
import org.apache.calcite.config.Lex; //导入依赖的package包/类
@Test public void testUnquotedCaseSensitiveSubQueryMySql() {
final CalciteAssert.AssertThat with =
CalciteAssert.that()
.with(Lex.MYSQL);
with.query("select DID from (select deptid as did FROM\n"
+ " ( values (1), (2) ) as T1(deptid) ) ")
.returnsUnordered("DID=1", "DID=2");
with.query("select x.DID from (select deptid as did FROM\n"
+ " ( values (1), (2) ) as T1(deptid) ) X ")
.returnsUnordered("DID=1", "DID=2");
with.query("select X.DID from (select deptid as did FROM\n"
+ " ( values (1), (2) ) as T1(deptid) ) X ")
.returnsUnordered("DID=1", "DID=2");
with.query("select X.DID2 from (select deptid as did FROM\n"
+ " ( values (1), (2) ) as T1(deptid) ) X (DID2)")
.returnsUnordered("DID2=1", "DID2=2");
with.query("select X.DID2 from (select deptid as did FROM\n"
+ " ( values (1), (2) ) as T1(deptid) ) X (DID2)")
.returnsUnordered("DID2=1", "DID2=2");
}
示例10: testQuotedCaseSensitiveSubQueryMySql
import org.apache.calcite.config.Lex; //导入依赖的package包/类
@Test public void testQuotedCaseSensitiveSubQueryMySql() {
final CalciteAssert.AssertThat with =
CalciteAssert.that()
.with(Lex.MYSQL);
with.query("select `DID` from (select deptid as did FROM\n"
+ " ( values (1), (2) ) as T1(deptid) ) ")
.returnsUnordered("DID=1", "DID=2");
with.query("select `x`.`DID` from (select deptid as did FROM\n"
+ " ( values (1), (2) ) as T1(deptid) ) X ")
.returnsUnordered("DID=1", "DID=2");
with.query("select `X`.`DID` from (select deptid as did FROM\n"
+ " ( values (1), (2) ) as T1(deptid) ) X ")
.returnsUnordered("DID=1", "DID=2");
with.query("select `X`.`DID2` from (select deptid as did FROM\n"
+ " ( values (1), (2) ) as T1(deptid) ) X (DID2)")
.returnsUnordered("DID2=1", "DID2=2");
with.query("select `X`.`DID2` from (select deptid as did FROM\n"
+ " ( values (1), (2) ) as T1(deptid) ) X (DID2)")
.returnsUnordered("DID2=1", "DID2=2");
}
示例11: testAvgInt
import org.apache.calcite.config.Lex; //导入依赖的package包/类
/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-580">[CALCITE-580]
* Average aggregation on an Integer column throws ClassCastException</a>. */
@Test public void testAvgInt() throws Exception {
CalciteAssert.that().withSchema("s", CATCHALL).with(Lex.JAVA)
.query("select primitiveLong, avg(primitiveInt)\n"
+ "from s.everyTypes\n"
+ "group by primitiveLong order by primitiveLong")
.returns(
new Function<ResultSet, Void>() {
public Void apply(ResultSet input) {
StringBuilder buf = new StringBuilder();
try {
while (input.next()) {
buf.append(input.getInt(2)).append("\n");
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
assertThat(buf.toString(), equalTo("0\n2147483647\n"));
return null;
}
});
}
示例12: parse
import org.apache.calcite.config.Lex; //导入依赖的package包/类
@VisibleForTesting
static SqlNodeList parse(String sql) throws ParseException {
// Keep the SQL syntax consistent with Flink
try (StringReader in = new StringReader(sql)) {
SqlParserImpl impl = new SqlParserImpl(in);
// back tick as the quote
impl.switchTo("BTID");
impl.setTabSize(1);
impl.setQuotedCasing(Lex.JAVA.quotedCasing);
impl.setUnquotedCasing(Lex.JAVA.unquotedCasing);
impl.setIdentifierMaxLength(DEFAULT_IDENTIFIER_MAX_LENGTH);
return impl.SqlStmtsEof();
}
}
示例13: DrillSqlWorker
import org.apache.calcite.config.Lex; //导入依赖的package包/类
public DrillSqlWorker(QueryContext context) {
final List<RelTraitDef> traitDefs = new ArrayList<RelTraitDef>();
traitDefs.add(ConventionTraitDef.INSTANCE);
traitDefs.add(DrillDistributionTraitDef.INSTANCE);
traitDefs.add(RelCollationTraitDef.INSTANCE);
this.context = context;
RelOptCostFactory costFactory = (context.getPlannerSettings().useDefaultCosting()) ?
null : new DrillCostBase.DrillCostFactory() ;
int idMaxLength = (int)context.getPlannerSettings().getIdentifierMaxLength();
FrameworkConfig config = Frameworks.newConfigBuilder() //
.parserConfig(SqlParser.configBuilder()
.setLex(Lex.MYSQL)
.setIdentifierMaxLength(idMaxLength)
.setParserFactory(DrillParserWithCompoundIdConverter.FACTORY)
.build()) //
.defaultSchema(context.getNewDefaultSchema()) //
.operatorTable(context.getDrillOperatorTable()) //
.traitDefs(traitDefs) //
.convertletTable(new DrillConvertletTable()) //
.context(context.getPlannerSettings()) //
.ruleSets(getRules(context)) //
.costFactory(costFactory) //
.executor(new DrillConstExecutor(context.getFunctionRegistry(), context, context.getPlannerSettings()))
.typeSystem(DrillRelDataTypeSystem.DRILL_REL_DATATYPE_SYSTEM) //
.build();
this.planner = Frameworks.getPlanner(config);
HepProgramBuilder builder = new HepProgramBuilder();
builder.addRuleClass(ReduceExpressionsRule.class);
builder.addRuleClass(ProjectToWindowRule.class);
this.hepPlanner = new HepPlanner(builder.build());
hepPlanner.addRule(ReduceExpressionsRule.CALC_INSTANCE);
hepPlanner.addRule(ProjectToWindowRule.PROJECT);
}
示例14: checkComplexExpressionParsing
import org.apache.calcite.config.Lex; //导入依赖的package包/类
@Test
public void checkComplexExpressionParsing() throws Exception{
FrameworkConfig config = Frameworks.newConfigBuilder() //
.parserConfig(SqlParser.configBuilder()
.setLex(Lex.MYSQL)
.setIdentifierMaxLength(PlannerSettings.DEFAULT_IDENTIFIER_MAX_LENGTH)
.setParserFactory(DrillParserImpl.FACTORY)
.build()) //
.defaultSchema(SimpleCalciteSchema.createRootSchema(false)) //
.convertletTable(new DrillConvertletTable()) //
.build();
Planner planner = Frameworks.getPlanner(config);
SqlNode node = planner.parse(""
+ "select a[4].c \n"
+ "from x.y.z \n"
+ "where a.c.b = 5 and x[2] = 7 \n"
+ "group by d \n"
+ "having a.c < 5 \n"
+ "order by x.a.a.a.a.a");
String expected = "SELECT `a`[4]['c']\n" +
"FROM `x`.`y`.`z`\n" +
"WHERE `a`.`c`['b'] = 5 AND `x`[2] = 7\n" +
"GROUP BY `d`\n" +
"HAVING `a`.`c` < 5\n" +
"ORDER BY `x`.`a`['a']['a']['a']['a']";
SqlNode rewritten = node.accept(new CompoundIdentifierConverter());
String rewrittenQuery = rewritten.toString();
DrillAssert.assertMultiLineStringEquals(expected, rewrittenQuery);
}
示例15: checkComplexExpressionParsing
import org.apache.calcite.config.Lex; //导入依赖的package包/类
@Test
public void checkComplexExpressionParsing() throws Exception{
FrameworkConfig config = Frameworks.newConfigBuilder()
.parserConfig(SqlParser.configBuilder()
.setLex(Lex.MYSQL)
.setIdentifierMaxLength(PlannerSettings.DEFAULT_IDENTIFIER_MAX_LENGTH)
.setParserFactory(ParserImpl.FACTORY)
.build())
.defaultSchema(CalciteSchema.createRootSchema(false /* addMetadata */, false /* cache */).plus())
.convertletTable(ConvertletTable.INSTANCE)
.build();
Planner planner = Frameworks.getPlanner(config);
SqlNode node = planner.parse(""
+ "select a[4].c \n"
+ "from x.y.z \n"
+ "where a.c.b = 5 and x[2] = 7 \n"
+ "group by d \n"
+ "having a.c < 5 \n"
+ "order by x.a.a.a.a.a");
String expected = "SELECT `a`[4]['c']\n" +
"FROM `x`.`y`.`z`\n" +
"WHERE `a`.`c`['b'] = 5 AND `x`[2] = 7\n" +
"GROUP BY `d`\n" +
"HAVING `a`.`c` < 5\n" +
"ORDER BY `x`.`a`['a']['a']['a']['a']";
SqlNode rewritten = node.accept(new CompoundIdentifierConverter());
String rewrittenQuery = rewritten.toString();
DremioAssert.assertMultiLineStringEquals(expected, rewrittenQuery);
}