Search in sources :

Example 21 with IFunctionInfo

use of org.apache.hyracks.algebricks.core.algebra.functions.IFunctionInfo in project asterixdb by apache.

the class BuiltinFunctions method addPrivateFunction.

public static void addPrivateFunction(FunctionIdentifier fi, IResultTypeComputer typeComputer, boolean isFunctional) {
    IFunctionInfo functionInfo = new FunctionInfo(fi, isFunctional);
    builtinPrivateFunctionsSet.put(functionInfo, functionInfo);
    funTypeComputer.put(functionInfo, typeComputer);
    registeredFunctions.put(fi, functionInfo);
}
Also used : IFunctionInfo(org.apache.hyracks.algebricks.core.algebra.functions.IFunctionInfo) IFunctionInfo(org.apache.hyracks.algebricks.core.algebra.functions.IFunctionInfo)

Example 22 with IFunctionInfo

use of org.apache.hyracks.algebricks.core.algebra.functions.IFunctionInfo in project asterixdb by apache.

the class ExternalFunctionCompilerUtil method getExternalFunctionInfo.

public static IFunctionInfo getExternalFunctionInfo(MetadataTransactionContext txnCtx, Function function) throws MetadataException {
    String functionKind = function.getKind();
    IFunctionInfo finfo = null;
    if (FunctionKind.SCALAR.toString().equalsIgnoreCase(functionKind)) {
        finfo = getScalarFunctionInfo(txnCtx, function);
    } else if (FunctionKind.AGGREGATE.toString().equalsIgnoreCase(functionKind)) {
        finfo = getAggregateFunctionInfo(txnCtx, function);
    } else if (FunctionKind.STATEFUL.toString().equalsIgnoreCase(functionKind)) {
        finfo = getStatefulFunctionInfo(txnCtx, function);
    } else if (FunctionKind.UNNEST.toString().equalsIgnoreCase(functionKind)) {
        finfo = getUnnestFunctionInfo(txnCtx, function);
    }
    return finfo;
}
Also used : IFunctionInfo(org.apache.hyracks.algebricks.core.algebra.functions.IFunctionInfo)

Example 23 with IFunctionInfo

use of org.apache.hyracks.algebricks.core.algebra.functions.IFunctionInfo in project asterixdb by apache.

the class DisjunctivePredicateToJoinRule method rewritePost.

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    MetadataProvider metadataProvider = (MetadataProvider) context.getMetadataProvider();
    if (metadataProvider.isBlockingOperatorDisabled()) {
        return false;
    }
    SelectOperator select;
    if ((select = asSelectOperator(opRef)) == null) {
        return false;
    }
    AbstractFunctionCallExpression condEx;
    if ((condEx = asFunctionCallExpression(select.getCondition(), AlgebricksBuiltinFunctions.OR)) == null) {
        return false;
    }
    List<Mutable<ILogicalExpression>> args = condEx.getArguments();
    VariableReferenceExpression varEx = null;
    IAType valType = null;
    HashSet<AsterixConstantValue> values = new HashSet<AsterixConstantValue>();
    for (Mutable<ILogicalExpression> arg : args) {
        AbstractFunctionCallExpression fctCall;
        if ((fctCall = asFunctionCallExpression(arg, AlgebricksBuiltinFunctions.EQ)) == null) {
            return false;
        }
        boolean haveConst = false;
        boolean haveVar = false;
        List<Mutable<ILogicalExpression>> fctArgs = fctCall.getArguments();
        for (Mutable<ILogicalExpression> fctArg : fctArgs) {
            final ILogicalExpression argExpr = fctArg.getValue();
            switch(argExpr.getExpressionTag()) {
                case CONSTANT:
                    haveConst = true;
                    AsterixConstantValue value = (AsterixConstantValue) ((ConstantExpression) argExpr).getValue();
                    if (valType == null) {
                        valType = value.getObject().getType();
                    } else if (!isCompatible(valType, value.getObject().getType())) {
                        return false;
                    }
                    values.add(value);
                    break;
                case VARIABLE:
                    haveVar = true;
                    final VariableReferenceExpression varArg = (VariableReferenceExpression) argExpr;
                    if (varEx == null) {
                        varEx = varArg;
                    } else if (!varEx.getVariableReference().equals(varArg.getVariableReference())) {
                        return false;
                    }
                    break;
                default:
                    return false;
            }
        }
        if (!(haveVar && haveConst)) {
            return false;
        }
    }
    AOrderedList list = new AOrderedList(new AOrderedListType(valType, "orderedlist"));
    for (AsterixConstantValue value : values) {
        list.add(value.getObject());
    }
    EmptyTupleSourceOperator ets = new EmptyTupleSourceOperator();
    context.computeAndSetTypeEnvironmentForOperator(ets);
    ILogicalExpression cExp = new ConstantExpression(new AsterixConstantValue(list));
    Mutable<ILogicalExpression> mutCExp = new MutableObject<>(cExp);
    IFunctionInfo scanFctInfo = BuiltinFunctions.getAsterixFunctionInfo(BuiltinFunctions.SCAN_COLLECTION);
    UnnestingFunctionCallExpression scanExp = new UnnestingFunctionCallExpression(scanFctInfo, mutCExp);
    LogicalVariable scanVar = context.newVar();
    UnnestOperator unn = new UnnestOperator(scanVar, new MutableObject<>(scanExp));
    unn.getInputs().add(new MutableObject<>(ets));
    context.computeAndSetTypeEnvironmentForOperator(unn);
    IFunctionInfo eqFctInfo = BuiltinFunctions.getAsterixFunctionInfo(AlgebricksBuiltinFunctions.EQ);
    AbstractFunctionCallExpression eqExp = new ScalarFunctionCallExpression(eqFctInfo);
    eqExp.getArguments().add(new MutableObject<>(new VariableReferenceExpression(scanVar)));
    eqExp.getArguments().add(new MutableObject<>(varEx.cloneExpression()));
    eqExp.getAnnotations().put(IndexedNLJoinExpressionAnnotation.INSTANCE, IndexedNLJoinExpressionAnnotation.INSTANCE);
    BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
    // Broadcast the OR predicates branch.
    bcast.setObject(BroadcastExpressionAnnotation.BroadcastSide.LEFT);
    eqExp.getAnnotations().put(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY, bcast);
    InnerJoinOperator jOp = new InnerJoinOperator(new MutableObject<>(eqExp));
    jOp.getInputs().add(new MutableObject<>(unn));
    jOp.getInputs().add(select.getInputs().get(0));
    opRef.setValue(jOp);
    context.computeAndSetTypeEnvironmentForOperator(jOp);
    return true;
}
Also used : IFunctionInfo(org.apache.hyracks.algebricks.core.algebra.functions.IFunctionInfo) ConstantExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression) InnerJoinOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator) UnnestOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.UnnestOperator) SelectOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.SelectOperator) AOrderedList(org.apache.asterix.om.base.AOrderedList) AsterixConstantValue(org.apache.asterix.om.constants.AsterixConstantValue) BroadcastExpressionAnnotation(org.apache.hyracks.algebricks.core.algebra.expressions.BroadcastExpressionAnnotation) EmptyTupleSourceOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.EmptyTupleSourceOperator) HashSet(java.util.HashSet) MutableObject(org.apache.commons.lang3.mutable.MutableObject) ScalarFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression) LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) UnnestingFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.UnnestingFunctionCallExpression) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) AOrderedListType(org.apache.asterix.om.types.AOrderedListType) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) MetadataProvider(org.apache.asterix.metadata.declared.MetadataProvider) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) IAType(org.apache.asterix.om.types.IAType)

