Java Code Examples for org.apache.calcite.tools.RelBuilder#getTypeFactory()

The following examples show how to use org.apache.calcite.tools.RelBuilder#getTypeFactory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RelBuilderTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Test void testFilterCastNull() {
  final RelBuilder builder = RelBuilder.create(config().build());
  final RelDataTypeFactory typeFactory = builder.getTypeFactory();
  final RelNode root =
      builder.scan("EMP")
          .filter(
              builder.getRexBuilder().makeCast(
                  typeFactory.createTypeWithNullability(
                      typeFactory.createSqlType(SqlTypeName.BOOLEAN), true),
                  builder.equals(builder.field("DEPTNO"),
                      builder.literal(10))))
          .build();
  final String expected = ""
      + "LogicalFilter(condition=[=($7, 10)])\n"
      + "  LogicalTableScan(table=[[scott, EMP]])\n";
  assertThat(root, hasTree(expected));
}
 
Example 2
Source File: QueryOperationConverter.java    From flink with Apache License 2.0 5 votes vote down vote up
public AggCallVisitor(RelBuilder relBuilder, RexNodeConverter rexNodeConverter, String name,
		boolean isDistinct) {
	this.relBuilder = relBuilder;
	this.sqlAggFunctionVisitor = new SqlAggFunctionVisitor((FlinkTypeFactory) relBuilder.getTypeFactory());
	this.rexNodeConverter = rexNodeConverter;
	this.name = name;
	this.isDistinct = isDistinct;
}
 
Example 3
Source File: QueryOperationConverter.java    From flink with Apache License 2.0 5 votes vote down vote up
public AggCallVisitor(RelBuilder relBuilder, ExpressionConverter expressionConverter, String name,
		boolean isDistinct) {
	this.relBuilder = relBuilder;
	this.sqlAggFunctionVisitor = new SqlAggFunctionVisitor((FlinkTypeFactory) relBuilder.getTypeFactory());
	this.expressionConverter = expressionConverter;
	this.name = name;
	this.isDistinct = isDistinct;
}
 
Example 4
Source File: QueryOperationConverter.java    From flink with Apache License 2.0 4 votes vote down vote up
public TableAggCallVisitor(RelBuilder relBuilder, RexNodeConverter rexNodeConverter) {
	this.relBuilder = relBuilder;
	this.sqlAggFunctionVisitor = new SqlAggFunctionVisitor((FlinkTypeFactory) relBuilder.getTypeFactory());
	this.rexNodeConverter = rexNodeConverter;
}
 
Example 5
Source File: QueryOperationConverter.java    From flink with Apache License 2.0 4 votes vote down vote up
public TableAggCallVisitor(RelBuilder relBuilder, ExpressionConverter expressionConverter) {
	this.relBuilder = relBuilder;
	this.sqlAggFunctionVisitor = new SqlAggFunctionVisitor((FlinkTypeFactory) relBuilder.getTypeFactory());
	this.expressionConverter = expressionConverter;
}
 
Example 6
Source File: RelBuilderTest.java    From calcite with Apache License 2.0 4 votes vote down vote up
@Test void testMatchRecognize() {
  // Equivalent SQL:
  //   SELECT *
  //   FROM emp
  //   MATCH_RECOGNIZE (
  //     PARTITION BY deptno
  //     ORDER BY empno asc
  //     MEASURES
  //       STRT.mgr as start_nw,
  //       LAST(DOWN.mgr) as bottom_nw,
  //     PATTERN (STRT DOWN+ UP+) WITHIN INTERVAL '5' SECOND
  //     DEFINE
  //       DOWN as DOWN.mgr < PREV(DOWN.mgr),
  //       UP as UP.mgr > PREV(UP.mgr)
  //   )
  final RelBuilder builder = RelBuilder.create(config().build()).scan("EMP");
  final RelDataTypeFactory typeFactory = builder.getTypeFactory();
  final RelDataType intType = typeFactory.createSqlType(SqlTypeName.INTEGER);

  RexNode pattern = builder.patternConcat(
      builder.literal("STRT"),
      builder.patternQuantify(builder.literal("DOWN"), builder.literal(1),
          builder.literal(-1), builder.literal(false)),
      builder.patternQuantify(builder.literal("UP"), builder.literal(1),
          builder.literal(-1), builder.literal(false)));

  ImmutableMap.Builder<String, RexNode> pdBuilder = new ImmutableMap.Builder<>();
  RexNode downDefinition = builder.call(SqlStdOperatorTable.LESS_THAN,
      builder.call(SqlStdOperatorTable.PREV,
          builder.patternField("DOWN", intType, 3),
          builder.literal(0)),
      builder.call(SqlStdOperatorTable.PREV,
          builder.patternField("DOWN", intType, 3),
          builder.literal(1)));
  pdBuilder.put("DOWN", downDefinition);
  RexNode upDefinition = builder.call(SqlStdOperatorTable.GREATER_THAN,
      builder.call(SqlStdOperatorTable.PREV,
          builder.patternField("UP", intType, 3),
          builder.literal(0)),
      builder.call(SqlStdOperatorTable.PREV,
          builder.patternField("UP", intType, 3),
          builder.literal(1)));
  pdBuilder.put("UP", upDefinition);

  ImmutableList.Builder<RexNode> measuresBuilder = new ImmutableList.Builder<>();
  measuresBuilder.add(
      builder.alias(builder.patternField("STRT", intType, 3),
          "start_nw"));
  measuresBuilder.add(
      builder.alias(
          builder.call(SqlStdOperatorTable.LAST,
              builder.patternField("DOWN", intType, 3),
              builder.literal(0)),
          "bottom_nw"));

  RexNode after = builder.getRexBuilder().makeFlag(
      SqlMatchRecognize.AfterOption.SKIP_TO_NEXT_ROW);

  ImmutableList.Builder<RexNode> partitionKeysBuilder = new ImmutableList.Builder<>();
  partitionKeysBuilder.add(builder.field("DEPTNO"));

  ImmutableList.Builder<RexNode> orderKeysBuilder = new ImmutableList.Builder<>();
  orderKeysBuilder.add(builder.field("EMPNO"));

  RexNode interval = builder.literal("INTERVAL '5' SECOND");

  final ImmutableMap<String, TreeSet<String>> subsets = ImmutableMap.of();
  final RelNode root = builder
      .match(pattern, false, false, pdBuilder.build(),
          measuresBuilder.build(), after, subsets, false,
          partitionKeysBuilder.build(), orderKeysBuilder.build(), interval)
      .build();
  final String expected = "LogicalMatch(partition=[[7]], order=[[0]], "
      + "outputFields=[[$7, 'start_nw', 'bottom_nw']], allRows=[false], "
      + "after=[FLAG(SKIP TO NEXT ROW)], pattern=[(('STRT', "
      + "PATTERN_QUANTIFIER('DOWN', 1, -1, false)), "
      + "PATTERN_QUANTIFIER('UP', 1, -1, false))], "
      + "isStrictStarts=[false], isStrictEnds=[false], "
      + "interval=['INTERVAL ''5'' SECOND'], subsets=[[]], "
      + "patternDefinitions=[[<(PREV(DOWN.$3, 0), PREV(DOWN.$3, 1)), "
      + ">(PREV(UP.$3, 0), PREV(UP.$3, 1))]], "
      + "inputFields=[[EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO]])\n"
      + "  LogicalTableScan(table=[[scott, EMP]])\n";
  assertThat(root, hasTree(expected));
}