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

The following examples show how to use org.apache.calcite.rel.metadata.RelMetadataQuery#isVisibleInExplain() . 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: RelWriterImpl.java    From Bats with Apache License 2.0 4 votes vote down vote up
protected void explain_(RelNode rel,
    List<Pair<String, Object>> values) {
  List<RelNode> inputs = rel.getInputs();
  final RelMetadataQuery mq = rel.getCluster().getMetadataQuery();
  if (!mq.isVisibleInExplain(rel, detailLevel)) {
    // render children in place of this, at same level
    explainInputs(inputs);
    return;
  }

  StringBuilder s = new StringBuilder();
  spacer.spaces(s);
  if (withIdPrefix) {
    s.append(rel.getId()).append(":");
  }
  s.append(rel.getRelTypeName());
  if (detailLevel != SqlExplainLevel.NO_ATTRIBUTES) {
    int j = 0;
    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(")");
    }
  }
  switch (detailLevel) {
  case ALL_ATTRIBUTES:
    s.append(": rowcount = ")
        .append(mq.getRowCount(rel))
        .append(", cumulative cost = ")
        .append(mq.getCumulativeCost(rel));
  }
  switch (detailLevel) {
  case NON_COST_ATTRIBUTES:
  case ALL_ATTRIBUTES:
    if (!withIdPrefix) {
      // If we didn't print the rel id at the start of the line, print
      // it at the end.
      s.append(", id = ").append(rel.getId());
    }
    break;
  }
  pw.println(s);
  spacer.add(2);
  explainInputs(inputs);
  spacer.subtract(2);
}
 
Example 2
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 3
Source File: NumberingRelWriter.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
protected void explain_(
    RelNode rel,
    List<Pair<String, Object>> values) {
  List<RelNode> inputs = rel.getInputs();
  RelMetadataQuery mq = rel.getCluster().getMetadataQuery();
  if (rel instanceof HashJoinPrel && ((HashJoinPrel) rel).isSwapped()) {
    HashJoinPrel joinPrel = (HashJoinPrel) rel;
    inputs = FlatLists.of(joinPrel.getRight(), joinPrel.getLeft());
  }

  if (!mq.isVisibleInExplain(rel, detailLevel)) {
    // render children in place of this, at same level
    explainInputs(inputs);
    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;
    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 = " + rel.getRowType().toString());
    s.append(": rowcount = ")
        .append(mq.getRowCount(rel))
        .append(", cumulative cost = ")
        .append(mq.getCumulativeCost(rel));
     s.append(", id = ").append(rel.getId());
  }
  pw.println(s);
  spacer.add(2);
  explainInputs(inputs);
  spacer.subtract(2);
}
 
Example 4
Source File: RelWriterImpl.java    From calcite with Apache License 2.0 4 votes vote down vote up
protected void explain_(RelNode rel,
    List<Pair<String, Object>> values) {
  List<RelNode> inputs = rel.getInputs();
  final RelMetadataQuery mq = rel.getCluster().getMetadataQuery();
  if (!mq.isVisibleInExplain(rel, detailLevel)) {
    // render children in place of this, at same level
    explainInputs(inputs);
    return;
  }

  StringBuilder s = new StringBuilder();
  spacer.spaces(s);
  if (withIdPrefix) {
    s.append(rel.getId()).append(":");
  }
  s.append(rel.getRelTypeName());
  if (detailLevel != SqlExplainLevel.NO_ATTRIBUTES) {
    int j = 0;
    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(")");
    }
  }
  switch (detailLevel) {
  case ALL_ATTRIBUTES:
    s.append(": rowcount = ")
        .append(mq.getRowCount(rel))
        .append(", cumulative cost = ")
        .append(mq.getCumulativeCost(rel));
  }
  switch (detailLevel) {
  case NON_COST_ATTRIBUTES:
  case ALL_ATTRIBUTES:
    if (!withIdPrefix) {
      // If we didn't print the rel id at the start of the line, print
      // it at the end.
      s.append(", id = ").append(rel.getId());
    }
    break;
  }
  pw.println(s);
  spacer.add(2);
  explainInputs(inputs);
  spacer.subtract(2);
}