org.apache.calcite.plan.hep.HepRelVertex Java Examples

The following examples show how to use org.apache.calcite.plan.hep.HepRelVertex. 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: PruneEmptyRules.java    From calcite with Apache License 2.0 6 votes vote down vote up
private static boolean isEmpty(RelNode node) {
  if (node instanceof Values) {
    return ((Values) node).getTuples().isEmpty();
  }
  if (node instanceof HepRelVertex) {
    return isEmpty(((HepRelVertex) node).getCurrentRel());
  }
  // Note: relation input might be a RelSubset, so we just iterate over the relations
  // in order to check if the subset is equivalent to an empty relation.
  if (!(node instanceof RelSubset)) {
    return false;
  }
  RelSubset subset = (RelSubset) node;
  for (RelNode rel : subset.getRels()) {
    if (isEmpty(rel)) {
      return true;
    }
  }
  return false;
}
 
Example #2
Source File: PythonCorrelateSplitRule.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public boolean matches(RelOptRuleCall call) {
	FlinkLogicalCorrelate correlate = call.rel(0);
	RelNode right = ((HepRelVertex) correlate.getRight()).getCurrentRel();
	FlinkLogicalTableFunctionScan tableFunctionScan;
	if (right instanceof FlinkLogicalTableFunctionScan) {
		tableFunctionScan = (FlinkLogicalTableFunctionScan) right;
	} else if (right instanceof FlinkLogicalCalc) {
		tableFunctionScan = StreamExecCorrelateRule.getTableScan((FlinkLogicalCalc) right);
	} else {
		return false;
	}
	RexNode rexNode = tableFunctionScan.getCall();
	if (rexNode instanceof RexCall) {
		return PythonUtil.isPythonCall(rexNode, null) && PythonUtil.containsNonPythonCall(rexNode)
			|| PythonUtil.isNonPythonCall(rexNode) && PythonUtil.containsPythonCall(rexNode, null)
			|| (PythonUtil.isPythonCall(rexNode, null) && RexUtil.containsFieldAccess(rexNode));
	}
	return false;
}
 
Example #3
Source File: FlinkAggregateJoinTransposeRule.java    From flink with Apache License 2.0 6 votes vote down vote up
private boolean containsSnapshot(RelNode relNode) {
	RelNode original = null;
	if (relNode instanceof RelSubset) {
		original = ((RelSubset) relNode).getOriginal();
	} else if (relNode instanceof HepRelVertex) {
		original = ((HepRelVertex) relNode).getCurrentRel();
	} else {
		original = relNode;
	}
	if (original instanceof LogicalSnapshot) {
		return true;
	} else if (original instanceof SingleRel) {
		return containsSnapshot(((SingleRel) original).getInput());
	} else {
		return false;
	}
}
 
Example #4
Source File: PythonCorrelateSplitRule.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public boolean matches(RelOptRuleCall call) {
	FlinkLogicalCorrelate correlate = call.rel(0);
	RelNode right = ((HepRelVertex) correlate.getRight()).getCurrentRel();
	FlinkLogicalTableFunctionScan tableFuncScan;
	if (right instanceof FlinkLogicalTableFunctionScan) {
		tableFuncScan = (FlinkLogicalTableFunctionScan) right;
	} else if (right instanceof FlinkLogicalCalc) {
		Option<FlinkLogicalTableFunctionScan> scan = CorrelateUtil
			.getTableFunctionScan((FlinkLogicalCalc) right);
		if (scan.isEmpty()) {
			return false;
		}
		tableFuncScan = scan.get();
	} else {
		return false;
	}
	RexNode rexNode = tableFuncScan.getCall();
	if (rexNode instanceof RexCall) {
		return PythonUtil.isPythonCall(rexNode, null) && PythonUtil.containsNonPythonCall(rexNode)
			|| PythonUtil.isNonPythonCall(rexNode) && PythonUtil.containsPythonCall(rexNode, null)
			|| (PythonUtil.isPythonCall(rexNode, null) && RexUtil.containsFieldAccess(rexNode));
	}
	return false;
}
 
