本文整理汇总了Java中org.apache.calcite.tools.RelBuilder.create方法的典型用法代码示例。如果您正苦于以下问题:Java RelBuilder.create方法的具体用法?Java RelBuilder.create怎么用?Java RelBuilder.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.calcite.tools.RelBuilder
的用法示例。
在下文中一共展示了RelBuilder.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: prepare
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的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: testIntersect
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
@Test public void testIntersect() {
// Equivalent SQL:
// SELECT empno FROM emp
// WHERE deptno = 20
// INTERSECT
// SELECT deptno FROM dept
final RelBuilder builder = RelBuilder.create(config().build());
RelNode root =
builder.scan("DEPT")
.project(builder.field("DEPTNO"))
.scan("EMP")
.filter(
builder.call(SqlStdOperatorTable.EQUALS,
builder.field("DEPTNO"),
builder.literal(20)))
.project(builder.field("EMPNO"))
.intersect(false)
.build();
assertThat(str(root),
is("LogicalIntersect(all=[false])\n"
+ " LogicalProject(DEPTNO=[$0])\n"
+ " LogicalTableScan(table=[[scott, DEPT]])\n"
+ " LogicalProject(EMPNO=[$0])\n"
+ " LogicalFilter(condition=[=($7, 20)])\n"
+ " LogicalTableScan(table=[[scott, EMP]])\n"));
}
示例3: testJoin
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
@Test public void testJoin() {
// Equivalent SQL:
// SELECT *
// FROM (SELECT * FROM emp WHERE comm IS NULL)
// JOIN dept ON emp.deptno = dept.deptno
final RelBuilder builder = RelBuilder.create(config().build());
RelNode root =
builder.scan("EMP")
.filter(
builder.call(SqlStdOperatorTable.IS_NULL,
builder.field("COMM")))
.scan("DEPT")
.join(JoinRelType.INNER,
builder.call(SqlStdOperatorTable.EQUALS,
builder.field(2, 0, "DEPTNO"),
builder.field(2, 1, "DEPTNO")))
.build();
final String expected = ""
+ "LogicalJoin(condition=[=($7, $8)], joinType=[inner])\n"
+ " LogicalFilter(condition=[IS NULL($6)])\n"
+ " LogicalTableScan(table=[[scott, EMP]])\n"
+ " LogicalTableScan(table=[[scott, DEPT]])\n";
assertThat(str(root), is(expected));
}
示例4: testDistinct
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
@Test public void testDistinct() {
// Equivalent SQL:
// SELECT DISTINCT deptno
// FROM emp
final RelBuilder builder = RelBuilder.create(config().build());
RelNode root =
builder.scan("EMP")
.project(builder.field("DEPTNO"))
.distinct()
.build();
final String expected = "LogicalAggregate(group=[{0}])\n"
+ " LogicalProject(DEPTNO=[$7])\n"
+ " LogicalTableScan(table=[[scott, EMP]])\n";
assertThat(str(root),
is(expected));
}
示例5: testRun
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
/** Tests {@link org.apache.calcite.tools.RelRunner} for a table scan + filter
* query. */
@Test public void testRun() throws Exception {
// Equivalent SQL:
// SELECT * FROM EMP WHERE DEPTNO = 20
final RelBuilder builder = RelBuilder.create(config().build());
RelNode root =
builder.scan("EMP")
.filter(
builder.equals(builder.field("DEPTNO"), builder.literal(20)))
.build();
// Note that because the table has been resolved in the RelNode tree
// we do not need to supply a "schema" as context to the runner.
try (final PreparedStatement preparedStatement = RelRunners.run(root)) {
String s = CalciteAssert.toString(preparedStatement.executeQuery());
final String result = ""
+ "EMPNO=7369; ENAME=SMITH; JOB=CLERK; MGR=7902; HIREDATE=1980-12-17; SAL=800.00; COMM=null; DEPTNO=20\n"
+ "EMPNO=7566; ENAME=JONES; JOB=MANAGER; MGR=7839; HIREDATE=1981-02-04; SAL=2975.00; COMM=null; DEPTNO=20\n"
+ "EMPNO=7788; ENAME=SCOTT; JOB=ANALYST; MGR=7566; HIREDATE=1987-04-19; SAL=3000.00; COMM=null; DEPTNO=20\n"
+ "EMPNO=7876; ENAME=ADAMS; JOB=CLERK; MGR=7788; HIREDATE=1987-05-23; SAL=1100.00; COMM=null; DEPTNO=20\n"
+ "EMPNO=7902; ENAME=FORD; JOB=ANALYST; MGR=7566; HIREDATE=1981-12-03; SAL=3000.00; COMM=null; DEPTNO=20\n";
assertThat(s, is(result));
}
}
示例6: testFilterCastAny
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
@Test public void testFilterCastAny() {
final RelBuilder builder = RelBuilder.create(config().build());
final RelDataType anyType =
builder.getTypeFactory().createSqlType(SqlTypeName.ANY);
final RelNode root =
builder.scan("EMP")
.filter(
builder.cast(
builder.getRexBuilder().makeInputRef(anyType, 0),
SqlTypeName.BOOLEAN))
.build();
final String expected = ""
+ "LogicalFilter(condition=[CAST($0):BOOLEAN NOT NULL])\n"
+ " LogicalTableScan(table=[[scott, EMP]])\n";
assertThat(str(root), is(expected));
}
示例7: testScanFilterAndFalse
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
@Test public void testScanFilterAndFalse() {
// Equivalent SQL:
// SELECT *
// FROM emp
// WHERE deptno = 20 AND FALSE
// simplifies to
// VALUES
final RelBuilder builder = RelBuilder.create(config().build());
RelNode root =
builder.scan("EMP")
.filter(
builder.call(SqlStdOperatorTable.GREATER_THAN,
builder.field("DEPTNO"),
builder.literal(20)),
builder.literal(false))
.build();
final String plan = "LogicalValues(tuples=[[]])\n";
assertThat(str(root), is(plan));
}
示例8: testRenameValues
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
@Test public void testRenameValues() {
final RelBuilder builder = RelBuilder.create(config().build());
RelNode root =
builder.values(new String[]{"a", "b"}, true, 1, false, -50)
.build();
final String expected =
"LogicalValues(tuples=[[{ true, 1 }, { false, -50 }]])\n";
assertThat(str(root), is(expected));
// When you rename Values, you get a Values with a new row type, no Project
root =
builder.push(root)
.rename(ImmutableList.of("x", "y z"))
.build();
assertThat(str(root), is(expected));
assertThat(root.getRowType().getFieldNames().toString(), is("[x, y z]"));
}
示例9: testBadUnionArgsErrorMessage
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-1522">[CALCITE-1522]
* Fix error message for SetOp with incompatible args</a>. */
@Test public void testBadUnionArgsErrorMessage() {
// Equivalent SQL:
// SELECT EMPNO, SAL FROM emp
// UNION ALL
// SELECT DEPTNO FROM dept
final RelBuilder builder = RelBuilder.create(config().build());
try {
final RelNode root =
builder.scan("DEPT")
.project(builder.field("DEPTNO"))
.scan("EMP")
.project(builder.field("EMPNO"), builder.field("SAL"))
.union(true)
.build();
fail("Expected error, got " + root);
} catch (IllegalArgumentException e) {
final String expected = "Cannot compute compatible row type for "
+ "arguments to set op: RecordType(TINYINT DEPTNO), "
+ "RecordType(SMALLINT EMPNO, DECIMAL(7, 2) SAL)";
assertThat(e.getMessage(), is(expected));
}
}
示例10: testDistinctEmpty
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
@Test public void testDistinctEmpty() {
// Is a relation with zero columns distinct?
// What about if we know there are zero rows?
// It is a matter of definition: there are no duplicate rows,
// but applying "select ... group by ()" to it would change the result.
// In theory, we could omit the distinct if we know there is precisely one
// row, but we don't currently.
final RelBuilder builder = RelBuilder.create(config().build());
RelNode root =
builder.scan("EMP")
.filter(
builder.call(SqlStdOperatorTable.IS_NULL,
builder.field("COMM")))
.project()
.distinct()
.build();
final String expected = "LogicalAggregate(group=[{}])\n"
+ " LogicalProject\n"
+ " LogicalFilter(condition=[IS NULL($6)])\n"
+ " LogicalTableScan(table=[[scott, EMP]])\n";
assertThat(str(root), is(expected));
}
示例11: testCorrelationFails
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
@Test public void testCorrelationFails() {
final RelBuilder builder = RelBuilder.create(config().build());
final Holder<RexCorrelVariable> v = Holder.of(null);
try {
builder.scan("EMP")
.variable(v)
.filter(builder.equals(builder.field(0), v.get()))
.scan("DEPT")
.join(JoinRelType.INNER, builder.literal(true),
ImmutableSet.of(v.get().id));
fail("expected error");
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(),
containsString("variable $cor0 must not be used by left input to correlation"));
}
}
示例12: testAliasPastTop
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-1523">[CALCITE-1523]
* Add RelBuilder field() method to reference aliased relations not on top of
* stack</a>, accessing tables aliased that are not accessible in the top
* RelNode. */
@Test public void testAliasPastTop() {
// Equivalent SQL:
// SELECT *
// FROM emp
// LEFT JOIN dept ON emp.deptno = dept.deptno
// AND emp.empno = 123
// AND dept.deptno IS NOT NULL
final RelBuilder builder = RelBuilder.create(config().build());
RelNode root =
builder.scan("EMP")
.scan("DEPT")
.join(JoinRelType.LEFT,
builder.call(SqlStdOperatorTable.EQUALS,
builder.field(2, "EMP", "DEPTNO"),
builder.field(2, "DEPT", "DEPTNO")),
builder.call(SqlStdOperatorTable.EQUALS,
builder.field(2, "EMP", "EMPNO"),
builder.literal(123)))
.build();
final String expected = ""
+ "LogicalJoin(condition=[AND(=($7, $8), =($0, 123))], joinType=[left])\n"
+ " LogicalTableScan(table=[[scott, EMP]])\n"
+ " LogicalTableScan(table=[[scott, DEPT]])\n";
assertThat(str(root), is(expected));
}
示例13: getBuilder
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
/**
* Creates a {@link RelBuilder} with the given schema.
*
* @param dataSource The dataSource for the jdbc schema.
* @param schemaName The name of the schema used for the database.
*
* @return the relbuilder from Calcite.
*
* @throws SQLException if can't readSqlResultSet from database.
*/
public static RelBuilder getBuilder(DataSource dataSource, String schemaName) throws SQLException {
SchemaPlus rootSchema = Frameworks.createRootSchema(true);
return RelBuilder.create(
Frameworks.newConfigBuilder()
.parserConfig(SqlParser.Config.DEFAULT)
.defaultSchema(addSchema(rootSchema, dataSource, schemaName))
.traitDefs((List<RelTraitDef>) null)
.programs(Programs.heuristicJoinOrder(Programs.RULE_SET, true, 2))
.build()
);
}
示例14: testAliasPastTop2
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
/** As {@link #testAliasPastTop()}. */
@Test public void testAliasPastTop2() {
// Equivalent SQL:
// SELECT t1.EMPNO, t2.EMPNO, t3.DEPTNO
// FROM emp t1
// INNER JOIN emp t2 ON t1.EMPNO = t2.EMPNO
// INNER JOIN dept t3 ON t1.DEPTNO = t3.DEPTNO
// AND t2.JOB != t3.LOC
final RelBuilder builder = RelBuilder.create(config().build());
RelNode root =
builder.scan("EMP").as("t1")
.scan("EMP").as("t2")
.join(JoinRelType.INNER,
builder.equals(builder.field(2, "t1", "EMPNO"),
builder.field(2, "t2", "EMPNO")))
.scan("DEPT").as("t3")
.join(JoinRelType.INNER,
builder.equals(builder.field(2, "t1", "DEPTNO"),
builder.field(2, "t3", "DEPTNO")),
builder.not(
builder.equals(builder.field(2, "t2", "JOB"),
builder.field(2, "t3", "LOC"))))
.build();
// Cols:
// 0-7 EMP as t1
// 8-15 EMP as t2
// 16-18 DEPT as t3
final String expected = ""
+ "LogicalJoin(condition=[AND(=($7, $16), <>($10, $18))], joinType=[inner])\n"
+ " LogicalJoin(condition=[=($0, $8)], joinType=[inner])\n"
+ " LogicalTableScan(table=[[scott, EMP]])\n"
+ " LogicalTableScan(table=[[scott, EMP]])\n"
+ " LogicalTableScan(table=[[scott, DEPT]])\n";
assertThat(str(root), is(expected));
}
示例15: testAggregateGroupingWithFilterFails
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
@Test public void testAggregateGroupingWithFilterFails() {
final RelBuilder builder = RelBuilder.create(config().build());
try {
RelNode root =
builder.scan("EMP")
.aggregate(builder.groupKey(6, 7),
builder.aggregateCall(SqlStdOperatorTable.GROUPING, false,
false, builder.literal(true), "g",
builder.field("DEPTNO")))
.build();
fail("expected error, got " + root);
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), is("FILTER not allowed"));
}
}