Search in sources :

Example 11 with Triple

use of org.apache.hyracks.algebricks.common.utils.Triple in project asterixdb by apache.

the class ResolveVariableRule method rewritePost.

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    ILogicalOperator op = opRef.getValue();
    if (op.getInputs().isEmpty()) {
        return false;
    }
    // Populates the latest type information, e.g., resolved path sugars.
    context.computeAndSetTypeEnvironmentForOperator(op);
    if (op.acceptExpressionTransform(exprRef -> rewriteExpressionReference(op, exprRef, new Triple<>(false, null, null), null, context))) {
        // Generates the up-to-date type information.
        context.computeAndSetTypeEnvironmentForOperator(op);
        return true;
    }
    return false;
}
Also used : Triple(org.apache.hyracks.algebricks.common.utils.Triple) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)

Example 12 with Triple

use of org.apache.hyracks.algebricks.common.utils.Triple in project asterixdb by apache.

the class MetadataProvider method buildFeedIntakeRuntime.

public Triple<IOperatorDescriptor, AlgebricksPartitionConstraint, IAdapterFactory> buildFeedIntakeRuntime(JobSpecification jobSpec, Feed primaryFeed, FeedPolicyAccessor policyAccessor) throws Exception {
    Triple<IAdapterFactory, RecordDescriptor, IDataSourceAdapter.AdapterType> factoryOutput;
    factoryOutput = FeedMetadataUtil.getPrimaryFeedFactoryAndOutput(primaryFeed, policyAccessor, mdTxnCtx, getApplicationContext());
    ARecordType recordType = FeedMetadataUtil.getOutputType(primaryFeed, primaryFeed.getAdapterConfiguration(), ExternalDataConstants.KEY_TYPE_NAME);
    IAdapterFactory adapterFactory = factoryOutput.first;
    FeedIntakeOperatorDescriptor feedIngestor = null;
    switch(factoryOutput.third) {
        case INTERNAL:
            feedIngestor = new FeedIntakeOperatorDescriptor(jobSpec, primaryFeed, adapterFactory, recordType, policyAccessor, factoryOutput.second);
            break;
        case EXTERNAL:
            String libraryName = primaryFeed.getAdapterName().trim().split(FeedConstants.NamingConstants.LIBRARY_NAME_SEPARATOR)[0];
            feedIngestor = new FeedIntakeOperatorDescriptor(jobSpec, primaryFeed, libraryName, adapterFactory.getClass().getName(), recordType, policyAccessor, factoryOutput.second);
            break;
        default:
            break;
    }
    AlgebricksPartitionConstraint partitionConstraint = adapterFactory.getPartitionConstraint();
    return new Triple<>(feedIngestor, partitionConstraint, adapterFactory);
}
Also used : Triple(org.apache.hyracks.algebricks.common.utils.Triple) RecordDescriptor(org.apache.hyracks.api.dataflow.value.RecordDescriptor) IAdapterFactory(org.apache.asterix.external.api.IAdapterFactory) AlgebricksPartitionConstraint(org.apache.hyracks.algebricks.common.constraints.AlgebricksPartitionConstraint) ARecordType(org.apache.asterix.om.types.ARecordType) FeedIntakeOperatorDescriptor(org.apache.asterix.external.operators.FeedIntakeOperatorDescriptor)

Example 13 with Triple

use of org.apache.hyracks.algebricks.common.utils.Triple in project asterixdb by apache.

the class InsertProjectBeforeUnionRule method rewritePost.

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
    if (op.getOperatorTag() != LogicalOperatorTag.UNIONALL) {
        return false;
    }
    UnionAllOperator opUnion = (UnionAllOperator) op;
    List<Triple<LogicalVariable, LogicalVariable, LogicalVariable>> varMap = opUnion.getVariableMappings();
    ArrayList<LogicalVariable> usedVariablesFromOne = new ArrayList<>();
    ArrayList<LogicalVariable> usedVariablesFromTwo = new ArrayList<>();
    for (Triple<LogicalVariable, LogicalVariable, LogicalVariable> triple : varMap) {
        usedVariablesFromOne.add(triple.first);
        usedVariablesFromTwo.add(triple.second);
    }
    ArrayList<LogicalVariable> inputSchemaOne = new ArrayList<>();
    VariableUtilities.getLiveVariables(opUnion.getInputs().get(0).getValue(), inputSchemaOne);
    ArrayList<LogicalVariable> inputSchemaTwo = new ArrayList<>();
    VariableUtilities.getLiveVariables(opUnion.getInputs().get(1).getValue(), inputSchemaTwo);
    boolean rewritten = false;
    if (!isIdentical(usedVariablesFromOne, inputSchemaOne)) {
        insertProjectOperator(opUnion, 0, usedVariablesFromOne, context);
        rewritten = true;
    }
    if (!isIdentical(usedVariablesFromTwo, inputSchemaTwo)) {
        insertProjectOperator(opUnion, 1, usedVariablesFromTwo, context);
        rewritten = true;
    }
    return rewritten;
}
Also used : Triple(org.apache.hyracks.algebricks.common.utils.Triple) LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) UnionAllOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.UnionAllOperator) ArrayList(java.util.ArrayList)

Example 14 with Triple

use of org.apache.hyracks.algebricks.common.utils.Triple in project asterixdb by apache.

