org.apache.calcite.rel.RelCollationTraitDef Java Examples

The following examples show how to use org.apache.calcite.rel.RelCollationTraitDef. 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: SqlHintsConverterTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Test void testUseMergeJoin() {
  final String sql = "select /*+ use_merge_join(emp, dept) */\n"
      + "ename, job, sal, dept.name\n"
      + "from emp join dept on emp.deptno = dept.deptno";
  RelOptPlanner planner = new VolcanoPlanner();
  planner.addRelTraitDef(ConventionTraitDef.INSTANCE);
  planner.addRelTraitDef(RelCollationTraitDef.INSTANCE);
  Tester tester1 = tester.withDecorrelation(true)
      .withClusterFactory(
          relOptCluster -> RelOptCluster.create(planner, relOptCluster.getRexBuilder()));
  final RelNode rel = tester1.convertSqlToRel(sql).rel;
  RuleSet ruleSet = RuleSets.ofList(
      EnumerableRules.ENUMERABLE_MERGE_JOIN_RULE,
      EnumerableRules.ENUMERABLE_JOIN_RULE,
      EnumerableRules.ENUMERABLE_PROJECT_RULE,
      EnumerableRules.ENUMERABLE_TABLE_SCAN_RULE,
      EnumerableRules.ENUMERABLE_SORT_RULE,
      AbstractConverter.ExpandConversionRule.INSTANCE);
  Program program = Programs.of(ruleSet);
  RelTraitSet toTraits = rel
      .getCluster()
      .traitSet()
      .replace(EnumerableConvention.INSTANCE);

  RelNode relAfter = program.run(planner, rel, toTraits,
      Collections.emptyList(), Collections.emptyList());

  String planAfter = NL + RelOptUtil.toString(relAfter);
  getDiffRepos().assertEquals("planAfter", "${planAfter}", planAfter);
}
 
Example #2
Source File: EnumerableCorrelate.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Creates an EnumerableCorrelate. */
public static EnumerableCorrelate create(
    RelNode left,
    RelNode right,
    CorrelationId correlationId,
    ImmutableBitSet requiredColumns,
    JoinRelType joinType) {
  final RelOptCluster cluster = left.getCluster();
  final RelMetadataQuery mq = cluster.getMetadataQuery();
  final RelTraitSet traitSet =
      cluster.traitSetOf(EnumerableConvention.INSTANCE)
          .replaceIfs(RelCollationTraitDef.INSTANCE,
              () -> RelMdCollation.enumerableCorrelate(mq, left, right, joinType));
  return new EnumerableCorrelate(
      cluster,
      traitSet,
      left,
      right,
      correlationId,
      requiredColumns,
      joinType);
}
 
Example #3
Source File: OLAPProjectRule.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public RelNode convert(final RelNode rel) {

    //  KYLIN-3281
    //  OLAPProjectRule can't normal working with projectRel[input=sortRel]
    final LogicalProject project = (LogicalProject) rel;
    final RelNode convertChild = convert(project.getInput(),
            project.getInput().getTraitSet().replace(OLAPRel.CONVENTION));
    final RelOptCluster cluster = convertChild.getCluster();
    final RelTraitSet traitSet = cluster.traitSet().replace(OLAPRel.CONVENTION)
            .replaceIfs(RelCollationTraitDef.INSTANCE, new Supplier<List<RelCollation>>() {
                public List<RelCollation> get() {
                    //  CALCITE-88
                    return RelMdCollation.project(cluster.getMetadataQuery(), convertChild, project.getProjects());
                }
            });
    return new OLAPProjectRel(convertChild.getCluster(), traitSet, convertChild, project.getProjects(),
            project.getRowType());
}
 
Example #4
Source File: OLAPValuesRel.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
/** Creates an OLAPValuesRel. */
public static OLAPValuesRel create(RelOptCluster cluster, final RelDataType rowType,
        final ImmutableList<ImmutableList<RexLiteral>> tuples) {
    final RelMetadataQuery mq = cluster.getMetadataQuery();
    final RelTraitSet traitSet = cluster.traitSetOf(OLAPRel.CONVENTION)
            .replaceIfs(RelCollationTraitDef.INSTANCE, new Supplier<List<RelCollation>>() {
                public List<RelCollation> get() {
                    return RelMdCollation.values(mq, rowType, tuples);
                }
            }).replaceIf(RelDistributionTraitDef.INSTANCE, new Supplier<RelDistribution>() {
                public RelDistribution get() {
                    return RelMdDistribution.values(rowType, tuples);
                }
            });
    return new OLAPValuesRel(cluster, rowType, tuples, traitSet);
}
 
