use of org.apache.calcite.rel.metadata.RelMetadataQuery in project calcite by apache.
the class RelMetadataTest method checkPercentageOriginalRows.
private void checkPercentageOriginalRows(String sql, double expected, double epsilon) {
RelNode rel = convertSql(sql);
final RelMetadataQuery mq = RelMetadataQuery.instance();
Double result = mq.getPercentageOriginalRows(rel);
assertTrue(result != null);
assertEquals(expected, result, epsilon);
}
use of org.apache.calcite.rel.metadata.RelMetadataQuery in project calcite by apache.
the class RelMetadataTest method testExpressionLineageStar.
@Test
public void testExpressionLineageStar() {
// All columns in output
final RelNode tableRel = convertSql("select * from emp");
final RelMetadataQuery mq = RelMetadataQuery.instance();
final RexNode ref = RexInputRef.of(4, tableRel.getRowType().getFieldList());
final Set<RexNode> r = mq.getExpressionLineage(tableRel, ref);
final String inputRef = RexInputRef.of(4, tableRel.getRowType().getFieldList()).toString();
assertThat(r.size(), is(1));
final String resultString = r.iterator().next().toString();
assertThat(resultString, startsWith(EMP_QNAME.toString()));
assertThat(resultString, endsWith(inputRef));
}
use of org.apache.calcite.rel.metadata.RelMetadataQuery in project calcite by apache.
the class PlannerTest method checkMetadataPredicates.
/**
* Helper method for testing {@link RelMetadataQuery#getPulledUpPredicates}
* metadata.
*/
private void checkMetadataPredicates(String sql, String expectedPredicates) throws Exception {
Planner planner = getPlanner(null);
SqlNode parse = planner.parse(sql);
SqlNode validate = planner.validate(parse);
RelNode rel = planner.rel(validate).project();
final RelMetadataQuery mq = RelMetadataQuery.instance();
final RelOptPredicateList predicates = mq.getPulledUpPredicates(rel);
final String buf = predicates.pulledUpPredicates.toString();
assertThat(buf, equalTo(expectedPredicates));
}
use of org.apache.calcite.rel.metadata.RelMetadataQuery in project calcite by apache.
the class TraitPropagationTest method testOne.
@Test
public void testOne() throws Exception {
RelNode planned = run(new PropAction(), RULES);
if (CalcitePrepareImpl.DEBUG) {
System.out.println(RelOptUtil.dumpPlan("LOGICAL PLAN", planned, SqlExplainFormat.TEXT, SqlExplainLevel.ALL_ATTRIBUTES));
}
final RelMetadataQuery mq = RelMetadataQuery.instance();
assertEquals("Sortedness was not propagated", 3, mq.getCumulativeCost(planned).getRows(), 0);
}
use of org.apache.calcite.rel.metadata.RelMetadataQuery in project drill by axbaretto.
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);
}
Aggregations