Search in sources :

Example 66 with AbstractFunctionCallExpression

use of org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression in project asterixdb by apache.

the class BTreeAccessMethod method getNewConditionExprs.

private void getNewConditionExprs(Mutable<ILogicalExpression> conditionRef, Set<ILogicalExpression> replacedFuncExprs, List<Mutable<ILogicalExpression>> remainingFuncExprs) throws CompilationException {
    remainingFuncExprs.clear();
    if (replacedFuncExprs.isEmpty()) {
        return;
    }
    AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) conditionRef.getValue();
    if (replacedFuncExprs.size() == 1) {
        Iterator<ILogicalExpression> it = replacedFuncExprs.iterator();
        if (!it.hasNext()) {
            return;
        }
        if (funcExpr == it.next()) {
            // There are no remaining function exprs.
            return;
        }
    }
    // The original select cond must be an AND. Check it just to be sure.
    if (funcExpr.getFunctionIdentifier() != AlgebricksBuiltinFunctions.AND) {
        throw new CompilationException(ErrorCode.COMPILATION_FUNC_EXPRESSION_CANNOT_UTILIZE_INDEX, funcExpr.toString());
    }
    // Clean the conjuncts.
    for (Mutable<ILogicalExpression> arg : funcExpr.getArguments()) {
        ILogicalExpression argExpr = arg.getValue();
        if (argExpr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
            continue;
        }
        // plan, then add it to the list of remaining function expressions.
        if (!replacedFuncExprs.contains(argExpr)) {
            remainingFuncExprs.add(arg);
        }
    }
}
Also used : CompilationException(org.apache.asterix.common.exceptions.CompilationException) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)

Example 67 with AbstractFunctionCallExpression

use of org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression in project asterixdb by apache.

the class PullSelectOutOfEqJoin method isEqVarVar.

private boolean isEqVarVar(ILogicalExpression expr) {
    if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
        return false;
    }
    AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) expr;
    if (!f.getFunctionIdentifier().equals(AlgebricksBuiltinFunctions.EQ)) {
        return false;
    }
    ILogicalExpression e1 = f.getArguments().get(0).getValue();
    if (e1.getExpressionTag() != LogicalExpressionTag.VARIABLE) {
        return false;
    } else {
        ILogicalExpression e2 = f.getArguments().get(1).getValue();
        return e2.getExpressionTag() == LogicalExpressionTag.VARIABLE;
    }
}
Also used : ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)

Example 68 with AbstractFunctionCallExpression

use of org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression in project asterixdb by apache.

the class PushFunctionsBelowJoin method gatherFunctionCalls.

private void gatherFunctionCalls(Mutable<ILogicalExpression> exprRef, List<Mutable<ILogicalExpression>> funcExprs) {
    AbstractLogicalExpression expr = (AbstractLogicalExpression) exprRef.getValue();
    if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
        return;
    }
    // Check whether the function is a function we want to push.
    AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr;
    if (toPushFuncIdents.contains(funcExpr.getFunctionIdentifier())) {
        funcExprs.add(exprRef);
    }
    // Traverse arguments.
    for (Mutable<ILogicalExpression> funcArg : funcExpr.getArguments()) {
        gatherFunctionCalls(funcArg, funcExprs);
    }
}
Also used : ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) AbstractLogicalExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractLogicalExpression) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)

Example 69 with AbstractFunctionCallExpression

use of org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression in project asterixdb by apache.

