Java Code Examples for org.apache.calcite.plan.volcano.RelSubset#getRels()

The following examples show how to use org.apache.calcite.plan.volcano.RelSubset#getRels() . 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: RelMdDistinctRowCount.java    From Bats with Apache License 2.0 6 votes vote down vote up
public Double getDistinctRowCount(RelSubset rel, RelMetadataQuery mq,
    ImmutableBitSet groupKey, RexNode predicate) {
  final RelNode best = rel.getBest();
  if (best != null) {
    return mq.getDistinctRowCount(best, groupKey, predicate);
  }
  if (!Bug.CALCITE_1048_FIXED) {
    return getDistinctRowCount((RelNode) rel, mq, groupKey, predicate);
  }
  Double d = null;
  for (RelNode r2 : rel.getRels()) {
    try {
      Double d2 = mq.getDistinctRowCount(r2, groupKey, predicate);
      d = NumberUtil.min(d, d2);
    } catch (CyclicMetadataException e) {
      // Ignore this relational expression; there will be non-cyclic ones
      // in this set.
    }
  }
  return d;
}
 
Example 2
Source File: RelMdColumnUniqueness.java    From Bats with Apache License 2.0 6 votes vote down vote up
public Boolean areColumnsUnique(RelSubset rel, RelMetadataQuery mq,
    ImmutableBitSet columns, boolean ignoreNulls) {
  int nullCount = 0;
  for (RelNode rel2 : rel.getRels()) {
    if (rel2 instanceof Aggregate
        || rel2 instanceof Filter
        || rel2 instanceof Values
        || rel2 instanceof TableScan
        || simplyProjects(rel2, columns)) {
      try {
        final Boolean unique = mq.areColumnsUnique(rel2, columns, ignoreNulls);
        if (unique != null) {
          if (unique) {
            return true;
          }
        } else {
          ++nullCount;
        }
      } catch (CyclicMetadataException e) {
        // Ignore this relational expression; there will be non-cyclic ones
        // in this set.
      }
    }
  }
  return nullCount == 0 ? false : null;
}
 
Example 3
Source File: RelMdPredicates.java    From Bats with Apache License 2.0 6 votes vote down vote up
/** @see RelMetadataQuery#getPulledUpPredicates(RelNode) */
public RelOptPredicateList getPredicates(RelSubset r,
    RelMetadataQuery mq) {
  if (!Bug.CALCITE_1048_FIXED) {
    return RelOptPredicateList.EMPTY;
  }
  final RexBuilder rexBuilder = r.getCluster().getRexBuilder();
  RelOptPredicateList list = null;
  for (RelNode r2 : r.getRels()) {
    RelOptPredicateList list2 = mq.getPulledUpPredicates(r2);
    if (list2 != null) {
      list = list == null ? list2 : list.union(rexBuilder, list2);
    }
  }
  return Util.first(list, RelOptPredicateList.EMPTY);
}
 
Example 4
Source File: RelMdDistinctRowCount.java    From calcite with Apache License 2.0 6 votes vote down vote up
public Double getDistinctRowCount(RelSubset rel, RelMetadataQuery mq,
    ImmutableBitSet groupKey, RexNode predicate) {
  final RelNode best = rel.getBest();
  if (best != null) {
    return mq.getDistinctRowCount(best, groupKey, predicate);
  }
  if (!Bug.CALCITE_1048_FIXED) {
    return getDistinctRowCount((RelNode) rel, mq, groupKey, predicate);
  }
  Double d = null;
  for (RelNode r2 : rel.getRels()) {
    try {
      Double d2 = mq.getDistinctRowCount(r2, groupKey, predicate);
      d = NumberUtil.min(d, d2);
    } catch (CyclicMetadataException e) {
      // Ignore this relational expression; there will be non-cyclic ones
      // in this set.
    }
  }
  return d;
}
 
Example 5
Source File: RelMdPredicates.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** @see RelMetadataQuery#getPulledUpPredicates(RelNode) */
public RelOptPredicateList getPredicates(RelSubset r,
    RelMetadataQuery mq) {
  if (!Bug.CALCITE_1048_FIXED) {
    return RelOptPredicateList.EMPTY;
  }
  final RexBuilder rexBuilder = r.getCluster().getRexBuilder();
  RelOptPredicateList list = null;
  for (RelNode r2 : r.getRels()) {
    RelOptPredicateList list2 = mq.getPulledUpPredicates(r2);
    if (list2 != null) {
      list = list == null ? list2 : list.union(rexBuilder, list2);
    }
  }
  return Util.first(list, RelOptPredicateList.EMPTY);
}
 
