use of org.apache.calcite.rel.RelNode in project drill by apache.
the class SelectionVectorPrelVisitor method visitPrel.
@Override
public Prel visitPrel(Prel prel, Void value) throws RuntimeException {
SelectionVectorMode[] encodings = prel.getSupportedEncodings();
List<RelNode> children = Lists.newArrayList();
for (Prel child : prel) {
child = child.accept(this, null);
children.add(convert(encodings, child));
}
return (Prel) prel.copy(prel.getTraitSet(), children);
}
use of org.apache.calcite.rel.RelNode in project drill by apache.
the class StarColumnConverter method visitPrel.
@Override
public Prel visitPrel(Prel prel, Void value) throws RuntimeException {
// Require prefix rename : there exists other expression, in addition to a star column.
if (// not set yet.
!prefixedForStar && StarColumnHelper.containsStarColumn(prel.getRowType()) && prel.getRowType().getFieldNames().size() > 1) {
prefixedForStar = true;
}
List<RelNode> children = Lists.newArrayList();
for (Prel child : prel) {
child = child.accept(this, null);
children.add(child);
}
return (Prel) prel.copy(prel.getTraitSet(), children);
}
use of org.apache.calcite.rel.RelNode in project drill by apache.
the class StarColumnConverter method visitProject.
@Override
public Prel visitProject(ProjectPrel prel, Void value) throws RuntimeException {
ProjectPrel proj = (ProjectPrel) prel;
// Require prefix rename : there exists other expression, in addition to a star column.
if (// not set yet.
!prefixedForStar && StarColumnHelper.containsStarColumnInProject(prel.getInput().getRowType(), proj.getProjects()) && prel.getRowType().getFieldNames().size() > 1) {
prefixedForStar = true;
}
// For project, we need make sure that the project's field name is same as the input,
// when the project expression is RexInPutRef, since we may insert a PAS which will
// rename the projected fields.
RelNode child = ((Prel) prel.getInput(0)).accept(this, null);
List<String> fieldNames = Lists.newArrayList();
for (Pair<String, RexNode> pair : Pair.zip(prel.getRowType().getFieldNames(), proj.getProjects())) {
if (pair.right instanceof RexInputRef) {
String name = child.getRowType().getFieldNames().get(((RexInputRef) pair.right).getIndex());
fieldNames.add(name);
} else {
fieldNames.add(pair.left);
}
}
// Make sure the field names are unique : no allow of duplicate field names in a rowType.
fieldNames = makeUniqueNames(fieldNames);
RelDataType rowType = RexUtil.createStructType(prel.getCluster().getTypeFactory(), proj.getProjects(), fieldNames);
ProjectPrel newProj = (ProjectPrel) proj.copy(proj.getTraitSet(), child, proj.getProjects(), rowType);
if (ProjectRemoveRule.isTrivial(newProj)) {
return (Prel) child;
} else {
return newProj;
}
}
use of org.apache.calcite.rel.RelNode in project drill by apache.
the class NumberingRelWriter method explain_.
//~ Methods ----------------------------------------------------------------
protected void explain_(RelNode rel, List<Pair<String, Object>> values) {
List<RelNode> inputs = rel.getInputs();
if (rel instanceof HashJoinPrel && ((HashJoinPrel) rel).isSwapped()) {
HashJoinPrel joinPrel = (HashJoinPrel) rel;
inputs = FlatLists.of(joinPrel.getRight(), joinPrel.getLeft());
}
RelMetadataQuery mq = RelMetadataQuery.instance();
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 = ").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(inputs);
spacer.subtract(2);
}
use of org.apache.calcite.rel.RelNode in project drill by apache.
the class NumberingRelWriter method done.
public RelWriter done(RelNode node) {
int i = 0;
if (values.size() > 0 && values.get(0).left.equals("subset")) {
++i;
}
for (RelNode input : node.getInputs()) {
assert values.get(i).right == input;
++i;
}
for (RexNode expr : node.getChildExps()) {
assert values.get(i).right == expr;
++i;
}
final List<Pair<String, Object>> valuesCopy = ImmutableList.copyOf(values);
values.clear();
explain_(node, valuesCopy);
pw.flush();
return this;
}
Aggregations