Example #5
Source File: FlinkAggregateJoinTransposeRule.java    From flink with Apache License 2.0 6 votes vote down vote up
private boolean containsSnapshot(RelNode relNode) {
	RelNode original = null;
	if (relNode instanceof RelSubset) {
		original = ((RelSubset) relNode).getOriginal();
	} else if (relNode instanceof HepRelVertex) {
		original = ((HepRelVertex) relNode).getCurrentRel();
	} else {
		original = relNode;
	}
	if (original instanceof LogicalSnapshot) {
		return true;
	} else if (original instanceof SingleRel) {
		return containsSnapshot(((SingleRel) original).getInput());
	} else {
		return false;
	}
}
 
Example #6
Source File: DrillPushRowKeyJoinToScanRule.java    From Bats with Apache License 2.0 6 votes vote down vote up
private static boolean canSwapJoinInputsInternal(RelNode rel) {
  if (rel instanceof DrillAggregateRel &&
      ((DrillAggregateRel) rel).getAggCallList().size() > 0) {
    return false;
  } else if (rel instanceof HepRelVertex) {
    return canSwapJoinInputsInternal(((HepRelVertex) rel).getCurrentRel());
  } else if (rel instanceof RelSubset) {
    if (((RelSubset) rel).getBest() != null) {
      return canSwapJoinInputsInternal(((RelSubset) rel).getBest());
    } else {
      return canSwapJoinInputsInternal(((RelSubset) rel).getOriginal());
    }
  } else {
    for (RelNode child : rel.getInputs()) {
      if (!canSwapJoinInputsInternal(child)) {
        return false;
      }
    }
  }
  return true;
}
 
Example #7
Source File: DrillPushRowKeyJoinToScanRule.java    From Bats with Apache License 2.0 6 votes vote down vote up
public static RelNode getValidJoinInput(RelNode rel) {
  if (rel instanceof DrillScanRel) {
    return rel;
  } else if (rel instanceof DrillProjectRel
      || rel instanceof DrillFilterRel
      || rel instanceof DrillLimitRel) {
    for (RelNode child : rel.getInputs()) {
      RelNode tgt = getValidJoinInput(child);
      if (tgt != null) {
        return tgt;
      }
    }
  } else if (rel instanceof HepRelVertex) {
    return getValidJoinInput(((HepRelVertex) rel).getCurrentRel());
  } else if (rel instanceof RelSubset) {
    if (((RelSubset) rel).getBest() != null) {
      return getValidJoinInput(((RelSubset) rel).getBest());
    } else {
      return getValidJoinInput(((RelSubset) rel).getOriginal());
    }
  }
  return null;
}
 
Example #8
Source File: SubQueryDecorrelator.java    From flink with Apache License 2.0 5 votes vote down vote up
private static RelNode stripHep(RelNode rel) {
	if (rel instanceof HepRelVertex) {
		HepRelVertex hepRelVertex = (HepRelVertex) rel;
		rel = hepRelVertex.getCurrentRel();
	}
	return rel;
}
 
Example #9
Source File: RelDecorrelator.java    From calcite with Apache License 2.0 5 votes vote down vote up
private static RelNode stripHep(RelNode rel) {
  if (rel instanceof HepRelVertex) {
    HepRelVertex hepRelVertex = (HepRelVertex) rel;
    rel = hepRelVertex.getCurrentRel();
  }
  return rel;
}
 
Example #10
Source File: ProjectCorrelateTransposeRule.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override protected RelNode visitChild(RelNode parent, int i, RelNode child) {
  if (child instanceof HepRelVertex) {
    child = ((HepRelVertex) child).getCurrentRel();
  } else if (child instanceof RelSubset) {
    RelSubset subset = (RelSubset) child;
    child = Util.first(subset.getBest(), subset.getOriginal());
  }
  return super.visitChild(parent, i, child).accept(rexVisitor);
}
 
Example #11
Source File: SubQueryDecorrelator.java    From flink with Apache License 2.0 5 votes vote down vote up
private static RelNode stripHep(RelNode rel) {
	if (rel instanceof HepRelVertex) {
		HepRelVertex hepRelVertex = (HepRelVertex) rel;
		rel = hepRelVertex.getCurrentRel();
	}
	return rel;
}
 
