Search in sources :

Example 41 with ScalarFunctionCallExpression

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

the class LogicalExpressionDeepCopyWithNewVariablesVisitor method visitScalarFunctionCallExpression.

@Override
public ILogicalExpression visitScalarFunctionCallExpression(ScalarFunctionCallExpression expr, Void arg) throws AlgebricksException {
    ScalarFunctionCallExpression exprCopy = new ScalarFunctionCallExpression(expr.getFunctionInfo(), deepCopyExpressionReferenceList(expr.getArguments()));
    deepCopyAnnotations(expr, exprCopy);
    deepCopyOpaqueParameters(expr, exprCopy);
    return exprCopy;
}
Also used : ScalarFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)

Example 42 with ScalarFunctionCallExpression

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

the class PushSelectIntoJoinRule method addCondToJoin.

private static void addCondToJoin(SelectOperator select, AbstractBinaryJoinOperator join, IOptimizationContext context) {
    ILogicalExpression cond = join.getCondition().getValue();
    if (OperatorPropertiesUtil.isAlwaysTrueCond(cond)) {
        // the join was a product
        join.getCondition().setValue(select.getCondition().getValue());
    } else {
        boolean bAddedToConj = false;
        if (cond.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
            AbstractFunctionCallExpression fcond = (AbstractFunctionCallExpression) cond;
            if (fcond.getFunctionIdentifier().equals(AlgebricksBuiltinFunctions.AND)) {
                AbstractFunctionCallExpression newCond = new ScalarFunctionCallExpression(context.getMetadataProvider().lookupFunction(AlgebricksBuiltinFunctions.AND));
                newCond.getArguments().add(select.getCondition());
                newCond.getArguments().addAll(fcond.getArguments());
                join.getCondition().setValue(newCond);
                bAddedToConj = true;
            }
        }
        if (!bAddedToConj) {
            AbstractFunctionCallExpression newCond = new ScalarFunctionCallExpression(context.getMetadataProvider().lookupFunction(AlgebricksBuiltinFunctions.AND), select.getCondition(), new MutableObject<ILogicalExpression>(join.getCondition().getValue()));
            join.getCondition().setValue(newCond);
        }
    }
}
Also used : ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) ScalarFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)

Example 43 with ScalarFunctionCallExpression

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

the class PushSelectIntoJoinRule method containsNotMissingFiltering.

/**
     * Whether the expression contains a not-missing filtering
     *
     * @param expr
     * @return true if the expression contains a not-missing filtering function call; false otherwise.
     */
private boolean containsNotMissingFiltering(ILogicalExpression expr) {
    if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
        return false;
    }
    ScalarFunctionCallExpression func = (ScalarFunctionCallExpression) expr;
    if (func.getFunctionIdentifier() == AlgebricksBuiltinFunctions.AND) {
        for (Mutable<ILogicalExpression> argumentRef : func.getArguments()) {
            if (containsNotMissingFiltering(argumentRef.getValue())) {
                return true;
            }
        }
        return false;
    }
    if (func.getFunctionIdentifier() != AlgebricksBuiltinFunctions.NOT) {
        return false;
    }
    ILogicalExpression arg = func.getArguments().get(0).getValue();
    if (arg.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
        return false;
    }
    ScalarFunctionCallExpression func2 = (ScalarFunctionCallExpression) arg;
    if (func2.getFunctionIdentifier() != AlgebricksBuiltinFunctions.IS_MISSING) {
        return false;
    }
    return true;
}
Also used : ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) ScalarFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)

Example 44 with ScalarFunctionCallExpression

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

the class IntroduceSecondaryIndexInsertDeleteRule method createFilterExpression.

private Mutable<ILogicalExpression> createFilterExpression(List<LogicalVariable> secondaryKeyVars, IVariableTypeEnvironment typeEnv, boolean forceFilter) throws AlgebricksException {
    List<Mutable<ILogicalExpression>> filterExpressions = new ArrayList<>();
    // condition.
    for (LogicalVariable secondaryKeyVar : secondaryKeyVars) {
        IAType secondaryKeyType = (IAType) typeEnv.getVarType(secondaryKeyVar);
        if (!NonTaggedFormatUtil.isOptional(secondaryKeyType) && !forceFilter) {
            continue;
        }
        ScalarFunctionCallExpression isUnknownFuncExpr = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.IS_UNKOWN), new MutableObject<ILogicalExpression>(new VariableReferenceExpression(secondaryKeyVar)));
        ScalarFunctionCallExpression notFuncExpr = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.NOT), new MutableObject<ILogicalExpression>(isUnknownFuncExpr));
        filterExpressions.add(new MutableObject<ILogicalExpression>(notFuncExpr));
    }
    // No nullable secondary keys.
    if (filterExpressions.isEmpty()) {
        return null;
    }
    Mutable<ILogicalExpression> filterExpression;
    if (filterExpressions.size() > 1) {
        // Create a conjunctive condition.
        filterExpression = new MutableObject<>(new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.AND), filterExpressions));
    } else {
        filterExpression = filterExpressions.get(0);
    }
    return filterExpression;
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) ArrayList(java.util.ArrayList) IAType(org.apache.asterix.om.types.IAType) ScalarFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)

Example 45 with ScalarFunctionCallExpression

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

the class IntroduceSecondaryIndexInsertDeleteRule method getOpenOrNestedFieldAccessFunction.

private static AbstractFunctionCallExpression getOpenOrNestedFieldAccessFunction(Mutable<ILogicalExpression> varRef, List<String> fields) {
    ScalarFunctionCallExpression func;
    if (fields.size() > 1) {
        IAObject fieldList = stringListToAOrderedList(fields);
        Mutable<ILogicalExpression> fieldRef = constantToMutableLogicalExpression(fieldList);
        // Create an expression for the nested case
        func = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.FIELD_ACCESS_NESTED), varRef, fieldRef);
    } else {
        IAObject fieldList = new AString(fields.get(0));
        Mutable<ILogicalExpression> fieldRef = constantToMutableLogicalExpression(fieldList);
        // Create an expression for the open field case (By name)
        func = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.FIELD_ACCESS_BY_NAME), varRef, fieldRef);
    }
    return func;
}
Also used : ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) IAObject(org.apache.asterix.om.base.IAObject) AString(org.apache.asterix.om.base.AString) ScalarFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)

Aggregations

ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)71 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)57 Mutable (org.apache.commons.lang3.mutable.Mutable)48 ArrayList (java.util.ArrayList)38 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)38 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)34 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)31 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)26 ConstantExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression)26 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)26 MutableObject (org.apache.commons.lang3.mutable.MutableObject)25 AsterixConstantValue (org.apache.asterix.om.constants.AsterixConstantValue)22 AString (org.apache.asterix.om.base.AString)14 IAType (org.apache.asterix.om.types.IAType)14 IFunctionInfo (org.apache.hyracks.algebricks.core.algebra.functions.IFunctionInfo)14 Pair (org.apache.hyracks.algebricks.common.utils.Pair)13 GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)10 AInt32 (org.apache.asterix.om.base.AInt32)10 SelectOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.SelectOperator)10 QuantifiedPair (org.apache.asterix.lang.common.struct.QuantifiedPair)8