Example 6
Source File: PruneEmptyRules.java    From calcite with Apache License 2.0 6 votes vote down vote up
private static boolean isEmpty(RelNode node) {
  if (node instanceof Values) {
    return ((Values) node).getTuples().isEmpty();
  }
  if (node instanceof HepRelVertex) {
    return isEmpty(((HepRelVertex) node).getCurrentRel());
  }
  // Note: relation input might be a RelSubset, so we just iterate over the relations
  // in order to check if the subset is equivalent to an empty relation.
  if (!(node instanceof RelSubset)) {
    return false;
  }
  RelSubset subset = (RelSubset) node;
  for (RelNode rel : subset.getRels()) {
    if (isEmpty(rel)) {
      return true;
    }
  }
  return false;
}
 
Example 7
Source File: RelMdMaxRowCount.java    From Bats with Apache License 2.0 5 votes vote down vote up
public Double getMaxRowCount(RelSubset rel, RelMetadataQuery mq) {
  // FIXME This is a short-term fix for [CALCITE-1018]. A complete
  // solution will come with [CALCITE-1048].
  Util.discard(Bug.CALCITE_1048_FIXED);
  for (RelNode node : rel.getRels()) {
    if (node instanceof Sort) {
      Sort sort = (Sort) node;
      if (sort.fetch != null) {
        return (double) RexLiteral.intValue(sort.fetch);
      }
    }
  }

  return Double.POSITIVE_INFINITY;
}
 
Example 8
Source File: RelMdMinRowCount.java    From Bats with Apache License 2.0 5 votes vote down vote up
public Double getMinRowCount(RelSubset rel, RelMetadataQuery mq) {
  // FIXME This is a short-term fix for [CALCITE-1018]. A complete
  // solution will come with [CALCITE-1048].
  Util.discard(Bug.CALCITE_1048_FIXED);
  for (RelNode node : rel.getRels()) {
    if (node instanceof Sort) {
      Sort sort = (Sort) node;
      if (sort.fetch != null) {
        return (double) RexLiteral.intValue(sort.fetch);
      }
    }
  }

  return 0D;
}
 
Example 9
Source File: RelMdMaxRowCount.java    From calcite with Apache License 2.0 5 votes vote down vote up
public Double getMaxRowCount(RelSubset rel, RelMetadataQuery mq) {
  // FIXME This is a short-term fix for [CALCITE-1018]. A complete
  // solution will come with [CALCITE-1048].
  Util.discard(Bug.CALCITE_1048_FIXED);
  for (RelNode node : rel.getRels()) {
    if (node instanceof Sort) {
      Sort sort = (Sort) node;
      if (sort.fetch != null) {
        return (double) RexLiteral.intValue(sort.fetch);
      }
    }
  }

  return Double.POSITIVE_INFINITY;
}
 
Example 10
Source File: RelMdMinRowCount.java    From calcite with Apache License 2.0 5 votes vote down vote up
public Double getMinRowCount(RelSubset rel, RelMetadataQuery mq) {
  // FIXME This is a short-term fix for [CALCITE-1018]. A complete
  // solution will come with [CALCITE-1048].
  Util.discard(Bug.CALCITE_1048_FIXED);
  for (RelNode node : rel.getRels()) {
    if (node instanceof Sort) {
      Sort sort = (Sort) node;
      if (sort.fetch != null) {
        return (double) RexLiteral.intValue(sort.fetch);
      }
    }
  }

  return 0D;
}
 
Example 11
Source File: RelMdColumnUniqueness.java    From calcite with Apache License 2.0 5 votes vote down vote up
public Boolean areColumnsUnique(RelSubset rel, RelMetadataQuery mq,
    ImmutableBitSet columns, boolean ignoreNulls) {
  columns = decorateWithConstantColumnsFromPredicates(columns, rel, mq);
  int nullCount = 0;
  for (RelNode rel2 : rel.getRels()) {
    if (rel2 instanceof Aggregate
        || rel2 instanceof Filter
        || rel2 instanceof Values
        || rel2 instanceof Sort
        || rel2 instanceof TableScan
        || simplyProjects(rel2, columns)) {
      try {
        final Boolean unique = mq.areColumnsUnique(rel2, columns, ignoreNulls);
        if (unique != null) {
          if (unique) {
            return true;
          }
        } else {
          ++nullCount;
        }
      } catch (CyclicMetadataException e) {
        // Ignore this relational expression; there will be non-cyclic ones
        // in this set.
      }
    }
  }
  return nullCount == 0 ? false : null;
}