Search in sources :

Example 31 with ILogicalExpression

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

the class RemoveLeftOuterUnnestForLeftOuterJoinRule method checkSelect.

// Checks the expression for the nested select operator inside the group-by operator.
private Pair<Boolean, ILogicalExpression> checkSelect(SelectOperator select) {
    ILogicalExpression condition = select.getCondition().getValue();
    if (condition.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
        return new Pair<>(false, null);
    }
    AbstractFunctionCallExpression conditionFunc = (AbstractFunctionCallExpression) condition;
    if (!conditionFunc.getFunctionIdentifier().equals(BuiltinFunctions.NOT)) {
        return new Pair<>(false, null);
    }
    condition = conditionFunc.getArguments().get(0).getValue();
    if (condition.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
        return new Pair<>(false, null);
    }
    conditionFunc = (AbstractFunctionCallExpression) condition;
    if (!conditionFunc.getFunctionIdentifier().equals(BuiltinFunctions.IS_MISSING)) {
        return new Pair<>(false, null);
    }
    ILogicalExpression conditionArg = conditionFunc.getArguments().get(0).getValue();
    return new Pair<>(true, conditionArg);
}
Also used : ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Example 32 with ILogicalExpression

use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression 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);
}
Also used : Triple(org.apache.hyracks.algebricks.common.utils.Triple) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) SelectOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.SelectOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) AggregateOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator)

Example 33 with ILogicalExpression

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

the class OpenRecordConstructorResultType method computeType.

@Override
public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env, IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
    AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) expression;
    /**
         * if type has been top-down propagated, use the enforced type
         */
    ARecordType type = (ARecordType) TypeCastUtils.getRequiredType(f);
    if (type != null) {
        return type;
    }
    Iterator<Mutable<ILogicalExpression>> argIter = f.getArguments().iterator();
    List<String> namesList = new ArrayList<>();
    List<IAType> typesList = new ArrayList<>();
    // The following set of names do not belong to the closed part,
    // but are additional possible field names. For example, a field "foo" with type
    // ANY cannot be in the closed part, but "foo" is a possible field name.
    Set<String> allPossibleAdditionalFieldNames = new HashSet<>();
    boolean canProvideAdditionFieldInfo = true;
    boolean isOpen = false;
    while (argIter.hasNext()) {
        ILogicalExpression e1 = argIter.next().getValue();
        ILogicalExpression e2 = argIter.next().getValue();
        IAType t2 = (IAType) env.getType(e2);
        String fieldName = ConstantExpressionUtil.getStringConstant(e1);
        if (fieldName != null && t2 != null && TypeHelper.isClosed(t2)) {
            namesList.add(fieldName);
            if (t2.getTypeTag() == ATypeTag.UNION) {
                AUnionType unionType = (AUnionType) t2;
                t2 = AUnionType.createUnknownableType(unionType.getActualType());
            }
            typesList.add(t2);
        } else {
            if (canProvideAdditionFieldInfo && fieldName != null) {
                allPossibleAdditionalFieldNames.add(fieldName);
            } else {
                canProvideAdditionFieldInfo = false;
            }
            isOpen = true;
        }
    }
    String[] fieldNames = namesList.toArray(new String[0]);
    IAType[] fieldTypes = typesList.toArray(new IAType[0]);
    return canProvideAdditionFieldInfo ? new ARecordType(null, fieldNames, fieldTypes, isOpen, allPossibleAdditionalFieldNames) : new ARecordType(null, fieldNames, fieldTypes, isOpen);
}
Also used : AUnionType(org.apache.asterix.om.types.AUnionType) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) ArrayList(java.util.ArrayList) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) ARecordType(org.apache.asterix.om.types.ARecordType) IAType(org.apache.asterix.om.types.IAType) HashSet(java.util.HashSet)

Example 34 with ILogicalExpression

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

the class RecordAddFieldsTypeComputer method containsVariable.

