Java Code Examples for org.apache.calcite.rel.RelWriter#nest()

The following examples show how to use org.apache.calcite.rel.RelWriter#nest() . 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: Values.java    From Bats with Apache License 2.0 6 votes vote down vote up
public RelWriter explainTerms(RelWriter pw) {
  // A little adapter just to get the tuples to come out
  // with curly brackets instead of square brackets.  Plus
  // more whitespace for readability.
  RelWriter relWriter = super.explainTerms(pw)
      // For rel digest, include the row type since a rendered
      // literal may leave the type ambiguous (e.g. "null").
      .itemIf("type", rowType,
          pw.getDetailLevel() == SqlExplainLevel.DIGEST_ATTRIBUTES)
      .itemIf("type", rowType.getFieldList(), pw.nest());
  if (pw.nest()) {
    pw.item("tuples", tuples);
  } else {
    pw.item("tuples",
        tuples.stream()
            .map(row -> row.stream()
                .map(lit -> lit.computeDigest(RexDigestIncludeType.NO_TYPE))
                .collect(Collectors.joining(", ", "{ ", " }")))
            .collect(Collectors.joining(", ", "[", "]")));
  }
  return relWriter;
}
 
Example 2
Source File: Values.java    From calcite with Apache License 2.0 6 votes vote down vote up
public RelWriter explainTerms(RelWriter pw) {
  // A little adapter just to get the tuples to come out
  // with curly brackets instead of square brackets.  Plus
  // more whitespace for readability.
  RelWriter relWriter = super.explainTerms(pw)
      // For rel digest, include the row type since a rendered
      // literal may leave the type ambiguous (e.g. "null").
      .itemIf("type", rowType,
          pw.getDetailLevel() == SqlExplainLevel.DIGEST_ATTRIBUTES)
      .itemIf("type", rowType.getFieldList(), pw.nest());
  if (pw.nest()) {
    pw.item("tuples", tuples);
  } else {
    pw.item("tuples",
        tuples.stream()
            .map(row -> row.stream()
                .map(lit -> lit.computeDigest(RexDigestIncludeType.NO_TYPE))
                .collect(Collectors.joining(", ", "{ ", " }")))
            .collect(Collectors.joining(", ", "[", "]")));
  }
  return relWriter;
}
 
Example 3
Source File: Aggregate.java    From Bats with Apache License 2.0 5 votes vote down vote up
public RelWriter explainTerms(RelWriter pw) {
  // We skip the "groups" element if it is a singleton of "group".
  super.explainTerms(pw)
      .item("group", groupSet)
      .itemIf("groups", groupSets, getGroupType() != Group.SIMPLE)
      .itemIf("indicator", indicator, indicator)
      .itemIf("aggs", aggCalls, pw.nest());
  if (!pw.nest()) {
    for (Ord<AggregateCall> ord : Ord.zip(aggCalls)) {
      pw.item(Util.first(ord.e.name, "agg#" + ord.i), ord.e);
    }
  }
  return pw;
}
 
Example 4
Source File: Project.java    From Bats with Apache License 2.0 5 votes vote down vote up
public RelWriter explainTerms(RelWriter pw) {
  super.explainTerms(pw);
  if (pw.nest()) {
    pw.item("fields", rowType.getFieldNames());
    pw.item("exprs", exps);
  } else {
    for (Ord<RelDataTypeField> field : Ord.zip(rowType.getFieldList())) {
      String fieldName = field.e.getName();
      if (fieldName == null) {
        fieldName = "field#" + field.i;
      }
      pw.item(fieldName, exps.get(field.i));
    }
  }

  // If we're generating a digest, include the rowtype. If two projects
  // differ in return type, we don't want to regard them as equivalent,
  // otherwise we will try to put rels of different types into the same
  // planner equivalence set.
  //CHECKSTYLE: IGNORE 2
  if ((pw.getDetailLevel() == SqlExplainLevel.DIGEST_ATTRIBUTES)
      && false) {
    pw.item("type", rowType);
  }

  return pw;
}
 
Example 5
Source File: SingleMergeExchangePrel.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override
public RelWriter explainTerms(RelWriter pw) {
  super.explainTerms(pw);
  if (pw.nest()) {
    pw.item("collation", collation);
  } else {
    for (Ord<RelFieldCollation> ord : Ord.zip(collation.getFieldCollations())) {
      pw.item("sort" + ord.i, ord.e);
    }
  }
  return pw;
}
 
Example 6
Source File: SingleMergeExchangePrel.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public RelWriter explainTerms(RelWriter pw) {
  super.explainTerms(pw);
  if (pw.nest()) {
    pw.item("collation", collation);
  } else {
    for (Ord<RelFieldCollation> ord : Ord.zip(collation.getFieldCollations())) {
      pw.item("sort" + ord.i, ord.e);
    }
  }
  return pw;
}
 
Example 7
Source File: Aggregate.java    From calcite with Apache License 2.0 5 votes vote down vote up
public RelWriter explainTerms(RelWriter pw) {
  // We skip the "groups" element if it is a singleton of "group".
  super.explainTerms(pw)
      .item("group", groupSet)
      .itemIf("groups", groupSets, getGroupType() != Group.SIMPLE)
      .itemIf("aggs", aggCalls, pw.nest());
  if (!pw.nest()) {
    for (Ord<AggregateCall> ord : Ord.zip(aggCalls)) {
      pw.item(Util.first(ord.e.name, "agg#" + ord.i), ord.e);
    }
  }
  return pw;
}
 
Example 8
Source File: Project.java    From calcite with Apache License 2.0 5 votes vote down vote up
public RelWriter explainTerms(RelWriter pw) {
  super.explainTerms(pw);
  // Skip writing field names so the optimizer can reuse the projects that differ in
  // field names only
  if (pw.getDetailLevel() == SqlExplainLevel.DIGEST_ATTRIBUTES) {
    final int firstNonTrivial = countTrivial(exps);
    if (firstNonTrivial == 1) {
      pw.item("inputs", "0");
    } else if (firstNonTrivial != 0) {
      pw.item("inputs", "0.." + (firstNonTrivial - 1));
    }
    if (firstNonTrivial != exps.size()) {
      pw.item("exprs", exps.subList(firstNonTrivial, exps.size()));
    }
    return pw;
  }

  if (pw.nest()) {
    pw.item("fields", rowType.getFieldNames());
    pw.item("exprs", exps);
  } else {
    for (Ord<RelDataTypeField> field : Ord.zip(rowType.getFieldList())) {
      String fieldName = field.e.getName();
      if (fieldName == null) {
        fieldName = "field#" + field.i;
      }
      pw.item(fieldName, exps.get(field.i));
    }
  }

  return pw;
}