Example #5
Source File: GremlinCompiler.java    From sql-gremlin with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #6
Source File: DirPrunedEnumerableTableScan.java    From Bats with Apache License 2.0 6 votes vote down vote up
/** Creates an DirPrunedEnumerableTableScan. */
public static EnumerableTableScan create(RelOptCluster cluster,
    RelOptTable relOptTable, String digestFromSelection) {
  final Table table = relOptTable.unwrap(Table.class);
  Class elementType = EnumerableTableScan.deduceElementType(table);
  final RelTraitSet traitSet =
      cluster.traitSetOf(EnumerableConvention.INSTANCE)
          .replaceIfs(RelCollationTraitDef.INSTANCE,
              () -> {
                if (table != null) {
                  return table.getStatistic().getCollations();
                }
                return ImmutableList.of();
              });
  return new DirPrunedEnumerableTableScan(cluster, traitSet, relOptTable, elementType, digestFromSelection);
}
 
Example #7
Source File: DremioRelFactories.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@Override
public RelNode createSort(RelTraitSet traits, RelNode input, RelCollation collation, RexNode offset, RexNode fetch) {
  RelNode newInput;
  if (!collation.getFieldCollations().isEmpty()) {
    collation = RelCollationTraitDef.INSTANCE.canonize(collation);
    newInput = SortRel.create(input.getCluster(), traits, input, collation, null, null);
    traits = newInput.getTraitSet();
  } else {
    newInput = input;
  }

  if (!isOffsetEmpty(offset) || !isFetchEmpty(fetch)) {
    return LimitRel.create(newInput.getCluster(), traits, newInput, offset, fetch);
  }
  return newInput;
}
 
Example #8
Source File: StreamAggPrel.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public static StreamAggPrel create(RelOptCluster cluster,
                     RelTraitSet traits,
                     RelNode child,
                     boolean indicator,
                     ImmutableBitSet groupSet,
                     List<ImmutableBitSet> groupSets,
                     List<AggregateCall> aggCalls,
                     OperatorPhase phase) throws InvalidRelException {
  final RelTraitSet adjustedTraits = AggPrelBase.adjustTraits(traits, child, groupSet)
      .replaceIf(RelCollationTraitDef.INSTANCE, () -> {
        // Validate input collation which should match groups
        if (AssertionUtil.isAssertionsEnabled()) {
          validateCollation(cluster, child, groupSet);
        }

        return collation(groupSet);
      });

  return new StreamAggPrel(cluster, adjustedTraits, child, indicator, groupSet, groupSets, aggCalls, phase);
}
 
Example #9
Source File: VolcanoPlannerTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that VolcanoPlanner should fire rule match from subsets after a
 * RelSet merge. The rules matching for a RelSubset should be able to fire
 * on the subsets that are merged into the RelSets.
 */
@Test void testSetMergeMatchSubsetRule() {
  VolcanoPlanner planner = new VolcanoPlanner();
  planner.addRelTraitDef(ConventionTraitDef.INSTANCE);
  planner.addRelTraitDef(RelCollationTraitDef.INSTANCE);

  planner.addRule(new PhysLeafRule());
  planner.addRule(new GoodSingleRule());
  planner.addRule(new PhysSingleInputSetMergeRule());
  final List<String> buf = new ArrayList<>();
  planner.addRule(new PhysSingleSubsetRule(buf));

  RelOptCluster cluster = newCluster(planner);
  NoneLeafRel leafRel = new NoneLeafRel(cluster, "a");
  NoneSingleRel singleRel = new NoneSingleRel(cluster, leafRel);
  RelNode convertedRel = planner
      .changeTraits(singleRel, cluster.traitSetOf(PHYS_CALLING_CONVENTION));
  planner.setRoot(convertedRel);
  RelNode result = planner.chooseDelegate().findBestExp();
  assertTrue(result instanceof PhysSingleRel);
  assertThat(sort(buf),
      equalTo(
          sort("PhysSingleRel:RelSubset#0.PHYS.[]",
          "PhysSingleRel:RelSubset#0.PHYS_3.[]")));
}
 