Example 24 with IFunctionInfo

use of org.apache.hyracks.algebricks.core.algebra.functions.IFunctionInfo in project asterixdb by apache.

the class FunctionMapUtil method isCoreAggregateFunction.

/**
     * Whether a function signature is a SQL++ core aggregate function.
     *
     * @param fs,
     *            the function signature.
     * @return true if the function signature is a SQL++ core aggregate,
     *         false otherwise.
     */
public static boolean isCoreAggregateFunction(FunctionSignature fs) {
    String name = fs.getName().toLowerCase();
    boolean coreAgg = name.startsWith(CORE_AGGREGATE_PREFIX);
    boolean coreSqlAgg = name.startsWith(CORE_SQL_AGGREGATE_PREFIX);
    if (!coreAgg && !coreSqlAgg) {
        return false;
    }
    String internalName = coreAgg ? name.substring(CORE_AGGREGATE_PREFIX.length()) : (INTERNAL_SQL_AGGREGATE_PREFIX + name.substring(CORE_SQL_AGGREGATE_PREFIX.length()));
    IFunctionInfo finfo = FunctionUtil.getFunctionInfo(new FunctionIdentifier(FunctionConstants.ASTERIX_NS, internalName, fs.getArity()));
    if (finfo == null) {
        return false;
    }
    return BuiltinFunctions.getAggregateFunction(finfo.getFunctionIdentifier()) != null;
}
Also used : FunctionIdentifier(org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier) IFunctionInfo(org.apache.hyracks.algebricks.core.algebra.functions.IFunctionInfo)

Aggregations

IFunctionInfo (org.apache.hyracks.algebricks.core.algebra.functions.IFunctionInfo)24 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)14 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)13 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)12 Mutable (org.apache.commons.lang3.mutable.Mutable)11 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)11 MutableObject (org.apache.commons.lang3.mutable.MutableObject)10 ArrayList (java.util.ArrayList)9 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)9 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)7 AggregateFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AggregateFunctionCallExpression)5 UnnestingFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.UnnestingFunctionCallExpression)5 IAObject (org.apache.asterix.om.base.IAObject)4 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)4 ConstantExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression)4 FunctionIdentifier (org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier)4 AbstractUnnestMapOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractUnnestMapOperator)4 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)4 HashSet (java.util.HashSet)3 AOrderedList (org.apache.asterix.om.base.AOrderedList)3