Java Code Examples for org.apache.calcite.rel.logical.LogicalFilter#getCondition()

The following examples show how to use org.apache.calcite.rel.logical.LogicalFilter#getCondition() . 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: GeodeRules.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Override public boolean matches(RelOptRuleCall call) {
  // Get the condition from the filter operation
  LogicalFilter filter = call.rel(0);
  RexNode condition = filter.getCondition();

  List<String> fieldNames = GeodeRules.geodeFieldNames(filter.getInput().getRowType());

  List<RexNode> disjunctions = RelOptUtil.disjunctions(condition);
  if (disjunctions.size() != 1) {
    return true;
  } else {
    // Check that all conjunctions are primary field conditions.
    condition = disjunctions.get(0);
    for (RexNode predicate : RelOptUtil.conjunctions(condition)) {
      if (!isEqualityOnKey(predicate, fieldNames)) {
        return false;
      }
    }
  }

  return true;
}
 
Example 2
Source File: GeodeRules.java    From calcite with Apache License 2.0 5 votes vote down vote up
private RelNode convert(LogicalFilter filter, GeodeTableScan scan) {
  final RelTraitSet traitSet = filter.getTraitSet().replace(GeodeRel.CONVENTION);
  return new GeodeFilter(
      filter.getCluster(),
      traitSet,
      convert(filter.getInput(), GeodeRel.CONVENTION),
      filter.getCondition());
}
 
Example 3
Source File: RelStructuredTypeFlattener.java    From calcite with Apache License 2.0 5 votes vote down vote up
public void rewriteRel(LogicalFilter rel) {
  RelTraitSet traits = rel.getTraitSet();
  RewriteRexShuttle rewriteRexShuttle = new RewriteRexShuttle();
  RexNode oldCondition = rel.getCondition();
  RelNode newInput = getNewForOldRel(rel.getInput());
  RexNode newCondition = oldCondition.accept(rewriteRexShuttle);
  LogicalFilter newRel = rel.copy(traits, newInput, newCondition);
  setNewForOldRel(rel, newRel);
}
 
Example 4
Source File: EnumerableFilterRule.java    From calcite with Apache License 2.0 5 votes vote down vote up
public RelNode convert(RelNode rel) {
  final LogicalFilter filter = (LogicalFilter) rel;
  return new EnumerableFilter(rel.getCluster(),
      rel.getTraitSet().replace(EnumerableConvention.INSTANCE),
      convert(filter.getInput(),
          filter.getInput().getTraitSet()
              .replace(EnumerableConvention.INSTANCE)),
      filter.getCondition());
}
 
Example 5
Source File: MongoRules.java    From calcite with Apache License 2.0 5 votes vote down vote up
public RelNode convert(RelNode rel) {
  final LogicalFilter filter = (LogicalFilter) rel;
  final RelTraitSet traitSet = filter.getTraitSet().replace(out);
  return new MongoFilter(
      rel.getCluster(),
      traitSet,
      convert(filter.getInput(), out),
      filter.getCondition());
}
 
Example 6
Source File: ElasticsearchRules.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public RelNode convert(RelNode relNode) {
  final LogicalFilter filter = (LogicalFilter) relNode;
  final RelTraitSet traitSet = filter.getTraitSet().replace(out);
  return new ElasticsearchFilter(relNode.getCluster(), traitSet,
    convert(filter.getInput(), out),
    filter.getCondition());
}
 
Example 7
Source File: CassandraRules.java    From calcite with Apache License 2.0 5 votes vote down vote up
public RelNode convert(LogicalFilter filter, CassandraTableScan scan) {
  final RelTraitSet traitSet = filter.getTraitSet().replace(CassandraRel.CONVENTION);
  final Pair<List<String>, List<String>> keyFields = scan.cassandraTable.getKeyFields();
  return new CassandraFilter(
      filter.getCluster(),
      traitSet,
      convert(filter.getInput(), CassandraRel.CONVENTION),
      filter.getCondition(),
      keyFields.left,
      keyFields.right,
      scan.cassandraTable.getClusteringOrder());
}
 