Example #10
Source File: EnumerableHashJoin.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Creates an EnumerableHashJoin. */
public static EnumerableHashJoin create(
    RelNode left,
    RelNode right,
    RexNode condition,
    Set<CorrelationId> variablesSet,
    JoinRelType joinType) {
  final RelOptCluster cluster = left.getCluster();
  final RelMetadataQuery mq = cluster.getMetadataQuery();
  final RelTraitSet traitSet =
      cluster.traitSetOf(EnumerableConvention.INSTANCE)
          .replaceIfs(RelCollationTraitDef.INSTANCE,
              () -> RelMdCollation.enumerableHashJoin(mq, left, right, joinType));
  return new EnumerableHashJoin(cluster, traitSet, left, right, condition,
      variablesSet, joinType);
}
 
Example #11
Source File: SqlWorker.java    From quark with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #12
Source File: EnumerableBatchNestedLoopJoin.java    From calcite with Apache License 2.0 6 votes vote down vote up
public static EnumerableBatchNestedLoopJoin create(
    RelNode left,
    RelNode right,
    RexNode condition,
    ImmutableBitSet requiredColumns,
    Set<CorrelationId> variablesSet,
    JoinRelType joinType) {
  final RelOptCluster cluster = left.getCluster();
  final RelMetadataQuery mq = cluster.getMetadataQuery();
  final RelTraitSet traitSet =
      cluster.traitSetOf(EnumerableConvention.INSTANCE)
          .replaceIfs(RelCollationTraitDef.INSTANCE,
              () -> RelMdCollation.enumerableBatchNestedLoopJoin(mq, left, right, joinType));
  return new EnumerableBatchNestedLoopJoin(
      cluster,
      traitSet,
      left,
      right,
      condition,
      variablesSet,
      requiredColumns,
      joinType);
}
 
Example #13
Source File: EnumerableNestedLoopJoin.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Creates an EnumerableNestedLoopJoin. */
public static EnumerableNestedLoopJoin create(
    RelNode left,
    RelNode right,
    RexNode condition,
    Set<CorrelationId> variablesSet,
    JoinRelType joinType) {
  final RelOptCluster cluster = left.getCluster();
  final RelMetadataQuery mq = cluster.getMetadataQuery();
  final RelTraitSet traitSet =
      cluster.traitSetOf(EnumerableConvention.INSTANCE)
          .replaceIfs(RelCollationTraitDef.INSTANCE,
              () -> RelMdCollation.enumerableNestedLoopJoin(mq, left, right, joinType));
  return new EnumerableNestedLoopJoin(cluster, traitSet, left, right, condition,
      variablesSet, joinType);
}
 
Example #14
Source File: Bindables.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Creates a BindableTableScan. */
public static BindableTableScan create(RelOptCluster cluster,
    RelOptTable relOptTable, List<RexNode> filters,
    List<Integer> projects) {
  final Table table = relOptTable.unwrap(Table.class);
  final RelTraitSet traitSet =
      cluster.traitSetOf(BindableConvention.INSTANCE)
          .replaceIfs(RelCollationTraitDef.INSTANCE, () -> {
            if (table != null) {
              return table.getStatistic().getCollations();
            }
            return ImmutableList.of();
          });
  return new BindableTableScan(cluster, traitSet, relOptTable,
      ImmutableList.copyOf(filters), ImmutableIntList.copyOf(projects));
}
 
Example #15
Source File: OLAPValuesRel.java    From kylin with Apache License 2.0 6 votes vote down vote up
/** Creates an OLAPValuesRel. */
public static OLAPValuesRel create(RelOptCluster cluster, final RelDataType rowType,
        final ImmutableList<ImmutableList<RexLiteral>> tuples) {
    final RelMetadataQuery mq = cluster.getMetadataQuery();
    final RelTraitSet traitSet = cluster.traitSetOf(OLAPRel.CONVENTION)
            .replaceIfs(RelCollationTraitDef.INSTANCE, new Supplier<List<RelCollation>>() {
                public List<RelCollation> get() {
                    return RelMdCollation.values(mq, rowType, tuples);
                }
            }).replaceIf(RelDistributionTraitDef.INSTANCE, new Supplier<RelDistribution>() {
                public RelDistribution get() {
                    return RelMdDistribution.values(rowType, tuples);
                }
            });
    return new OLAPValuesRel(cluster, rowType, tuples, traitSet);
}
 
