use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator in project asterixdb by apache.
the class RemoveUnusedOneToOneEquiJoinRule method gatherProducingDataScans.
private void gatherProducingDataScans(Mutable<ILogicalOperator> opRef, List<LogicalVariable> joinUsedVars, List<DataSourceScanOperator> dataScans) {
AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
if (op.getOperatorTag() != LogicalOperatorTag.DATASOURCESCAN) {
for (Mutable<ILogicalOperator> inputOp : op.getInputs()) {
gatherProducingDataScans(inputOp, joinUsedVars, dataScans);
}
return;
}
DataSourceScanOperator dataScan = (DataSourceScanOperator) op;
fillPKVars(dataScan, pkVars);
// Check if join uses all PK vars.
if (joinUsedVars.containsAll(pkVars)) {
dataScans.add(dataScan);
}
}
use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator in project asterixdb by apache.
the class RemoveLeftOuterUnnestForLeftOuterJoinRule method rewritePre.
@Override
public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
ILogicalOperator op1 = opRef.getValue();
// Checks the plan pattern.
if (!checkOperatorPattern(op1)) {
return false;
}
LeftOuterUnnestOperator outerUnnest = (LeftOuterUnnestOperator) op1;
GroupByOperator gbyOperator = (GroupByOperator) outerUnnest.getInputs().get(0).getValue();
LeftOuterJoinOperator lojOperator = (LeftOuterJoinOperator) gbyOperator.getInputs().get(0).getValue();
// Checks whether the left outer unnest and the group-by operator are qualified for rewriting.
Triple<Boolean, ILogicalExpression, ILogicalExpression> checkGbyResult = checkUnnestAndGby(outerUnnest, gbyOperator);
// The argument for listify and not(is-missing(...)) check should be variables.
if (!isVariableReference(checkGbyResult.second) || !isVariableReference(checkGbyResult.third)) {
return false;
}
// Checks whether both the listify variable and the condition test variable are from the right input
// branch of the left outer join.
LogicalVariable listifyVar = ((VariableReferenceExpression) checkGbyResult.second).getVariableReference();
LogicalVariable conditionTestVar = ((VariableReferenceExpression) checkGbyResult.third).getVariableReference();
if (!checkListifyAndConditionVar(lojOperator, listifyVar, conditionTestVar)) {
return false;
}
// Does the rewrite.
removeGroupByAndOuterUnnest(opRef, context, outerUnnest, gbyOperator, lojOperator, listifyVar);
return true;
}
use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator in project asterixdb by apache.
the class RemoveLeftOuterUnnestForLeftOuterJoinRule method checkNestedPlan.
// Checks the nested plan for the group-by operator.
private Pair<Boolean, ILogicalOperator> checkNestedPlan(GroupByOperator gbyOperator) {
List<ILogicalPlan> nestedPlans = gbyOperator.getNestedPlans();
if (nestedPlans.size() > 1) {
return new Pair<>(false, null);
}
ILogicalPlan plan = nestedPlans.get(0);
List<Mutable<ILogicalOperator>> roots = plan.getRoots();
if (roots.size() > 1) {
return new Pair<>(false, null);
}
ILogicalOperator root = roots.get(0).getValue();
return new Pair<>(true, root);
}
use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator in project asterixdb by apache.
the class RemoveLeftOuterUnnestForLeftOuterJoinRule method checkGroupBy.
// Checks the group-by operator on top of the left outer join operator.
private Triple<Boolean, ILogicalExpression, ILogicalExpression> checkGroupBy(GroupByOperator gbyOperator, LogicalVariable varToUnnest) {
Pair<Boolean, ILogicalOperator> checkNestedPlanResult = checkNestedPlan(gbyOperator);
if (!checkNestedPlanResult.first) {
return new Triple<>(false, null, null);
}
ILogicalOperator root = checkNestedPlanResult.second;
if (root.getOperatorTag() != LogicalOperatorTag.AGGREGATE) {
return new Triple<>(false, null, null);
}
// Checks aggregate.
AggregateOperator agg = (AggregateOperator) root;
Pair<Boolean, ILogicalExpression> listifyArgPair = checksAggregate(agg, varToUnnest);
if (!listifyArgPair.first) {
return new Triple<>(false, null, null);
}
// Checks select.
ILogicalOperator rootInputOp = root.getInputs().get(0).getValue();
if (rootInputOp.getOperatorTag() != LogicalOperatorTag.SELECT) {
return new Triple<>(false, null, null);
}
SelectOperator select = (SelectOperator) rootInputOp;
Pair<Boolean, ILogicalExpression> conditionArgPair = checkSelect(select);
return new Triple<>(true, listifyArgPair.second, conditionArgPair.second);
}
use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator in project asterixdb by apache.
the class AccessMethodUtils method retainInputs.
//Get Variables used by afterSelectRefs that were created before the datasource
//If there are any, we should retain inputs
public static boolean retainInputs(List<LogicalVariable> dataSourceVariables, ILogicalOperator sourceOp, List<Mutable<ILogicalOperator>> afterSelectRefs) throws AlgebricksException {
List<LogicalVariable> usedVars = new ArrayList<>();
List<LogicalVariable> producedVars = new ArrayList<>();
List<LogicalVariable> liveVars = new ArrayList<>();
VariableUtilities.getLiveVariables(sourceOp, liveVars);
for (Mutable<ILogicalOperator> opMutable : afterSelectRefs) {
ILogicalOperator op = opMutable.getValue();
VariableUtilities.getUsedVariables(op, usedVars);
VariableUtilities.getProducedVariables(op, producedVars);
}
usedVars.removeAll(producedVars);
usedVars.removeAll(dataSourceVariables);
usedVars.retainAll(liveVars);
return usedVars.isEmpty() ? false : true;
}
Aggregations