Example 8
Source File: CassandraRules.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public boolean matches(RelOptRuleCall call) {
  // Get the condition from the filter operation
  LogicalFilter filter = call.rel(0);
  RexNode condition = filter.getCondition();

  // Get field names from the scan operation
  CassandraTableScan scan = call.rel(1);
  Pair<List<String>, List<String>> keyFields = scan.cassandraTable.getKeyFields();
  Set<String> partitionKeys = new HashSet<>(keyFields.left);
  List<String> fieldNames = CassandraRules.cassandraFieldNames(filter.getInput().getRowType());

  List<RexNode> disjunctions = RelOptUtil.disjunctions(condition);
  if (disjunctions.size() != 1) {
    return false;
  } else {
    // Check that all conjunctions are primary key equalities
    condition = disjunctions.get(0);
    for (RexNode predicate : RelOptUtil.conjunctions(condition)) {
      if (!isEqualityOnKey(predicate, fieldNames, partitionKeys, keyFields.right)) {
        return false;
      }
    }
  }

  // Either all of the partition keys must be specified or none
  return partitionKeys.size() == keyFields.left.size() || partitionKeys.size() == 0;
}
 
Example 9
Source File: OLAPFilterRule.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
public RelNode convert(RelNode rel) {
    LogicalFilter filter = (LogicalFilter) rel;

    RelTraitSet origTraitSet = filter.getTraitSet();
    RelTraitSet traitSet = origTraitSet.replace(OLAPRel.CONVENTION).simplify();

    return new OLAPFilterRel(filter.getCluster(), traitSet,
            convert(filter.getInput(), filter.getInput().getTraitSet().replace(OLAPRel.CONVENTION)),
            filter.getCondition());
}
 
Example 10
Source File: GremlinRules.java    From sql-gremlin with Apache License 2.0 5 votes vote down vote up
public RelNode convert(RelNode rel) {
    final LogicalFilter filter = (LogicalFilter) rel;
    final RelTraitSet traitSet = filter.getTraitSet().replace(out);
    return new GremlinFilter(
            rel.getCluster(),
            traitSet,
            convert(filter.getInput(), out),
            filter.getCondition());
}
 
Example 11
Source File: SolrRules.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public RelNode convert(RelNode rel) {
  final LogicalFilter filter = (LogicalFilter) rel;
  final RelTraitSet traitSet = filter.getTraitSet().replace(out);
  return new SolrFilter(
      rel.getCluster(),
      traitSet,
      convert(filter.getInput(), out),
      filter.getCondition());
}
 
Example 12
Source File: ReduceTrigFunctionsRule.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void onMatch(RelOptRuleCall call) {
  LogicalFilter filter = (LogicalFilter) call.rels[0];
  RexNode newCondition = RexRewriter.rewrite(filter.getCondition(), getRules(filter.getCluster().getRexBuilder()));
  if (newCondition != filter.getCondition()) {
    call.transformTo(LogicalFilter.create(filter.getInput(), newCondition));
  }
}
 
Example 13
Source File: ElasticsearchFilterRule.java    From dk-fitting with Apache License 2.0 5 votes vote down vote up
public RelNode convert(RelNode relNode) {
    final LogicalFilter filter = (LogicalFilter) relNode;
    final RelTraitSet traitSet = filter.getTraitSet().replace(getOutTrait());
    return new ElasticsearchFilter(relNode.getCluster(), traitSet,
            convert(filter.getInput(), getOutTrait()),
            filter.getCondition());
}
 
Example 14
Source File: ElasticsearchFilterRule.java    From dk-fitting with Apache License 2.0 5 votes vote down vote up
public RelNode convert(RelNode relNode) {
    final LogicalFilter filter = (LogicalFilter) relNode;
    final RelTraitSet traitSet = filter.getTraitSet().replace(getOutTrait());
    return new ElasticsearchFilter(relNode.getCluster(), traitSet,
            convert(filter.getInput(), getOutTrait()),
            filter.getCondition());
}
 
Example 15
Source File: OLAPFilterRule.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public RelNode convert(RelNode rel) {
    LogicalFilter filter = (LogicalFilter) rel;

    RelTraitSet origTraitSet = filter.getTraitSet();
    RelTraitSet traitSet = origTraitSet.replace(OLAPRel.CONVENTION).simplify();

    return new OLAPFilterRel(filter.getCluster(), traitSet,
            convert(filter.getInput(), filter.getInput().getTraitSet().replace(OLAPRel.CONVENTION)),
            filter.getCondition());
}
 