Example #16
Source File: SortRemoveRuleTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * The default schema that is used in these tests provides tables sorted on the primary key. Due
 * to this scan operators always come with a {@link org.apache.calcite.rel.RelCollation} trait.
 */
private RelNode transform(String sql, RuleSet prepareRules) throws Exception {
  final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
  final SchemaPlus defSchema = rootSchema.add("hr", new HrClusteredSchema());
  final FrameworkConfig config = Frameworks.newConfigBuilder()
      .parserConfig(SqlParser.Config.DEFAULT)
      .defaultSchema(defSchema)
      .traitDefs(ConventionTraitDef.INSTANCE, RelCollationTraitDef.INSTANCE)
      .programs(
          Programs.of(prepareRules),
          Programs.ofRules(SortRemoveRule.INSTANCE))
      .build();
  Planner planner = Frameworks.getPlanner(config);
  SqlNode parse = planner.parse(sql);
  SqlNode validate = planner.validate(parse);
  RelRoot planRoot = planner.rel(validate);
  RelNode planBefore = planRoot.rel;
  RelTraitSet desiredTraits = planBefore.getTraitSet()
      .replace(EnumerableConvention.INSTANCE);
  RelNode planAfter = planner.transform(0, desiredTraits, planBefore);
  return planner.transform(1, desiredTraits, planAfter);
}
 
Example #17
Source File: OLAPProjectRule.java    From kylin with Apache License 2.0 6 votes vote down vote up
@Override
public RelNode convert(final RelNode rel) {

    //  KYLIN-3281
    //  OLAPProjectRule can't normal working with projectRel[input=sortRel]
    final LogicalProject project = (LogicalProject) rel;
    final RelNode convertChild = convert(project.getInput(),
            project.getInput().getTraitSet().replace(OLAPRel.CONVENTION));
    final RelOptCluster cluster = convertChild.getCluster();
    final RelTraitSet traitSet = cluster.traitSet().replace(OLAPRel.CONVENTION)
            .replaceIfs(RelCollationTraitDef.INSTANCE, new Supplier<List<RelCollation>>() {
                public List<RelCollation> get() {
                    //  CALCITE-88
                    return RelMdCollation.project(cluster.getMetadataQuery(), convertChild, project.getProjects());
                }
            });
    return new OLAPProjectRel(convertChild.getCluster(), traitSet, convertChild, project.getProjects(),
            project.getRowType());
}
 
Example #18
Source File: PlannerTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Unit test that parses, validates, converts and plans. Planner is
 * provided with a list of RelTraitDefs to register. */
@Test void testPlanWithExplicitTraitDefs() throws Exception {
  RuleSet ruleSet =
      RuleSets.ofList(
          FilterMergeRule.INSTANCE,
          EnumerableRules.ENUMERABLE_TABLE_SCAN_RULE,
          EnumerableRules.ENUMERABLE_FILTER_RULE,
          EnumerableRules.ENUMERABLE_PROJECT_RULE);
  final List<RelTraitDef> traitDefs = new ArrayList<>();
  traitDefs.add(ConventionTraitDef.INSTANCE);
  traitDefs.add(RelCollationTraitDef.INSTANCE);

  Planner planner = getPlanner(traitDefs, Programs.of(ruleSet));

  SqlNode parse = planner.parse("select * from \"emps\"");
  SqlNode validate = planner.validate(parse);
  RelNode convert = planner.rel(validate).project();
  RelTraitSet traitSet = convert.getTraitSet()
      .replace(EnumerableConvention.INSTANCE);
  RelNode transform = planner.transform(0, traitSet, convert);
  assertThat(toString(transform),
      equalTo(
          "EnumerableProject(empid=[$0], deptno=[$1], name=[$2], salary=[$3], commission=[$4])\n"
          + "  EnumerableTableScan(table=[[hr, emps]])\n"));
}
 