Example #12
Source File: MoreRelOptUtil.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public RelNode visit(RelNode other) {
  if (other instanceof HepRelVertex) {
    return super.visit(((HepRelVertex) other).getCurrentRel());
  } else {
    return super.visit(other);
  }
}
 
Example #13
Source File: RelDecorrelator.java    From flink with Apache License 2.0 5 votes vote down vote up
private static RelNode stripHep(RelNode rel) {
  if (rel instanceof HepRelVertex) {
    HepRelVertex hepRelVertex = (HepRelVertex) rel;
    rel = hepRelVertex.getCurrentRel();
  }
  return rel;
}
 
Example #14
Source File: RelDecorrelator.java    From flink with Apache License 2.0 5 votes vote down vote up
private static RelNode stripHep(RelNode rel) {
  if (rel instanceof HepRelVertex) {
    HepRelVertex hepRelVertex = (HepRelVertex) rel;
    rel = hepRelVertex.getCurrentRel();
  }
  return rel;
}
 
Example #15
Source File: DrillRelOptUtil.java    From Bats with Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether statistics-based estimates or guesses are used by the optimizer
 * for the {@link RelNode} rel.
 * @param rel : input
 * @return TRUE if the estimate is a guess, FALSE otherwise
 * */
public static boolean guessRows(RelNode rel) {
    final PlannerSettings settings = rel.getCluster().getPlanner().getContext().unwrap(PlannerSettings.class);
    if (!settings.useStatistics()) {
        return true;
    }
    /* We encounter RelSubset/HepRelVertex which are CALCITE constructs, hence we
     * cannot add guessRows() to the DrillRelNode interface.
     */
    if (rel instanceof RelSubset) {
        if (((RelSubset) rel).getBest() != null) {
            return guessRows(((RelSubset) rel).getBest());
        } else if (((RelSubset) rel).getOriginal() != null) {
            return guessRows(((RelSubset) rel).getOriginal());
        }
    } else if (rel instanceof HepRelVertex) {
        if (((HepRelVertex) rel).getCurrentRel() != null) {
            return guessRows(((HepRelVertex) rel).getCurrentRel());
        }
    } else if (rel instanceof TableScan) {
        DrillTable table = Utilities.getDrillTable(rel.getTable());
        try {
            TableMetadata tableMetadata;
            return table == null || (tableMetadata = table.getGroupScan().getTableMetadata()) == null
                    || !((Boolean) TableStatisticsKind.HAS_STATISTICS.getValue(tableMetadata));
        } catch (IOException e) {
            RelOptPlanner.LOGGER.debug("Unable to obtain table metadata due to exception:", e);
            return true;
        }
    } else {
        for (RelNode child : rel.getInputs()) {
            if (guessRows(child)) { // at least one child is a guess
                return true;
            }
        }
    }
    return false;
}
 
Example #16
Source File: RelDecorrelator.java    From Bats with Apache License 2.0 5 votes vote down vote up
private static RelNode stripHep(RelNode rel) {
    if (rel instanceof HepRelVertex) {
        HepRelVertex hepRelVertex = (HepRelVertex) rel;
        rel = hepRelVertex.getCurrentRel();
    }
    return rel;
}
 
Example #17
Source File: ProjectCorrelateTransposeRule.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override
protected RelNode visitChild(RelNode parent, int i, RelNode child) {
    if (child instanceof HepRelVertex) {
        child = ((HepRelVertex) child).getCurrentRel();
    } else if (child instanceof RelSubset) {
        RelSubset subset = (RelSubset) child;
        child = Util.first(subset.getBest(), subset.getOriginal());
    }
    return super.visitChild(parent, i, child).accept(rexVisitor);
}
 
Example #18
Source File: LimitExchangeTransposeRule.java    From Bats with Apache License 2.0 5 votes vote down vote up
private boolean findRowKeyJoin(RelNode rel) {
  if (rel instanceof RowKeyJoinPrel) {
    return true;
  }
  if (rel instanceof RelSubset) {
    if (((RelSubset) rel).getBest() != null) {
      if (findRowKeyJoin(((RelSubset) rel).getBest())) {
        return true;
      }
    } else if (((RelSubset) rel).getOriginal() != null) {
      if (findRowKeyJoin(((RelSubset) rel).getOriginal())) {
        return true;
      }
    }
  } else if (rel instanceof HepRelVertex) {
    if (((HepRelVertex) rel).getCurrentRel() != null) {
      if (findRowKeyJoin(((HepRelVertex) rel).getCurrentRel())) {
        return true;
      }
    }
  } else {
    for (RelNode child : rel.getInputs()) {
      if (findRowKeyJoin(child)) {
        return true;
      }
    }
  }
  return false;
}
 
