Search in sources :

Example 46 with FunctionIdentifier

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

the class FunctionManagerImpl method registerFunction.

@Override
public synchronized void registerFunction(IFunctionDescriptorFactory descriptorFactory) throws AlgebricksException {
    FunctionIdentifier fid = descriptorFactory.createFunctionDescriptor().getIdentifier();
    functions.put(new Pair<FunctionIdentifier, Integer>(fid, fid.getArity()), descriptorFactory);
}
Also used : FunctionIdentifier(org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier)

Example 47 with FunctionIdentifier

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

the class FunctionManagerImpl method lookupFunction.

@Override
public synchronized IFunctionDescriptor lookupFunction(FunctionIdentifier fid) throws AlgebricksException {
    Pair<FunctionIdentifier, Integer> key = new Pair<>(fid, fid.getArity());
    IFunctionDescriptorFactory factory = functions.get(key);
    if (factory == null) {
        throw new AlgebricksException("Inappropriate use of function " + "'" + fid.getName() + "'");
    }
    return factory.createFunctionDescriptor();
}
Also used : FunctionIdentifier(org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier) IFunctionDescriptorFactory(org.apache.asterix.om.functions.IFunctionDescriptorFactory) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Example 48 with FunctionIdentifier

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

the class AbstractFunctionCallExpression method getConstraintsAndEquivClasses.

@Override
public void getConstraintsAndEquivClasses(Collection<FunctionalDependency> fds, Map<LogicalVariable, EquivalenceClass> equivClasses) {
    FunctionIdentifier funId = getFunctionIdentifier();
    if (funId.equals(AlgebricksBuiltinFunctions.AND)) {
        for (Mutable<ILogicalExpression> a : arguments) {
            a.getValue().getConstraintsAndEquivClasses(fds, equivClasses);
        }
    } else if (funId.equals(AlgebricksBuiltinFunctions.EQ)) {
        ILogicalExpression opLeft = arguments.get(0).getValue();
        ILogicalExpression opRight = arguments.get(1).getValue();
        if (opLeft.getExpressionTag() == LogicalExpressionTag.CONSTANT && opRight.getExpressionTag() == LogicalExpressionTag.VARIABLE) {
            ConstantExpression op1 = (ConstantExpression) opLeft;
            VariableReferenceExpression op2 = (VariableReferenceExpression) opRight;
            getFDsAndEquivClassesForEqWithConstant(op1, op2, fds, equivClasses);
        } else if (opLeft.getExpressionTag() == LogicalExpressionTag.VARIABLE && opRight.getExpressionTag() == LogicalExpressionTag.VARIABLE) {
            VariableReferenceExpression op1 = (VariableReferenceExpression) opLeft;
            VariableReferenceExpression op2 = (VariableReferenceExpression) opRight;
            getFDsAndEquivClassesForColumnEq(op1, op2, fds, equivClasses);
        }
    }
}
Also used : FunctionIdentifier(org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)

Example 49 with FunctionIdentifier

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

the class TypeComputerTest method testTypeComputer.

private boolean testTypeComputer(Class<? extends IResultTypeComputer> c) throws Exception {
    // Mocks the type environment.
    IVariableTypeEnvironment mockTypeEnv = mock(IVariableTypeEnvironment.class);
    // Mocks the metadata provider.
    IMetadataProvider<?, ?> mockMetadataProvider = mock(IMetadataProvider.class);
    // Mocks function expression.
    AbstractFunctionCallExpression mockExpr = mock(AbstractFunctionCallExpression.class);
    FunctionIdentifier fid = mock(FunctionIdentifier.class);
    when(mockExpr.getFunctionIdentifier()).thenReturn(fid);
    when(fid.getName()).thenReturn("testFunction");
    // A function at most has six argument.
    List<Mutable<ILogicalExpression>> argRefs = new ArrayList<>();
    for (int argIndex = 0; argIndex < 6; ++argIndex) {
        ILogicalExpression mockArg = mock(ILogicalExpression.class);
        argRefs.add(new MutableObject<>(mockArg));
        when(mockTypeEnv.getType(mockArg)).thenReturn(BuiltinType.ANY);
    }
    // Sets up arguments for the mocked expression.
    when(mockExpr.getArguments()).thenReturn(argRefs);
    // Sets up required/actual types of the mocked expression.
    Object[] opaqueParameters = new Object[2];
    opaqueParameters[0] = BuiltinType.ANY;
    opaqueParameters[1] = BuiltinType.ANY;
    when(mockExpr.getOpaqueParameters()).thenReturn(opaqueParameters);
    // Tests the return type. It should be either ANY or NULLABLE/MISSABLE.
    IResultTypeComputer instance = (IResultTypeComputer) c.getField("INSTANCE").get(null);
    IAType resultType = instance.computeType(mockExpr, mockTypeEnv, mockMetadataProvider);
    ATypeTag typeTag = resultType.getTypeTag();
    if (typeTag == ATypeTag.ANY) {
        return true;
    }
    if (typeTag == ATypeTag.UNION) {
        AUnionType unionType = (AUnionType) resultType;
        return unionType.isMissableType() && unionType.isNullableType();
    }
    return false;
}
Also used : IResultTypeComputer(org.apache.asterix.om.typecomputer.base.IResultTypeComputer) AUnionType(org.apache.asterix.om.types.AUnionType) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) ArrayList(java.util.ArrayList) 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) ATypeTag(org.apache.asterix.om.types.ATypeTag) MutableObject(org.apache.commons.lang3.mutable.MutableObject) IVariableTypeEnvironment(org.apache.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment) IAType(org.apache.asterix.om.types.IAType)

Example 50 with FunctionIdentifier

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

the class ExternalFunctionCompilerUtil method getScalarFunctionInfo.

private static IFunctionInfo getScalarFunctionInfo(MetadataTransactionContext txnCtx, Function function) throws MetadataException {
    FunctionIdentifier fid = new FunctionIdentifier(function.getDataverseName(), function.getName(), function.getArity());
    IResultTypeComputer typeComputer = getResultTypeComputer(txnCtx, function);
    List<IAType> arguments = new ArrayList<IAType>();
    IAType returnType = null;
    List<String> paramTypes = function.getParams();
    for (String paramType : paramTypes) {
        arguments.add(getTypeInfo(paramType, txnCtx, function));
    }
    returnType = getTypeInfo(function.getReturnType(), txnCtx, function);
    return new ExternalScalarFunctionInfo(fid.getNamespace(), fid.getName(), fid.getArity(), returnType, function.getFunctionBody(), function.getLanguage(), arguments, typeComputer);
}
Also used : IResultTypeComputer(org.apache.asterix.om.typecomputer.base.IResultTypeComputer) FunctionIdentifier(org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier) ArrayList(java.util.ArrayList) IAType(org.apache.asterix.om.types.IAType)

Aggregations

FunctionIdentifier (org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier)50 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)33 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)31 ArrayList (java.util.ArrayList)15 Mutable (org.apache.commons.lang3.mutable.Mutable)14 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)13 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)11 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)10 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)10 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)10 MetadataProvider (org.apache.asterix.metadata.declared.MetadataProvider)7 IAType (org.apache.asterix.om.types.IAType)7 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)7 List (java.util.List)6 MutableObject (org.apache.commons.lang3.mutable.MutableObject)6 AggregateFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AggregateFunctionCallExpression)6 ConstantExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression)6 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)6 AString (org.apache.asterix.om.base.AString)5 Pair (org.apache.hyracks.algebricks.common.utils.Pair)5