Example #19
Source File: BatsOptimizerTest.java    From Bats with Apache License 2.0 6 votes vote down vote up
static HepPlanner createHepPlanner() {
    HepProgramBuilder builder = new HepProgramBuilder();
    // builder.addRuleInstance(FilterJoinRule.FilterIntoJoinRule.FILTER_ON_JOIN);
    // builder.addRuleInstance(FilterJoinRule.JOIN);
    builder.addRuleCollection(Programs.CALC_RULES);
    // builder.addRuleCollection(Programs.RULE_SET);
    // builder.addRuleInstance(ReduceExpressionsRule.PROJECT_INSTANCE); // 加上这个可以把100+100变成200,常量折叠
    // builder.addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE);
    // builder.addRuleInstance(FilterProjectTransposeRule.INSTANCE);

    // HepMatchOrder order = HepMatchOrder.TOP_DOWN;
    // builder.addMatchOrder(order);
    // builder.addConverters(true);

    HepPlanner hepPlanner = new HepPlanner(builder.build());

    hepPlanner.addRelTraitDef(ConventionTraitDef.INSTANCE);
    hepPlanner.addRelTraitDef(RelCollationTraitDef.INSTANCE);
    return hepPlanner;
}
 
Example #20
Source File: EnumerableCalc.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Creates an EnumerableCalc. */
public static EnumerableCalc create(final RelNode input,
    final RexProgram program) {
  final RelOptCluster cluster = input.getCluster();
  final RelMetadataQuery mq = cluster.getMetadataQuery();
  final RelTraitSet traitSet = cluster.traitSet()
      .replace(EnumerableConvention.INSTANCE)
      .replaceIfs(RelCollationTraitDef.INSTANCE,
          () -> RelMdCollation.calc(mq, input, program))
      .replaceIf(RelDistributionTraitDef.INSTANCE,
          () -> RelMdDistribution.calc(mq, input, program));
  return new EnumerableCalc(cluster, traitSet, input, program);
}
 
Example #21
Source File: LogicalTableSpool.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Creates a LogicalTableSpool. */
public static LogicalTableSpool create(RelNode input, Type readType,
    Type writeType, RelOptTable table) {
  RelOptCluster cluster = input.getCluster();
  RelMetadataQuery mq = cluster.getMetadataQuery();
  RelTraitSet traitSet = cluster.traitSetOf(Convention.NONE)
      .replaceIfs(RelCollationTraitDef.INSTANCE,
          () -> mq.collations(input))
      .replaceIf(RelDistributionTraitDef.INSTANCE,
          () -> mq.distribution(input));
  return new LogicalTableSpool(cluster, traitSet, input, readType, writeType, table);
}
 
Example #22
Source File: SortExchange.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a SortExchange by parsing serialized output.
 */
public SortExchange(RelInput input) {
  this(input.getCluster(),
      input.getTraitSet().plus(input.getCollation())
          .plus(input.getDistribution()),
      input.getInput(),
      RelDistributionTraitDef.INSTANCE.canonize(input.getDistribution()),
      RelCollationTraitDef.INSTANCE.canonize(input.getCollation()));
}
 
Example #23
Source File: Bindables.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Creates a BindableFilter. */
public static BindableFilter create(final RelNode input,
    RexNode condition) {
  final RelOptCluster cluster = input.getCluster();
  final RelMetadataQuery mq = cluster.getMetadataQuery();
  final RelTraitSet traitSet =
      cluster.traitSetOf(BindableConvention.INSTANCE)
          .replaceIfs(RelCollationTraitDef.INSTANCE,
              () -> RelMdCollation.filter(mq, input));
  return new BindableFilter(cluster, traitSet, input, condition);
}
 
Example #24
Source File: LogicalTableScan.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Creates a LogicalTableScan.
 *
 * @param cluster     Cluster
 * @param relOptTable Table
 * @param hints       The hints
 */
public static LogicalTableScan create(RelOptCluster cluster,
    final RelOptTable relOptTable, List<RelHint> hints) {
  final Table table = relOptTable.unwrap(Table.class);
  final RelTraitSet traitSet =
      cluster.traitSetOf(Convention.NONE)
          .replaceIfs(RelCollationTraitDef.INSTANCE, () -> {
            if (table != null) {
              return table.getStatistic().getCollations();
            }
            return ImmutableList.of();
          });
  return new LogicalTableScan(cluster, traitSet, hints, relOptTable);
}
 