the class PushAssignBelowUnionAllRule method rewritePost.

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
    if (!op.hasInputs()) {
        return false;
    }
    boolean modified = false;
    for (int i = 0; i < op.getInputs().size(); i++) {
        AbstractLogicalOperator childOp = (AbstractLogicalOperator) op.getInputs().get(i).getValue();
        if (childOp.getOperatorTag() != LogicalOperatorTag.ASSIGN) {
            continue;
        }
        AssignOperator assignOp = (AssignOperator) childOp;
        for (Mutable<ILogicalExpression> expr : assignOp.getExpressions()) {
            if (!expr.getValue().isFunctional()) {
                return false;
            }
        }
        AbstractLogicalOperator childOfChildOp = (AbstractLogicalOperator) assignOp.getInputs().get(0).getValue();
        if (childOfChildOp.getOperatorTag() != LogicalOperatorTag.UNIONALL) {
            continue;
        }
        UnionAllOperator unionOp = (UnionAllOperator) childOfChildOp;
        Set<LogicalVariable> assignUsedVars = new HashSet<LogicalVariable>();
        VariableUtilities.getUsedVariables(assignOp, assignUsedVars);
        List<LogicalVariable> assignVars = assignOp.getVariables();
        AssignOperator[] newAssignOps = new AssignOperator[2];
        for (int j = 0; j < unionOp.getInputs().size(); j++) {
            newAssignOps[j] = createAssignBelowUnionAllBranch(unionOp, j, assignOp, assignUsedVars, context);
        }
        // Add original assign variables to the union variable mappings.
        for (int j = 0; j < assignVars.size(); j++) {
            LogicalVariable first = newAssignOps[0].getVariables().get(j);
            LogicalVariable second = newAssignOps[1].getVariables().get(j);
            Triple<LogicalVariable, LogicalVariable, LogicalVariable> varMapping = new Triple<LogicalVariable, LogicalVariable, LogicalVariable>(first, second, assignVars.get(j));
            unionOp.getVariableMappings().add(varMapping);
        }
        context.computeAndSetTypeEnvironmentForOperator(unionOp);
        // Remove original assign operator.
        op.getInputs().set(i, assignOp.getInputs().get(0));
        context.computeAndSetTypeEnvironmentForOperator(op);
        modified = true;
    }
    return modified;
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) AssignOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator) Triple(org.apache.hyracks.algebricks.common.utils.Triple) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) UnionAllOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.UnionAllOperator) HashSet(java.util.HashSet)

Example 15 with Triple

use of org.apache.hyracks.algebricks.common.utils.Triple in project asterixdb by apache.

the class RemoveUnusedAssignAndAggregateRule method removeAssignVarFromConsideration.

/**
     * Collect the information from the given operator and removes assigned
     * variables if they are used afterwards.
     */
private Set<LogicalVariable> removeAssignVarFromConsideration(Mutable<ILogicalOperator> opRef) {
    Set<LogicalVariable> assignVarsSetForThisOp = null;
    Set<LogicalVariable> usedVarsSetForThisOp = null;
    if (accumulatedUsedVarFromRootMap.containsKey(opRef)) {
        usedVarsSetForThisOp = accumulatedUsedVarFromRootMap.get(opRef);
    }
    if (assignedVarMap.containsKey(opRef)) {
        assignVarsSetForThisOp = assignedVarMap.get(opRef);
    }
    if (assignVarsSetForThisOp != null && !assignVarsSetForThisOp.isEmpty()) {
        Iterator<LogicalVariable> varIter = assignVarsSetForThisOp.iterator();
        while (varIter.hasNext()) {
            LogicalVariable v = varIter.next();
            if ((usedVarsSetForThisOp != null && usedVarsSetForThisOp.contains(v)) || survivedUnionSourceVarSet.contains(v)) {
                varIter.remove();
            }
        }
    }
    // afterwards.
    if (opRef.getValue().getOperatorTag() == LogicalOperatorTag.UNIONALL) {
        Iterator<Triple<LogicalVariable, LogicalVariable, LogicalVariable>> iter = ((UnionAllOperator) opRef.getValue()).getVariableMappings().iterator();
        while (iter.hasNext()) {
            Triple<LogicalVariable, LogicalVariable, LogicalVariable> varMapping = iter.next();
            survivedUnionSourceVarSet.add(varMapping.first);
            survivedUnionSourceVarSet.add(varMapping.second);
        }
    }
    return assignVarsSetForThisOp;
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) Triple(org.apache.hyracks.algebricks.common.utils.Triple)

Aggregations

Triple (org.apache.hyracks.algebricks.common.utils.Triple)15 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)9 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)8 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)7 UnionAllOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.UnionAllOperator)7 ArrayList (java.util.ArrayList)6 Mutable (org.apache.commons.lang3.mutable.Mutable)4 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)4 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)3 AString (org.apache.asterix.om.base.AString)2 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)2 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)2 SelectOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.SelectOperator)2 UnnestOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.UnnestOperator)2 DataOutput (java.io.DataOutput)1 HashSet (java.util.HashSet)1 List (java.util.List)1 IAdapterFactory (org.apache.asterix.external.api.IAdapterFactory)1 FeedIntakeOperatorDescriptor (org.apache.asterix.external.operators.FeedIntakeOperatorDescriptor)1 ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)1