Search in sources :

Example 21 with NestedTupleSourceOperator

use of org.apache.hyracks.algebricks.core.algebra.operators.logical.NestedTupleSourceOperator in project asterixdb by apache.

the class IntroJoinInsideSubplanRule method rewritePost.

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    AbstractLogicalOperator op0 = (AbstractLogicalOperator) opRef.getValue();
    if (op0.getOperatorTag() != LogicalOperatorTag.SUBPLAN) {
        return false;
    }
    SubplanOperator subplan = (SubplanOperator) op0;
    Mutable<ILogicalOperator> leftRef = subplan.getInputs().get(0);
    if (((AbstractLogicalOperator) leftRef.getValue()).getOperatorTag() == LogicalOperatorTag.EMPTYTUPLESOURCE) {
        return false;
    }
    ListIterator<ILogicalPlan> plansIter = subplan.getNestedPlans().listIterator();
    ILogicalPlan p = null;
    while (plansIter.hasNext()) {
        p = plansIter.next();
    }
    if (p == null) {
        return false;
    }
    if (p.getRoots().size() != 1) {
        return false;
    }
    Mutable<ILogicalOperator> opRef1 = p.getRoots().get(0);
    while (true) {
        AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef1.getValue();
        if (op1.getInputs().size() != 1) {
            return false;
        }
        if (op1.getOperatorTag() == LogicalOperatorTag.SELECT) {
            Mutable<ILogicalOperator> op2Ref = op1.getInputs().get(0);
            AbstractLogicalOperator op2 = (AbstractLogicalOperator) op2Ref.getValue();
            if (op2.getOperatorTag() != LogicalOperatorTag.SELECT && descOrSelfIsScanOrJoin(op2)) {
                Set<LogicalVariable> free2 = new HashSet<LogicalVariable>();
                OperatorPropertiesUtil.getFreeVariablesInSelfOrDesc(op2, free2);
                if (free2.isEmpty()) {
                    Set<LogicalVariable> free1 = new HashSet<LogicalVariable>();
                    OperatorPropertiesUtil.getFreeVariablesInSelfOrDesc(op1, free1);
                    if (!free1.isEmpty()) {
                        OperatorManipulationUtil.ntsToEts(op2Ref, context);
                        NestedTupleSourceOperator nts = new NestedTupleSourceOperator(new MutableObject<ILogicalOperator>(subplan));
                        Mutable<ILogicalOperator> ntsRef = new MutableObject<ILogicalOperator>(nts);
                        Mutable<ILogicalOperator> innerRef = new MutableObject<ILogicalOperator>(op2);
                        InnerJoinOperator join = new InnerJoinOperator(new MutableObject<ILogicalExpression>(ConstantExpression.TRUE), ntsRef, innerRef);
                        op2Ref.setValue(join);
                        context.computeAndSetTypeEnvironmentForOperator(nts);
                        context.computeAndSetTypeEnvironmentForOperator(join);
                        return true;
                    }
                }
            }
        }
        opRef1 = op1.getInputs().get(0);
    }
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) NestedTupleSourceOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.NestedTupleSourceOperator) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) InnerJoinOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator) SubplanOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.SubplanOperator) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) ILogicalPlan(org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan) HashSet(java.util.HashSet) MutableObject(org.apache.commons.lang3.mutable.MutableObject)

Example 22 with NestedTupleSourceOperator

use of org.apache.hyracks.algebricks.core.algebra.operators.logical.NestedTupleSourceOperator in project asterixdb by apache.

the class NestedTupleSourcePOperator method computeDeliveredProperties.