Example #25
Source File: LogicalValues.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Creates a LogicalValues. */
public static LogicalValues create(RelOptCluster cluster,
    final RelDataType rowType,
    final ImmutableList<ImmutableList<RexLiteral>> tuples) {
  final RelMetadataQuery mq = cluster.getMetadataQuery();
  final RelTraitSet traitSet = cluster.traitSetOf(Convention.NONE)
      .replaceIfs(RelCollationTraitDef.INSTANCE,
          () -> RelMdCollation.values(mq, rowType, tuples))
      .replaceIf(RelDistributionTraitDef.INSTANCE,
          () -> RelMdDistribution.values(rowType, tuples));
  return new LogicalValues(cluster, traitSet, rowType, tuples);
}
 
Example #26
Source File: LogicalSnapshot.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Creates a LogicalSnapshot. */
public static LogicalSnapshot create(RelNode input, RexNode period) {
  final RelOptCluster cluster = input.getCluster();
  final RelMetadataQuery mq = cluster.getMetadataQuery();
  final RelTraitSet traitSet = cluster.traitSet()
      .replace(Convention.NONE)
      .replaceIfs(RelCollationTraitDef.INSTANCE,
          () -> RelMdCollation.snapshot(mq, input))
      .replaceIf(RelDistributionTraitDef.INSTANCE,
          () -> RelMdDistribution.snapshot(mq, input));
  return new LogicalSnapshot(cluster, traitSet, input, period);
}
 
Example #27
Source File: LogicalFilter.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Creates a LogicalFilter. */
public static LogicalFilter create(final RelNode input, RexNode condition,
    ImmutableSet<CorrelationId> variablesSet) {
  final RelOptCluster cluster = input.getCluster();
  final RelMetadataQuery mq = cluster.getMetadataQuery();
  final RelTraitSet traitSet = cluster.traitSetOf(Convention.NONE)
      .replaceIfs(RelCollationTraitDef.INSTANCE,
          () -> RelMdCollation.filter(mq, input))
      .replaceIf(RelDistributionTraitDef.INSTANCE,
          () -> RelMdDistribution.filter(mq, input));
  return new LogicalFilter(cluster, traitSet, input, condition, variablesSet);
}
 
Example #28
Source File: LogicalCalc.java    From calcite with Apache License 2.0 5 votes vote down vote up
public static LogicalCalc create(final RelNode input,
    final RexProgram program) {
  final RelOptCluster cluster = input.getCluster();
  final RelMetadataQuery mq = cluster.getMetadataQuery();
  final RelTraitSet traitSet = cluster.traitSet()
      .replace(Convention.NONE)
      .replaceIfs(RelCollationTraitDef.INSTANCE,
          () -> RelMdCollation.calc(mq, input, program))
      .replaceIf(RelDistributionTraitDef.INSTANCE,
          () -> RelMdDistribution.calc(mq, input, program));
  return new LogicalCalc(cluster, traitSet, ImmutableList.of(), input, program);
}
 
Example #29
Source File: LogicalSortExchange.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a LogicalSortExchange.
 *
 * @param input     Input relational expression
 * @param distribution Distribution specification
 * @param collation array of sort specifications
 */
public static LogicalSortExchange create(
    RelNode input,
    RelDistribution distribution,
    RelCollation collation) {
  RelOptCluster cluster = input.getCluster();
  collation = RelCollationTraitDef.INSTANCE.canonize(collation);
  distribution = RelDistributionTraitDef.INSTANCE.canonize(distribution);
  RelTraitSet traitSet =
      input.getTraitSet().replace(Convention.NONE).replace(distribution).replace(collation);
  return new LogicalSortExchange(cluster, traitSet, input, distribution,
      collation);
}
 
Example #30
Source File: LogicalProject.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Creates a LogicalProject, specifying row type rather than field names. */
public static LogicalProject create(final RelNode input, List<RelHint> hints,
    final List<? extends RexNode> projects, RelDataType rowType) {
  final RelOptCluster cluster = input.getCluster();
  final RelMetadataQuery mq = cluster.getMetadataQuery();
  final RelTraitSet traitSet =
      cluster.traitSet().replace(Convention.NONE)
          .replaceIfs(RelCollationTraitDef.INSTANCE,
              () -> RelMdCollation.project(mq, input, projects));
  return new LogicalProject(cluster, traitSet, hints, input, projects, rowType);
}