Java Code Examples for org.apache.calcite.plan.RelOptCluster#getMetadataQuery()

The following examples show how to use org.apache.calcite.plan.RelOptCluster#getMetadataQuery() . 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: 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 2
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 3
Source File: StreamAggPrel.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public static void validateCollation(RelOptCluster cluster, RelNode child, ImmutableBitSet groupSet) {
  if (groupSet.isEmpty()) {
    // If no groups, no collation is required
    return;
  }

  final RelCollation requiredCollation = RelCollations.of(
      StreamSupport.stream(groupSet.spliterator(), false).map(RelFieldCollation::new).collect(Collectors.toList()));

  final RelMetadataQuery mq = cluster.getMetadataQuery();
  final List<RelCollation> collations = mq.collations(child);

  for(RelCollation collation: collations) {
    if (collation.satisfies(requiredCollation)) {
      return;
    }
  }

  throw new AssertionError("child collations [" + collations + "] does not match expected collation [" + requiredCollation + "]");
}
 
Example 4
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 5
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 6
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);
}
 
Example 7
Source File: EnumerableMergeJoin.java    From calcite with Apache License 2.0 5 votes vote down vote up
public static EnumerableMergeJoin create(RelNode left, RelNode right,
    RexNode condition, ImmutableIntList leftKeys,
    ImmutableIntList rightKeys, JoinRelType joinType) {
  final RelOptCluster cluster = right.getCluster();
  RelTraitSet traitSet = cluster.traitSet();
  if (traitSet.isEnabled(RelCollationTraitDef.INSTANCE)) {
    final RelMetadataQuery mq = cluster.getMetadataQuery();
    final List<RelCollation> collations =
        RelMdCollation.mergeJoin(mq, left, right, leftKeys, rightKeys, joinType);
    traitSet = traitSet.replace(collations);
  }
  return new EnumerableMergeJoin(cluster, traitSet, left, right, condition,
      ImmutableSet.of(), joinType);
}
 
Example 8
Source File: EnumerableLimit.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Creates an EnumerableLimit. */
public static EnumerableLimit create(final RelNode input, RexNode offset,
    RexNode fetch) {
  final RelOptCluster cluster = input.getCluster();
  final RelMetadataQuery mq = cluster.getMetadataQuery();
  final RelTraitSet traitSet =
      cluster.traitSetOf(EnumerableConvention.INSTANCE)
          .replaceIfs(
              RelCollationTraitDef.INSTANCE,
              () -> RelMdCollation.limit(mq, input))
          .replaceIf(RelDistributionTraitDef.INSTANCE,
              () -> RelMdDistribution.limit(mq, input));
  return new EnumerableLimit(cluster, traitSet, input, offset, fetch);
}
 
Example 9
Source File: EnumerableValues.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Creates an EnumerableValues. */
public static EnumerableValues create(RelOptCluster cluster,
    final RelDataType rowType,
    final ImmutableList<ImmutableList<RexLiteral>> tuples) {
  final RelMetadataQuery mq = cluster.getMetadataQuery();
  final RelTraitSet traitSet =
      cluster.traitSetOf(EnumerableConvention.INSTANCE)
          .replaceIfs(RelCollationTraitDef.INSTANCE,
              () -> RelMdCollation.values(mq, rowType, tuples))
          .replaceIf(RelDistributionTraitDef.INSTANCE,
              () -> RelMdDistribution.values(rowType, tuples));
  return new EnumerableValues(cluster, rowType, tuples, traitSet);
}
 
Example 10
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 11
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 12
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 13
Source File: TraitPropagationTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
public static PhysProj create(final RelNode input,
    final List<RexNode> projects, RelDataType rowType) {
  final RelOptCluster cluster = input.getCluster();
  final RelMetadataQuery mq = cluster.getMetadataQuery();
  final RelTraitSet traitSet =
      cluster.traitSet().replace(PHYSICAL)
          .replaceIfs(
              RelCollationTraitDef.INSTANCE,
              () -> RelMdCollation.project(mq, input, projects));
  return new PhysProj(cluster, traitSet, input, projects, rowType);
}
 
Example 14
Source File: LogicalProject.java    From Bats 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,
    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, input, projects, rowType);
}
 
Example 15
Source File: ProjectRelBase.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
protected static RelTraitSet adjustTraits(RelOptCluster cluster, RelNode input, List<? extends RexNode> exps, RelTraitSet traits) {
  final RelMetadataQuery mq = cluster.getMetadataQuery();
  return traits.replaceIfs(
      RelCollationTraitDef.INSTANCE,
      () -> RelMdCollation.project(mq, input, exps)
  );
}
 
Example 16
Source File: LogicalValues.java    From Bats 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));
  return new LogicalValues(cluster, traitSet, rowType, tuples);
}
 
Example 17
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 18
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 19
Source File: LogicalCalc.java    From Bats 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, input, program);
}
 
Example 20
Source File: ConvertFromJsonConverter.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public ConvertFromJsonConverter(QueryContext context, RelOptCluster cluster) {
  this.context = context;
  this.query = cluster.getMetadataQuery();
  this.factory = cluster.getTypeFactory();
}