org.apache.calcite.plan.RelTraitSet Java Examples

The following examples show how to use org.apache.calcite.plan.RelTraitSet. 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: EnumerableTableModifyRule.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Override public RelNode convert(RelNode rel) {
  final LogicalTableModify modify =
      (LogicalTableModify) rel;
  final ModifiableTable modifiableTable =
      modify.getTable().unwrap(ModifiableTable.class);
  if (modifiableTable == null) {
    return null;
  }
  final RelTraitSet traitSet =
      modify.getTraitSet().replace(EnumerableConvention.INSTANCE);
  return new EnumerableTableModify(
      modify.getCluster(), traitSet,
      modify.getTable(),
      modify.getCatalogReader(),
      convert(modify.getInput(), traitSet),
      modify.getOperation(),
      modify.getUpdateColumnList(),
      modify.getSourceExpressionList(),
      modify.isFlattened());
}
 
Example #2
Source File: MongoRules.java    From calcite with Apache License 2.0 6 votes vote down vote up
public RelNode convert(RelNode rel) {
  final LogicalAggregate agg = (LogicalAggregate) rel;
  final RelTraitSet traitSet =
      agg.getTraitSet().replace(out);
  try {
    return new MongoAggregate(
        rel.getCluster(),
        traitSet,
        convert(agg.getInput(), traitSet.simplify()),
        agg.getGroupSet(),
        agg.getGroupSets(),
        agg.getAggCallList());
  } catch (InvalidRelException e) {
    LOGGER.warn(e.toString());
    return null;
  }
}
 
Example #3
Source File: HashAggPrule.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
private void createTransformRequest(RelOptRuleCall call, AggregateRel aggregate,
                                    RelNode input, RelTraitSet traits) throws InvalidRelException {

  final RelNode convertedInput = convert(input, PrelUtil.fixTraits(call, traits));

  HashAggPrel newAgg = HashAggPrel.create(
      aggregate.getCluster(),
      traits,
      convertedInput,
      aggregate.indicator,
      aggregate.getGroupSet(),
      aggregate.getGroupSets(),
      aggregate.getAggCallList(),
      OperatorPhase.PHASE_1of1);

  call.transformTo(newAgg);
}
 
Example #4
Source File: StreamAggPrule.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
private void createTransformRequest(RelOptRuleCall call, AggregateRel aggregate,
                                    RelNode input, RelTraitSet inputTraits, RelTraitSet outputTraits) throws InvalidRelException {

  final RelNode convertedInput = convert(input, inputTraits);

  StreamAggPrel newAgg = StreamAggPrel.create(
      aggregate.getCluster(),
      outputTraits,
      convertedInput,
      aggregate.indicator,
      aggregate.getGroupSet(),
      aggregate.getGroupSets(),
      aggregate.getAggCallList(),
      OperatorPhase.PHASE_1of1);

  call.transformTo(newAgg);
}
 
Example #5
Source File: SparkRules.java    From calcite with Apache License 2.0 5 votes vote down vote up
public RelNode copy(RelTraitSet traitSet, List<RelNode> inputs) {
  return new SparkCalc(
      getCluster(),
      traitSet,
      sole(inputs),
      program);
}
 
Example #6
Source File: AbstractRelNode.java    From Bats with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an <code>AbstractRelNode</code>.
 */
public AbstractRelNode(RelOptCluster cluster, RelTraitSet traitSet) {
  super();
  assert cluster != null;
  this.cluster = cluster;
  this.traitSet = traitSet;
  this.id = NEXT_ID.getAndIncrement();
  this.digest = getRelTypeName() + "#" + id;
  this.desc = digest;
  LOGGER.trace("new {}", digest);
}
 
Example #7
Source File: Aggregate.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Deprecated // to be removed before 2.0
public Aggregate copy(RelTraitSet traitSet, RelNode input,
    boolean indicator, ImmutableBitSet groupSet,
    List<ImmutableBitSet> groupSets, List<AggregateCall> aggCalls) {
  checkIndicator(indicator);
  return copy(traitSet, input, groupSet, groupSets, aggCalls);
}
 
Example #8
Source File: GremlinFilter.java    From sql-gremlin with Apache License 2.0 5 votes vote down vote up
public GremlinFilter(
        RelOptCluster cluster,
        RelTraitSet traitSet,
        RelNode child,
        RexNode condition) {
    super(cluster, traitSet, child, condition);
}
 
Example #9
Source File: JdbcRules.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Deprecated // to be removed before 2.0
protected JdbcJoin(
    RelOptCluster cluster,
    RelTraitSet traitSet,
    RelNode left,
    RelNode right,
    RexNode condition,
    JoinRelType joinType,
    Set<String> variablesStopped)
    throws InvalidRelException {
  this(cluster, traitSet, left, right, condition,
      CorrelationId.setOf(variablesStopped), joinType);
}
 