Example 16
Source File: FilterTableFunctionTransposeRule.java    From Bats with Apache License 2.0 4 votes vote down vote up
public void onMatch(RelOptRuleCall call) {
  LogicalFilter filter = call.rel(0);
  LogicalTableFunctionScan funcRel = call.rel(1);
  Set<RelColumnMapping> columnMappings = funcRel.getColumnMappings();
  if (columnMappings == null || columnMappings.isEmpty()) {
    // No column mapping information, so no push-down
    // possible.
    return;
  }

  List<RelNode> funcInputs = funcRel.getInputs();
  if (funcInputs.size() != 1) {
    // TODO:  support more than one relational input; requires
    // offsetting field indices, similar to join
    return;
  }
  // TODO:  support mappings other than 1-to-1
  if (funcRel.getRowType().getFieldCount()
      != funcInputs.get(0).getRowType().getFieldCount()) {
    return;
  }
  for (RelColumnMapping mapping : columnMappings) {
    if (mapping.iInputColumn != mapping.iOutputColumn) {
      return;
    }
    if (mapping.derived) {
      return;
    }
  }
  final List<RelNode> newFuncInputs = new ArrayList<>();
  final RelOptCluster cluster = funcRel.getCluster();
  final RexNode condition = filter.getCondition();

  // create filters on top of each func input, modifying the filter
  // condition to reference the child instead
  RexBuilder rexBuilder = filter.getCluster().getRexBuilder();
  List<RelDataTypeField> origFields = funcRel.getRowType().getFieldList();
  // TODO:  these need to be non-zero once we
  // support arbitrary mappings
  int[] adjustments = new int[origFields.size()];
  for (RelNode funcInput : funcInputs) {
    RexNode newCondition =
        condition.accept(
            new RelOptUtil.RexInputConverter(
                rexBuilder,
                origFields,
                funcInput.getRowType().getFieldList(),
                adjustments));
    newFuncInputs.add(
        LogicalFilter.create(funcInput, newCondition));
  }

  // create a new UDX whose children are the filters created above
  LogicalTableFunctionScan newFuncRel =
      LogicalTableFunctionScan.create(cluster, newFuncInputs,
          funcRel.getCall(), funcRel.getElementType(), funcRel.getRowType(),
          columnMappings);
  call.transformTo(newFuncRel);
}
 
Example 17
Source File: PigRules.java    From calcite with Apache License 2.0 4 votes vote down vote up
public RelNode convert(RelNode rel) {
  final LogicalFilter filter = (LogicalFilter) rel;
  final RelTraitSet traitSet = filter.getTraitSet().replace(PigRel.CONVENTION);
  return new PigFilter(rel.getCluster(), traitSet,
      convert(filter.getInput(), PigRel.CONVENTION), filter.getCondition());
}
 
Example 18
Source File: FilterTableFunctionTransposeRule.java    From calcite with Apache License 2.0 4 votes vote down vote up
public void onMatch(RelOptRuleCall call) {
  LogicalFilter filter = call.rel(0);
  LogicalTableFunctionScan funcRel = call.rel(1);
  Set<RelColumnMapping> columnMappings = funcRel.getColumnMappings();
  if (columnMappings == null || columnMappings.isEmpty()) {
    // No column mapping information, so no push-down
    // possible.
    return;
  }

  List<RelNode> funcInputs = funcRel.getInputs();
  if (funcInputs.size() != 1) {
    // TODO:  support more than one relational input; requires
    // offsetting field indices, similar to join
    return;
  }
  // TODO:  support mappings other than 1-to-1
  if (funcRel.getRowType().getFieldCount()
      != funcInputs.get(0).getRowType().getFieldCount()) {
    return;
  }
  for (RelColumnMapping mapping : columnMappings) {
    if (mapping.iInputColumn != mapping.iOutputColumn) {
      return;
    }
    if (mapping.derived) {
      return;
    }
  }
  final List<RelNode> newFuncInputs = new ArrayList<>();
  final RelOptCluster cluster = funcRel.getCluster();
  final RexNode condition = filter.getCondition();

  // create filters on top of each func input, modifying the filter
  // condition to reference the child instead
  RexBuilder rexBuilder = filter.getCluster().getRexBuilder();
  List<RelDataTypeField> origFields = funcRel.getRowType().getFieldList();
  // TODO:  these need to be non-zero once we
  // support arbitrary mappings
  int[] adjustments = new int[origFields.size()];
  for (RelNode funcInput : funcInputs) {
    RexNode newCondition =
        condition.accept(
            new RelOptUtil.RexInputConverter(
                rexBuilder,
                origFields,
                funcInput.getRowType().getFieldList(),
                adjustments));
    newFuncInputs.add(
        LogicalFilter.create(funcInput, newCondition));
  }

  // create a new UDX whose children are the filters created above
  LogicalTableFunctionScan newFuncRel =
      LogicalTableFunctionScan.create(cluster, newFuncInputs,
          funcRel.getCall(), funcRel.getElementType(), funcRel.getRowType(),
          columnMappings);
  call.transformTo(newFuncRel);
}