Search in sources :

Example 41 with ILogicalOperator

use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator in project asterixdb by apache.

the class IndexBulkloadPOperator method contributeRuntimeOperator.

@Override
public void contributeRuntimeOperator(IHyracksJobBuilder builder, JobGenContext context, ILogicalOperator op, IOperatorSchema propagatedSchema, IOperatorSchema[] inputSchemas, IOperatorSchema outerPlanSchema) throws AlgebricksException {
    IndexInsertDeleteUpsertOperator indexInsertDeleteOp = (IndexInsertDeleteUpsertOperator) op;
    assert indexInsertDeleteOp.getOperation() == Kind.INSERT;
    assert indexInsertDeleteOp.isBulkload();
    IMetadataProvider mp = context.getMetadataProvider();
    IVariableTypeEnvironment typeEnv = context.getTypeEnvironment(op);
    JobSpecification spec = builder.getJobSpec();
    RecordDescriptor inputDesc = JobGenHelper.mkRecordDescriptor(context.getTypeEnvironment(op.getInputs().get(0).getValue()), inputSchemas[0], context);
    Pair<IOperatorDescriptor, AlgebricksPartitionConstraint> runtimeAndConstraints = mp.getIndexInsertRuntime(dataSourceIndex, propagatedSchema, inputSchemas, typeEnv, primaryKeys, secondaryKeys, additionalFilteringKeys, filterExpr, inputDesc, context, spec, true);
    builder.contributeHyracksOperator(indexInsertDeleteOp, runtimeAndConstraints.first);
    builder.contributeAlgebricksPartitionConstraint(runtimeAndConstraints.first, runtimeAndConstraints.second);
    ILogicalOperator src = indexInsertDeleteOp.getInputs().get(0).getValue();
    builder.contributeGraphEdge(src, 0, indexInsertDeleteOp, 0);
}
Also used : RecordDescriptor(org.apache.hyracks.api.dataflow.value.RecordDescriptor) IOperatorDescriptor(org.apache.hyracks.api.dataflow.IOperatorDescriptor) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) IndexInsertDeleteUpsertOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.IndexInsertDeleteUpsertOperator) AlgebricksPartitionConstraint(org.apache.hyracks.algebricks.common.constraints.AlgebricksPartitionConstraint) JobSpecification(org.apache.hyracks.api.job.JobSpecification) IMetadataProvider(org.apache.hyracks.algebricks.core.algebra.metadata.IMetadataProvider) IVariableTypeEnvironment(org.apache.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment)

Example 42 with ILogicalOperator

use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator in project asterixdb by apache.

the class AbstractPropagatePropertiesForUsedVariablesPOperator method computeDeliveredPropertiesForUsedVariables.

public void computeDeliveredPropertiesForUsedVariables(ILogicalOperator op, List<LogicalVariable> usedVariables) {
    ILogicalOperator op2 = op.getInputs().get(0).getValue();
    IPartitioningProperty pp = op2.getDeliveredPhysicalProperties().getPartitioningProperty();
    List<ILocalStructuralProperty> downPropsLocal = op2.getDeliveredPhysicalProperties().getLocalProperties();
    List<ILocalStructuralProperty> propsLocal = new ArrayList<ILocalStructuralProperty>();
    if (downPropsLocal != null) {
        for (ILocalStructuralProperty lsp : downPropsLocal) {
            LinkedList<LogicalVariable> cols = new LinkedList<LogicalVariable>();
            lsp.getColumns(cols);
            ILocalStructuralProperty propagatedProp = lsp.retainVariables(usedVariables);
            if (propagatedProp != null) {
                propsLocal.add(propagatedProp);
            }
        }
    }
    deliveredProperties = new StructuralPropertiesVector(pp, propsLocal);
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) StructuralPropertiesVector(org.apache.hyracks.algebricks.core.algebra.properties.StructuralPropertiesVector) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) ArrayList(java.util.ArrayList) ILocalStructuralProperty(org.apache.hyracks.algebricks.core.algebra.properties.ILocalStructuralProperty) IPartitioningProperty(org.apache.hyracks.algebricks.core.algebra.properties.IPartitioningProperty) LinkedList(java.util.LinkedList)

Example 43 with ILogicalOperator

use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator in project asterixdb by apache.

the class InjectTypeCastForUnionRule method rewritePost.

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    ILogicalOperator op = opRef.getValue();
    if (op.getOperatorTag() != LogicalOperatorTag.UNIONALL) {
        return false;
    }
    UnionAllOperator unionAllOperator = (UnionAllOperator) op;
    // Injects casts to the first and second input branch of the UnionAllOperator.
    return injectCast(unionAllOperator, 0, context) || injectCast(unionAllOperator, 1, context);
}
Also used : UnionAllOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.UnionAllOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)

Example 44 with ILogicalOperator

use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator in project asterixdb by apache.

the class InjectTypeCastForUnionRule method injectCast.