Example #10
Source File: GremlinTraversalToEnumerableRelConverter.java    From sql-gremlin with Apache License 2.0 5 votes vote down vote up
public GremlinTraversalToEnumerableRelConverter (
        RelOptCluster cluster,
        RelTraitSet traits,
        RelNode input, RelDataType rowType) {
    super(cluster, ConventionTraitDef.INSTANCE, traits, input);
    this.rowType = rowType;
}
 
Example #11
Source File: RelSubset.java    From Bats with Apache License 2.0 5 votes vote down vote up
private static String traitDiff(RelTraitSet original, RelTraitSet desired) {
  return Pair.zip(original, desired)
      .stream()
      .filter(p -> !p.left.satisfies(p.right))
      .map(p -> p.left.getTraitDef().getSimpleName() + ": " + p.left + " -> " + p.right)
      .collect(Collectors.joining(", ", "[", "]"));
}
 
Example #12
Source File: EnumerableFilter.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public Pair<RelTraitSet, List<RelTraitSet>> passThroughTraits(
    RelTraitSet required) {
  RelCollation collation = required.getCollation();
  if (collation == null || collation == RelCollations.EMPTY) {
    return null;
  }
  RelTraitSet traits = traitSet.replace(collation);
  return Pair.of(traits, ImmutableList.of(traits));
}
 
Example #13
Source File: EquiJoin.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Creates an EquiJoin. */
public EquiJoin(RelOptCluster cluster, RelTraitSet traits, RelNode left,
    RelNode right, RexNode condition, Set<CorrelationId> variablesSet,
    JoinRelType joinType) {
  super(cluster, traits, ImmutableList.of(), left, right, condition, variablesSet, joinType);
  this.leftKeys = Objects.requireNonNull(joinInfo.leftKeys);
  this.rightKeys = Objects.requireNonNull(joinInfo.rightKeys);
  assert joinInfo.isEqui() : "Create EquiJoin with non-equi join condition.";
}
 
Example #14
Source File: EnumerableTableFunctionScanRule.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public RelNode convert(RelNode rel) {
  final RelTraitSet traitSet =
      rel.getTraitSet().replace(EnumerableConvention.INSTANCE);
  LogicalTableFunctionScan tbl = (LogicalTableFunctionScan) rel;
  return new EnumerableTableFunctionScan(rel.getCluster(), traitSet,
      convertList(tbl.getInputs(), traitSet.getTrait(0)), tbl.getElementType(), tbl.getRowType(),
      tbl.getCall(), tbl.getColumnMappings());
}
 
Example #15
Source File: OLAPNonEquiJoinRel.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
public EnumerableThetaJoin copy(RelTraitSet traitSet, RexNode condition, RelNode left, RelNode right, JoinRelType joinType, boolean semiJoinDone) {
    try {
        return new OLAPNonEquiJoinRel(this.getCluster(), traitSet, left, right, condition, this.variablesSet, joinType);
    } catch (InvalidRelException var8) {
        throw new AssertionError(var8);
    }
}
 
Example #16
Source File: JdbcRules.java    From calcite with Apache License 2.0 5 votes vote down vote up
public JdbcProject(
    RelOptCluster cluster,
    RelTraitSet traitSet,
    RelNode input,
    List<? extends RexNode> projects,
    RelDataType rowType) {
  super(cluster, traitSet, ImmutableList.of(), input, projects, rowType);
  assert getConvention() instanceof JdbcConvention;
}
 
Example #17
Source File: WindowRel.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a window relational expression.
 *
 * @param cluster Cluster
 * @param traits
 * @param child   Input relational expression
 * @param rowType Output row type
 * @param groups Windows
 */
private WindowRel(
    RelOptCluster cluster,
    RelTraitSet traits,
    RelNode child,
    List<RexLiteral> constants,
    RelDataType rowType,
    List<Group> groups) {
  super(cluster, traits, child, constants, rowType, groups);
}
 
Example #18
Source File: LogicalSortExchange.java    From Bats 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 #19
Source File: HashJoinPrel.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override
public Join copy(RelTraitSet traitSet, RexNode conditionExpr, RelNode left, RelNode right, JoinRelType joinType, boolean semiJoinDone) {
  try {
    return new HashJoinPrel(this.getCluster(), traitSet, left, right, conditionExpr, joinType, this.swapped, this.runtimeFilterDef,
        this.isRowKeyJoin, this.joinControl, this.isSemiJoin);
  }catch (InvalidRelException e) {
    throw new AssertionError(e);
  }
}
 
Example #20
Source File: JdbcRules.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public JdbcAggregate copy(RelTraitSet traitSet, RelNode input,
    ImmutableBitSet groupSet,
    List<ImmutableBitSet> groupSets, List<AggregateCall> aggCalls) {
  try {
    return new JdbcAggregate(getCluster(), traitSet, input,
        groupSet, groupSets, aggCalls);
  } catch (InvalidRelException e) {
    // Semantic error not possible. Must be a bug. Convert to
    // internal error.
    throw new AssertionError(e);
  }
}
 