// Handle variable as input
private boolean containsVariable(ILogicalExpression expression) {
    if (expression.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
        AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) expression;
        List<Mutable<ILogicalExpression>> args = f.getArguments();
        for (Mutable<ILogicalExpression> arg : args) {
            ILogicalExpression subExpression = arg.getValue();
            switch(subExpression.getExpressionTag()) {
                case VARIABLE:
                    return true;
                case CONSTANT:
                    return false;
                default:
                    //FUNCTION_CALL
                    return containsVariable(subExpression);
            }
        }
    }
    return true;
}
Also used : Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)

Example 35 with ILogicalExpression

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

the class AbstractUnnestPOperator method contributeRuntimeOperator.

@Override
public void contributeRuntimeOperator(IHyracksJobBuilder builder, JobGenContext context, ILogicalOperator op, IOperatorSchema opSchema, IOperatorSchema[] inputSchemas, IOperatorSchema outerPlanSchema) throws AlgebricksException {
    AbstractUnnestNonMapOperator unnest = (AbstractUnnestNonMapOperator) op;
    int outCol = opSchema.findVariable(unnest.getVariable());
    ILogicalExpression unnestExpr = unnest.getExpressionRef().getValue();
    IExpressionRuntimeProvider expressionRuntimeProvider = context.getExpressionRuntimeProvider();
    boolean exit = false;
    if (unnestExpr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
        exit = true;
    } else {
        AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) unnestExpr;
        if (fce.getKind() != FunctionKind.UNNEST) {
            exit = true;
        }
    }
    if (exit) {
        throw new AlgebricksException("Unnest expression " + unnestExpr + " is not an unnesting function call.");
    }
    UnnestingFunctionCallExpression agg = (UnnestingFunctionCallExpression) unnestExpr;
    IUnnestingEvaluatorFactory unnestingFactory = expressionRuntimeProvider.createUnnestingFunctionFactory(agg, context.getTypeEnvironment(op.getInputs().get(0).getValue()), inputSchemas, context);
    int[] projectionList = JobGenHelper.projectAllVariables(opSchema);
    UnnestRuntimeFactory unnestRuntime = new UnnestRuntimeFactory(outCol, unnestingFactory, projectionList, unnest.getPositionWriter(), leftOuter, context.getMissingWriterFactory());
    RecordDescriptor recDesc = JobGenHelper.mkRecordDescriptor(context.getTypeEnvironment(op), opSchema, context);
    builder.contributeMicroOperator(unnest, unnestRuntime, recDesc);
    ILogicalOperator src = unnest.getInputs().get(0).getValue();
    builder.contributeGraphEdge(src, 0, unnest, 0);
}
Also used : AbstractUnnestNonMapOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractUnnestNonMapOperator) UnnestingFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.UnnestingFunctionCallExpression) RecordDescriptor(org.apache.hyracks.api.dataflow.value.RecordDescriptor) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) IUnnestingEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IUnnestingEvaluatorFactory) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) IExpressionRuntimeProvider(org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionRuntimeProvider) UnnestRuntimeFactory(org.apache.hyracks.algebricks.runtime.operators.std.UnnestRuntimeFactory)

Aggregations

ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)312 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)182 Mutable (org.apache.commons.lang3.mutable.Mutable)160 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)130 ArrayList (java.util.ArrayList)125 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)125 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)121 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)84 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)75 Pair (org.apache.hyracks.algebricks.common.utils.Pair)70 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)68 MutableObject (org.apache.commons.lang3.mutable.MutableObject)62 ConstantExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression)50 IAType (org.apache.asterix.om.types.IAType)42 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)38 ILogicalPlan (org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan)36 AsterixConstantValue (org.apache.asterix.om.constants.AsterixConstantValue)34 FunctionIdentifier (org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier)34 HashSet (java.util.HashSet)32 AString (org.apache.asterix.om.base.AString)32