Example #19
Source File: RelMdCollation.java    From Bats with Apache License 2.0 4 votes vote down vote up
public ImmutableList<RelCollation> collations(HepRelVertex rel,
    RelMetadataQuery mq) {
  return mq.collations(rel.getCurrentRel());
}
 
Example #20
Source File: RelMdNodeTypes.java    From Bats with Apache License 2.0 4 votes vote down vote up
public Multimap<Class<? extends RelNode>, RelNode> getNodeTypes(HepRelVertex rel,
    RelMetadataQuery mq) {
  return mq.getNodeTypes(rel.getCurrentRel());
}
 
Example #21
Source File: RelMdExpressionLineage.java    From Bats with Apache License 2.0 4 votes vote down vote up
public Set<RexNode> getExpressionLineage(HepRelVertex rel, RelMetadataQuery mq,
    RexNode outputExpression) {
  return mq.getExpressionLineage(rel.getCurrentRel(), outputExpression);
}
 
Example #22
Source File: RelMdDistribution.java    From Bats with Apache License 2.0 4 votes vote down vote up
public RelDistribution distribution(HepRelVertex rel, RelMetadataQuery mq) {
  return mq.distribution(rel.getCurrentRel());
}
 
Example #23
Source File: RelMdPredicates.java    From calcite with Apache License 2.0 4 votes vote down vote up
public RelOptPredicateList getPredicates(HepRelVertex rel,
    RelMetadataQuery mq) {
  return mq.getPulledUpPredicates(rel.getCurrentRel());
}
 
Example #24
Source File: RelMdAllPredicates.java    From calcite with Apache License 2.0 4 votes vote down vote up
public RelOptPredicateList getAllPredicates(HepRelVertex rel, RelMetadataQuery mq) {
  return mq.getAllPredicates(rel.getCurrentRel());
}
 
Example #25
Source File: RelMdColumnUniqueness.java    From calcite with Apache License 2.0 4 votes vote down vote up
public Boolean areColumnsUnique(HepRelVertex rel, RelMetadataQuery mq,
    ImmutableBitSet columns, boolean ignoreNulls) {
  columns = decorateWithConstantColumnsFromPredicates(columns, rel, mq);
  return mq.areColumnsUnique(rel.getCurrentRel(), columns, ignoreNulls);
}
 
Example #26
Source File: RelMdCollation.java    From calcite with Apache License 2.0 4 votes vote down vote up
public ImmutableList<RelCollation> collations(HepRelVertex rel,
    RelMetadataQuery mq) {
  return mq.collations(rel.getCurrentRel());
}
 
Example #27
Source File: RelMdDistribution.java    From calcite with Apache License 2.0 4 votes vote down vote up
public RelDistribution distribution(HepRelVertex rel, RelMetadataQuery mq) {
  return mq.distribution(rel.getCurrentRel());
}
 
Example #28
Source File: RelMdExpressionLineage.java    From calcite with Apache License 2.0 4 votes vote down vote up
public Set<RexNode> getExpressionLineage(HepRelVertex rel, RelMetadataQuery mq,
    RexNode outputExpression) {
  return mq.getExpressionLineage(rel.getCurrentRel(), outputExpression);
}
 
Example #29
Source File: RelMdNodeTypes.java    From calcite with Apache License 2.0 4 votes vote down vote up
public Multimap<Class<? extends RelNode>, RelNode> getNodeTypes(HepRelVertex rel,
    RelMetadataQuery mq) {
  return mq.getNodeTypes(rel.getCurrentRel());
}
 
Example #30
Source File: RelMdTableReferences.java    From calcite with Apache License 2.0 4 votes vote down vote up
public Set<RelTableRef> getTableReferences(HepRelVertex rel, RelMetadataQuery mq) {
  return mq.getTableReferences(rel.getCurrentRel());
}