// Injects a type cast function on one input (indicated by childIndex) of the union all operator if necessary.
private boolean injectCast(UnionAllOperator op, int childIndex, IOptimizationContext context) throws AlgebricksException {
    // Gets the type environments for the union all operator and its child operator with the right child index.
    IVariableTypeEnvironment env = context.getOutputTypeEnvironment(op);
    Mutable<ILogicalOperator> branchOpRef = op.getInputs().get(childIndex);
    IVariableTypeEnvironment childEnv = context.getOutputTypeEnvironment(branchOpRef.getValue());
    // The two lists are used for the assign operator that calls cast functions.
    List<LogicalVariable> varsToCast = new ArrayList<>();
    List<Mutable<ILogicalExpression>> castFunctionsForLeft = new ArrayList<>();
    // Iterate through all triples.
    List<Triple<LogicalVariable, LogicalVariable, LogicalVariable>> triples = op.getVariableMappings();
    for (Triple<LogicalVariable, LogicalVariable, LogicalVariable> triple : triples) {
        LogicalVariable producedVar = triple.third;
        IAType producedType = (IAType) env.getVarType(producedVar);
        LogicalVariable varToCast = childIndex == 0 ? triple.first : triple.second;
        IAType inputType = (IAType) childEnv.getVarType(varToCast);
        if (!TypeResolverUtil.needsCast(producedType, inputType)) {
            // Continues to the next triple if no cast is neeeded.
            continue;
        }
        LogicalVariable castedVar = context.newVar();
        // Resets triple variables to new variables that bind to the results of type casting.
        triple.first = childIndex == 0 ? castedVar : triple.first;
        triple.second = childIndex > 0 ? castedVar : triple.second;
        ScalarFunctionCallExpression castFunc = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.CAST_TYPE), new ArrayList<>(Collections.singletonList(new MutableObject<>(new VariableReferenceExpression(varToCast)))));
        TypeCastUtils.setRequiredAndInputTypes(castFunc, producedType, inputType);
        // Adds the variable and function expression into lists, for the assign operator.
        varsToCast.add(castedVar);
        castFunctionsForLeft.add(new MutableObject<>(castFunc));
    }
    if (castFunctionsForLeft.isEmpty()) {
        return false;
    }
    // Injects an assign operator to perform type casts.
    AssignOperator assignOp = new AssignOperator(varsToCast, castFunctionsForLeft);
    assignOp.getInputs().add(new MutableObject<>(branchOpRef.getValue()));
    branchOpRef.setValue(assignOp);
    context.computeAndSetTypeEnvironmentForOperator(assignOp);
    // Returns true to indicate that rewriting happens.
    return true;
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) ArrayList(java.util.ArrayList) AssignOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator) Triple(org.apache.hyracks.algebricks.common.utils.Triple) Mutable(org.apache.commons.lang3.mutable.Mutable) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) IVariableTypeEnvironment(org.apache.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment) IAType(org.apache.asterix.om.types.IAType) ScalarFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)

Example 45 with ILogicalOperator

use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator in project asterixdb by apache.

the class FeedScanCollectionToUnnest method findVarOriginExpression.

private ILogicalExpression findVarOriginExpression(LogicalVariable v, ILogicalOperator op) throws AlgebricksException {
    boolean searchInputs = false;
    if (!(op instanceof AbstractAssignOperator)) {
        searchInputs = true;
    } else {
        AbstractAssignOperator aao = (AbstractAssignOperator) op;
        List<LogicalVariable> producedVars = new ArrayList<>();
        VariableUtilities.getProducedVariables(op, producedVars);
        int exprIndex = producedVars.indexOf(v);
        if (exprIndex == -1) {
            searchInputs = true;
        } else {
            ILogicalExpression originalCandidate = aao.getExpressions().get(exprIndex).getValue();
            if (originalCandidate.getExpressionTag() == LogicalExpressionTag.VARIABLE) {
                searchInputs = true;
            } else {
                return originalCandidate;
            }
        }
    }
    if (searchInputs) {
        for (Mutable<ILogicalOperator> childOp : op.getInputs()) {
            ILogicalExpression ret = findVarOriginExpression(v, childOp.getValue());
            if (ret != null) {
                return ret;
            }
        }
    }
    throw new IllegalStateException("Unable to find the original expression that produced variable " + v);
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) AbstractAssignOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractAssignOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) ArrayList(java.util.ArrayList)

Aggregations

ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)355 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)196 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)130 Mutable (org.apache.commons.lang3.mutable.Mutable)125 ArrayList (java.util.ArrayList)119 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)117 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)86 ILogicalPlan (org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan)73 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)57 Pair (org.apache.hyracks.algebricks.common.utils.Pair)53 MutableObject (org.apache.commons.lang3.mutable.MutableObject)51 HashSet (java.util.HashSet)46 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)43 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)36 GroupByOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator)36 RecordDescriptor (org.apache.hyracks.api.dataflow.value.RecordDescriptor)33 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)29 AggregateOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator)28 SubplanOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.SubplanOperator)26 AggregateFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AggregateFunctionCallExpression)25