@Override
public void computeDeliveredProperties(ILogicalOperator op, IOptimizationContext context) {
    Mutable<ILogicalOperator> dataSource = ((NestedTupleSourceOperator) op).getDataSourceReference();
    AbstractLogicalOperator op2 = (AbstractLogicalOperator) dataSource.getValue().getInputs().get(0).getValue();
    IPhysicalPropertiesVector inheritedProps = op2.getDeliveredPhysicalProperties();
    AbstractLogicalOperator parent = (AbstractLogicalOperator) dataSource.getValue();
    if (parent.getOperatorTag() != LogicalOperatorTag.GROUP) {
        deliveredProperties = inheritedProps.clone();
        return;
    }
    GroupByOperator gby = (GroupByOperator) parent;
    List<ILocalStructuralProperty> originalLocalProperties = inheritedProps.getLocalProperties();
    List<ILocalStructuralProperty> newLocalProperties = null;
    if (originalLocalProperties != null) {
        newLocalProperties = new ArrayList<>();
        for (ILocalStructuralProperty lsp : originalLocalProperties) {
            ILocalStructuralProperty groupLocalLsp = lsp.regardToGroup(gby.getGbyVarList());
            if (groupLocalLsp != null) {
                // Adds the property that is satisfied in the context of a particular group.
                newLocalProperties.add(groupLocalLsp);
            }
        }
        // Adds the original local properties as they are still maintained.
        // The optimizer should be able to process multiple delivered local order/grouping properties.
        newLocalProperties.addAll(originalLocalProperties);
    }
    deliveredProperties = new StructuralPropertiesVector(inheritedProps.getPartitioningProperty(), newLocalProperties);
}
Also used : StructuralPropertiesVector(org.apache.hyracks.algebricks.core.algebra.properties.StructuralPropertiesVector) NestedTupleSourceOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.NestedTupleSourceOperator) GroupByOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) IPhysicalPropertiesVector(org.apache.hyracks.algebricks.core.algebra.properties.IPhysicalPropertiesVector) ILocalStructuralProperty(org.apache.hyracks.algebricks.core.algebra.properties.ILocalStructuralProperty)

Example 23 with NestedTupleSourceOperator

use of org.apache.hyracks.algebricks.core.algebra.operators.logical.NestedTupleSourceOperator in project asterixdb by apache.

the class PhysicalOptimizationsUtil method computeFDsAndEqClassesWithVisitorRec.

private static <R> void computeFDsAndEqClassesWithVisitorRec(ILogicalOperator op, IOptimizationContext ctx, ILogicalOperatorVisitor<R, IOptimizationContext> visitor, Set<ILogicalOperator> visitSet) throws AlgebricksException {
    visitSet.add(op);
    for (Mutable<ILogicalOperator> i : op.getInputs()) {
        computeFDsAndEqClassesWithVisitorRec((AbstractLogicalOperator) i.getValue(), ctx, visitor, visitSet);
    }
    AbstractLogicalOperator aop = (AbstractLogicalOperator) op;
    if (aop.hasNestedPlans()) {
        for (ILogicalPlan p : ((AbstractOperatorWithNestedPlans) op).getNestedPlans()) {
            for (Mutable<ILogicalOperator> r : p.getRoots()) {
                AbstractLogicalOperator rootOp = (AbstractLogicalOperator) r.getValue();
                computeFDsAndEqClassesWithVisitorRec(rootOp, ctx, visitor, visitSet);
            }
        }
    }
    if (op.getOperatorTag() == LogicalOperatorTag.NESTEDTUPLESOURCE) {
        NestedTupleSourceOperator nts = (NestedTupleSourceOperator) op;
        ILogicalOperator source = nts.getDataSourceReference().getValue().getInputs().get(0).getValue();
        if (!visitSet.contains(source)) {
            computeFDsAndEqClassesWithVisitorRec((AbstractLogicalOperator) source, ctx, visitor, visitSet);
        }
    }
    op.accept(visitor, ctx);
}
Also used : NestedTupleSourceOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.NestedTupleSourceOperator) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) ILogicalPlan(org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan) AbstractOperatorWithNestedPlans(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractOperatorWithNestedPlans)

Aggregations

NestedTupleSourceOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.NestedTupleSourceOperator)23 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)22 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)16 MutableObject (org.apache.commons.lang3.mutable.MutableObject)13 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)13 ILogicalPlan (org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan)13 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)13 SubplanOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.SubplanOperator)11 AggregateOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator)10 GroupByOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator)10 ArrayList (java.util.ArrayList)9 Mutable (org.apache.commons.lang3.mutable.Mutable)9 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)9 Pair (org.apache.hyracks.algebricks.common.utils.Pair)8 ALogicalPlanImpl (org.apache.hyracks.algebricks.core.algebra.plan.ALogicalPlanImpl)7 HashSet (java.util.HashSet)6 AggregateFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AggregateFunctionCallExpression)6 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)6 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)5 SelectOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.SelectOperator)5