Java Code Examples for org.apache.calcite.rel.metadata.RelMetadataQuery#instance()

The following examples show how to use org.apache.calcite.rel.metadata.RelMetadataQuery#instance() . 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: Join.java    From Bats with Apache License 2.0 5 votes vote down vote up
/** @deprecated Use {@link RelMdUtil#getJoinRowCount(RelMetadataQuery, Join, RexNode)}. */
@Deprecated // to be removed before 2.0
public static double estimateJoinedRows(
    Join joinRel,
    RexNode condition) {
  final RelMetadataQuery mq = RelMetadataQuery.instance();
  return Util.first(RelMdUtil.getJoinRowCount(mq, joinRel, condition), 1D);
}
 
Example 2
Source File: RelOptCluster.java    From Bats with Apache License 2.0 5 votes vote down vote up
/** Returns the current RelMetadataQuery.
 *
 * <p>This method might be changed or moved in future.
 * If you have a {@link RelOptRuleCall} available,
 * for example if you are in a {@link RelOptRule#onMatch(RelOptRuleCall)}
 * method, then use {@link RelOptRuleCall#getMetadataQuery()} instead. */
public RelMetadataQuery getMetadataQuery() {
  if (mq == null) {
    mq = RelMetadataQuery.instance();
  }
  return mq;
}
 
Example 3
Source File: RelOptCluster.java    From flink with Apache License 2.0 5 votes vote down vote up
/** Returns the current RelMetadataQuery.
 *
 * <p>This method might be changed or moved in future.
 * If you have a {@link RelOptRuleCall} available,
 * for example if you are in a {@link RelOptRule#onMatch(RelOptRuleCall)}
 * method, then use {@link RelOptRuleCall#getMetadataQuery()} instead. */
public RelMetadataQuery getMetadataQuery() {
	if (mq == null) {
		mq = RelMetadataQuery.instance();
	}
	return mq;
}
 
Example 4
Source File: RelOptCluster.java    From flink with Apache License 2.0 5 votes vote down vote up
/** Returns the current RelMetadataQuery.
 *
 * <p>This method might be changed or moved in future.
 * If you have a {@link RelOptRuleCall} available,
 * for example if you are in a {@link RelOptRule#onMatch(RelOptRuleCall)}
 * method, then use {@link RelOptRuleCall#getMetadataQuery()} instead. */
public RelMetadataQuery getMetadataQuery() {
	if (mq == null) {
		mq = RelMetadataQuery.instance();
	}
	return mq;
}
 
Example 5
Source File: AbstractRelNode.java    From Bats with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
public boolean isDistinct() {
  final RelMetadataQuery mq = RelMetadataQuery.instance();
  return Boolean.TRUE.equals(mq.areRowsUnique(this));
}
 
Example 6
Source File: AbstractRelNode.java    From Bats with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
public boolean isKey(ImmutableBitSet columns) {
  final RelMetadataQuery mq = RelMetadataQuery.instance();
  return Boolean.TRUE.equals(mq.areColumnsUnique(this, columns));
}
 
Example 7
Source File: Filter.java    From Bats with Apache License 2.0 4 votes vote down vote up
@Deprecated // to be removed before 2.0
public static double estimateFilteredRows(RelNode child, RexProgram program) {
  final RelMetadataQuery mq = RelMetadataQuery.instance();
  return RelMdUtil.estimateFilteredRows(child, program, mq);
}
 
Example 8
Source File: Filter.java    From Bats with Apache License 2.0 4 votes vote down vote up
@Deprecated // to be removed before 2.0
public static double estimateFilteredRows(RelNode child, RexNode condition) {
  final RelMetadataQuery mq = RelMetadataQuery.instance();
  return RelMdUtil.estimateFilteredRows(child, condition, mq);
}
 
Example 9
Source File: Union.java    From Bats with Apache License 2.0 4 votes vote down vote up
@Deprecated // to be removed before 2.0
public static double estimateRowCount(RelNode rel) {
  final RelMetadataQuery mq = RelMetadataQuery.instance();
  return RelMdUtil.getUnionAllRowCount(mq, (Union) rel);
}
 
Example 10
Source File: AbstractRelOptPlanner.java    From Bats with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
public RelOptCost getCost(RelNode rel) {
  final RelMetadataQuery mq = RelMetadataQuery.instance();
  return getCost(rel, mq);
}
 
Example 11
Source File: NumberingRelWriter.java    From Bats with Apache License 2.0 4 votes vote down vote up
protected void explain_(
    RelNode rel,
    List<Pair<String, Object>> values) {
  RelMetadataQuery mq = RelMetadataQuery.instance();
  if (!mq.isVisibleInExplain(rel, detailLevel)) {
    // render children in place of this, at same level
    explainInputs(rel);
    return;
  }

  StringBuilder s = new StringBuilder();
  OpId id = ids.get(rel);
  if (id != null) {
    s.append(String.format("%02d-%02d", id.fragmentId, id.opId));
  }else{
    s.append("     ");
  }
  s.append("  ");

  if (id != null && id.opId == 0) {
    for (int i = 0; i < spacer.get(); i++) {
      s.append('-');
    }
  }else{
    spacer.spaces(s);
  }

  s.append("  ");

  s.append(rel.getRelTypeName().replace("Prel", ""));
  if (detailLevel != SqlExplainLevel.NO_ATTRIBUTES) {
    int j = 0;
    s.append(getDependentSrcOp(rel));
    for (Pair<String, Object> value : values) {
      if (value.right instanceof RelNode) {
        continue;
      }
      if (j++ == 0) {
        s.append("(");
      } else {
        s.append(", ");
      }
      s.append(value.left)
          .append("=[")
          .append(value.right)
          .append("]");
    }
    if (j > 0) {
      s.append(")");
    }
  }
  if (detailLevel == SqlExplainLevel.ALL_ATTRIBUTES) {
    s.append(" : rowType = ")
      .append(rel.getRowType())
      .append(": rowcount = ")
      .append(mq.getRowCount(rel))
      .append(", cumulative cost = ")
      .append(mq.getCumulativeCost(rel))
      .append(", id = ")
      .append(rel.getId());
  }
  pw.println(s);
  spacer.add(2);
  explainInputs(rel);
  spacer.subtract(2);
}
 
Example 12
Source File: MemoryEstimationVisitor.java    From Bats with Apache License 2.0 4 votes vote down vote up
@Override
  public Double visitPrel(Prel prel, Void value) throws RuntimeException {
    RelMetadataQuery mq = RelMetadataQuery.instance();
    return ((DrillCostBase) mq.getCumulativeCost(prel)).getMemory();
//    return findCost(prel, mq);
  }