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);
}
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();
}
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);
}
}
}
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;
}
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);
}
Aggregations