the class PullSelectOutOfEqJoin method rewritePost.

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
    if (op.getOperatorTag() != LogicalOperatorTag.INNERJOIN) {
        return false;
    }
    AbstractBinaryJoinOperator join = (AbstractBinaryJoinOperator) op;
    ILogicalExpression expr = join.getCondition().getValue();
    if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
        return false;
    }
    AbstractFunctionCallExpression fexp = (AbstractFunctionCallExpression) expr;
    FunctionIdentifier fi = fexp.getFunctionIdentifier();
    if (!fi.equals(AlgebricksBuiltinFunctions.AND)) {
        return false;
    }
    List<Mutable<ILogicalExpression>> eqVarVarComps = new ArrayList<Mutable<ILogicalExpression>>();
    List<Mutable<ILogicalExpression>> otherPredicates = new ArrayList<Mutable<ILogicalExpression>>();
    for (Mutable<ILogicalExpression> arg : fexp.getArguments()) {
        if (isEqVarVar(arg.getValue())) {
            eqVarVarComps.add(arg);
        } else {
            otherPredicates.add(arg);
        }
    }
    if (eqVarVarComps.isEmpty() || otherPredicates.isEmpty()) {
        return false;
    }
    // pull up
    ILogicalExpression pulledCond = makeCondition(otherPredicates, context);
    SelectOperator select = new SelectOperator(new MutableObject<ILogicalExpression>(pulledCond), false, null);
    ILogicalExpression newJoinCond = makeCondition(eqVarVarComps, context);
    join.getCondition().setValue(newJoinCond);
    select.getInputs().add(new MutableObject<ILogicalOperator>(join));
    opRef.setValue(select);
    context.computeAndSetTypeEnvironmentForOperator(select);
    return true;
}
Also used : AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) ArrayList(java.util.ArrayList) AbstractBinaryJoinOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractBinaryJoinOperator) FunctionIdentifier(org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) SelectOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.SelectOperator)

Example 70 with AbstractFunctionCallExpression

use of org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression in project asterixdb by apache.

the class FDsAndEquivClassesVisitor method fdsEqClassesForAbstractUnnestOperator.

private void fdsEqClassesForAbstractUnnestOperator(AbstractUnnestOperator op, IOptimizationContext ctx) throws AlgebricksException {
    ILogicalOperator inp1 = op.getInputs().get(0).getValue();
    Map<LogicalVariable, EquivalenceClass> eqClasses = getOrCreateEqClasses(op, ctx);
    Map<LogicalVariable, EquivalenceClass> propagatedEqClasses = getOrComputeEqClasses(inp1, ctx);
    /**
         * The original eq classes of unnest-map are only for produced
         * variables, therefore eqClasses and propagatedEqClasses do not have
         * overlaps.
         */
    eqClasses.putAll(propagatedEqClasses);
    ctx.putEquivalenceClassMap(op, eqClasses);
    List<FunctionalDependency> fds = getOrComputeFDs(inp1, ctx);
    ctx.putFDList(op, fds);
    ILogicalExpression expr = op.getExpressionRef().getValue();
    if (expr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
        AbstractFunctionCallExpression afe = (AbstractFunctionCallExpression) expr;
        if (afe.getKind() == FunctionKind.UNNEST && ((UnnestingFunctionCallExpression) afe).returnsUniqueValues()) {
            List<LogicalVariable> vars = new ArrayList<LogicalVariable>();
            VariableUtilities.getLiveVariables(op, vars);
            ArrayList<LogicalVariable> h = new ArrayList<LogicalVariable>();
            h.addAll(op.getVariables());
            FunctionalDependency fd = new FunctionalDependency(h, vars);
            fds.add(fd);
        }
    }
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) FunctionalDependency(org.apache.hyracks.algebricks.core.algebra.properties.FunctionalDependency) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) ArrayList(java.util.ArrayList) EquivalenceClass(org.apache.hyracks.algebricks.core.algebra.base.EquivalenceClass)

Aggregations

AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)138 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)111 Mutable (org.apache.commons.lang3.mutable.Mutable)59 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)54 ArrayList (java.util.ArrayList)50 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)38 IAType (org.apache.asterix.om.types.IAType)37 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)37 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)35 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)35 FunctionIdentifier (org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier)34 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)33 ConstantExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression)25 ARecordType (org.apache.asterix.om.types.ARecordType)20 AsterixConstantValue (org.apache.asterix.om.constants.AsterixConstantValue)19 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)19 Pair (org.apache.hyracks.algebricks.common.utils.Pair)19 MutableObject (org.apache.commons.lang3.mutable.MutableObject)18 AString (org.apache.asterix.om.base.AString)17 MetadataProvider (org.apache.asterix.metadata.declared.MetadataProvider)13