Java Code Examples for org.apache.calcite.sql.SqlExplainLevel#ALL_ATTRIBUTES

The following examples show how to use org.apache.calcite.sql.SqlExplainLevel#ALL_ATTRIBUTES . 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: RelJsonWriter.java    From Bats with Apache License 2.0 4 votes vote down vote up
public SqlExplainLevel getDetailLevel() {
  return SqlExplainLevel.ALL_ATTRIBUTES;
}
 
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: ExplainHandler.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Override
  public List<Explain> toResult(String sql, SqlNode sqlNode) throws Exception {
    try {
      final SqlExplain node = SqlNodeUtil.unwrap(sqlNode, SqlExplain.class);
      final SqlLiteral op = node.operand(2);
      final SqlExplain.Depth depth = (SqlExplain.Depth) op.getValue();

      final ResultMode mode;
      SqlExplainLevel level = SqlExplainLevel.ALL_ATTRIBUTES;

      if (node.getDetailLevel() != null) {
        level = node.getDetailLevel();
      }

      switch (depth) {
      case LOGICAL:
        mode = ResultMode.LOGICAL;
        break;
      case PHYSICAL:
        mode = ResultMode.PHYSICAL;
        break;
      default:
        throw new UnsupportedOperationException("Unknown depth " + depth);
      }

      final SqlNode innerNode = node.operand(0);

//      try(DisabledBlock block = toggle.openDisabledBlock()){
        Rel drel;
        final ConvertedRelNode convertedRelNode = PrelTransformer.validateAndConvert(config, innerNode);
        final RelDataType validatedRowType = convertedRelNode.getValidatedRowType();
        final RelNode queryRelNode = convertedRelNode.getConvertedNode();

        PrelTransformer.log("Calcite", queryRelNode, logger, null);
        drel = PrelTransformer.convertToDrel(config, queryRelNode, validatedRowType);

        if (mode == ResultMode.LOGICAL) {
          return Collections.singletonList(new Explain(RelOptUtil.toString(drel, level)));
        }

        final Pair<Prel, String> convertToPrel = PrelTransformer.convertToPrel(config, drel);
        final String text = convertToPrel.getValue();
        return Collections.singletonList(new Explain(text));
//      }
    } catch (Exception ex){
      throw SqlExceptionHelper.coerceException(logger, sql, ex, true);
    }
  }
 
Example 5
Source File: RelJsonWriter.java    From calcite with Apache License 2.0 4 votes vote down vote up
public SqlExplainLevel getDetailLevel() {
  return SqlExplainLevel.ALL_ATTRIBUTES;
}