Example #21
Source File: LogicalJoin.java    From Bats with Apache License 2.0 5 votes vote down vote up
/** Creates a LogicalJoin, flagged with whether it has been translated to a
 * semi-join. */
public static LogicalJoin create(RelNode left, RelNode right,
    RexNode condition, Set<CorrelationId> variablesSet, JoinRelType joinType,
    boolean semiJoinDone, ImmutableList<RelDataTypeField> systemFieldList) {
  final RelOptCluster cluster = left.getCluster();
  final RelTraitSet traitSet = cluster.traitSetOf(Convention.NONE);
  return new LogicalJoin(cluster, traitSet, left, right, condition,
      variablesSet, joinType, semiJoinDone, systemFieldList);
}
 
Example #22
Source File: EnumerableFilter.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public Pair<RelTraitSet, List<RelTraitSet>> deriveTraits(
    final RelTraitSet childTraits, final int childId) {
  RelCollation collation = childTraits.getCollation();
  if (collation == null || collation == RelCollations.EMPTY) {
    return null;
  }
  RelTraitSet traits = traitSet.replace(collation);
  return Pair.of(traits, ImmutableList.of(traits));
}
 
Example #23
Source File: ConverterImpl.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a ConverterImpl.
 *
 * @param cluster  planner's cluster
 * @param traitDef the RelTraitDef this converter converts
 * @param traits   the output traits of this converter
 * @param child    child rel (provides input traits)
 */
protected ConverterImpl(
    RelOptCluster cluster,
    RelTraitDef traitDef,
    RelTraitSet traits,
    RelNode child) {
  super(cluster, traits, child);
  this.inTraits = child.getTraitSet();
  this.traitDef = traitDef;
}
 
Example #24
Source File: MongoFilter.java    From calcite with Apache License 2.0 5 votes vote down vote up
public MongoFilter(
    RelOptCluster cluster,
    RelTraitSet traitSet,
    RelNode child,
    RexNode condition) {
  super(cluster, traitSet, child, condition);
  assert getConvention() == MongoRel.CONVENTION;
  assert getConvention() == child.getConvention();
}
 
Example #25
Source File: ElasticsearchAggregate.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public Aggregate copy(RelTraitSet traitSet, RelNode input,
    ImmutableBitSet groupSet, List<ImmutableBitSet> groupSets,
    List<AggregateCall> aggCalls) {
  try {
    return new ElasticsearchAggregate(getCluster(), traitSet, input,
        groupSet, groupSets, aggCalls);
  } catch (InvalidRelException e) {
    throw new AssertionError(e);
  }
}
 
Example #26
Source File: HashToMergeExchangePrel.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public HashToMergeExchangePrel(RelOptCluster cluster, RelTraitSet traitSet, RelNode input,
                               List<DistributionField> fields,
                               RelCollation collation,
                               int numEndPoints) {
  super(cluster, traitSet, input);
  this.distFields = fields;
  this.collation = collation;
  this.numEndPoints = numEndPoints;
  assert input.getConvention() == Prel.PHYSICAL;
}
 
Example #27
Source File: MultiJoin.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override public RelNode copy(RelTraitSet traitSet, List<RelNode> inputs) {
  assert traitSet.containsIfApplicable(Convention.NONE);
  return new MultiJoin(
      getCluster(),
      inputs,
      joinFilter,
      rowType,
      isFullOuterJoin,
      outerJoinConditions,
      joinTypes,
      projFields,
      joinFieldRefCountsMap,
      postJoinFilter);
}
 
Example #28
Source File: EnumerableCalc.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Deprecated // to be removed before 2.0
public EnumerableCalc(
    RelOptCluster cluster,
    RelTraitSet traitSet,
    RelNode input,
    RexProgram program,
    List<RelCollation> collationList) {
  this(cluster, traitSet, input, program);
  Util.discard(collationList);
}
 
Example #29
Source File: AbstractRelNode.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an <code>AbstractRelNode</code>.
 */
public AbstractRelNode(RelOptCluster cluster, RelTraitSet traitSet) {
  super();
  assert cluster != null;
  this.cluster = cluster;
  this.traitSet = traitSet;
  this.id = NEXT_ID.getAndIncrement();
  this.digest = new InnerRelDigest();
}
 
Example #30
Source File: DrillWindowRel.java    From Bats with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a window relational expression.
 *
 * @param cluster Cluster
 * @param traits
 * @param child   Input relational expression
 * @param rowType Output row type
 * @param groups Windows
 */
public DrillWindowRel(
    RelOptCluster cluster,
    RelTraitSet traits,
    RelNode child,
    List<RexLiteral> constants,
    RelDataType rowType,
    List<Group> groups) {
  super(cluster, traits, child, constants, rowType, groups);
}