use of org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier in project asterixdb by apache.
the class PartialAggregationTypeComputer method getType.
@Override
public Object getType(ILogicalExpression expr, IVariableTypeEnvironment env, IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
AggregateFunctionCallExpression agg = (AggregateFunctionCallExpression) expr;
FunctionIdentifier partialFid = agg.getFunctionIdentifier();
if (partialFid.equals(BuiltinFunctions.SERIAL_GLOBAL_AVG)) {
partialFid = BuiltinFunctions.SERIAL_LOCAL_AVG;
}
AggregateFunctionCallExpression partialAgg = BuiltinFunctions.makeAggregateFunctionExpression(partialFid, agg.getArguments());
return getTypeForFunction(partialAgg, env, metadataProvider);
}
use of org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier in project asterixdb by apache.
the class BuiltinFunctions method isBuiltinCompilerFunction.
public static boolean isBuiltinCompilerFunction(FunctionSignature signature, boolean includePrivateFunctions) {
FunctionIdentifier fi = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, signature.getName(), signature.getArity());
IFunctionInfo finfo = getAsterixFunctionInfo(fi);
if (builtinPublicFunctionsSet.keySet().contains(finfo) || (includePrivateFunctions && builtinPrivateFunctionsSet.keySet().contains(finfo))) {
return true;
}
fi = new FunctionIdentifier(AlgebricksBuiltinFunctions.ALGEBRICKS_NS, signature.getName(), signature.getArity());
finfo = getAsterixFunctionInfo(fi);
if (builtinPublicFunctionsSet.keySet().contains(finfo) || (includePrivateFunctions && builtinPrivateFunctionsSet.keySet().contains(finfo))) {
return true;
}
return false;
}
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);
}
use of org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier in project asterixdb by apache.
the class FuzzyEqRule method expandFuzzyEq.
private boolean expandFuzzyEq(Mutable<ILogicalExpression> expRef, IOptimizationContext context, IVariableTypeEnvironment env, MetadataProvider metadataProvider) throws AlgebricksException {
ILogicalExpression exp = expRef.getValue();
if (exp.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
return false;
}
boolean expanded = false;
AbstractFunctionCallExpression funcExp = (AbstractFunctionCallExpression) exp;
FunctionIdentifier fi = funcExp.getFunctionIdentifier();
if (fi.equals(BuiltinFunctions.FUZZY_EQ)) {
List<Mutable<ILogicalExpression>> inputExps = funcExp.getArguments();
String simFuncName = FuzzyUtils.getSimFunction(metadataProvider);
ArrayList<Mutable<ILogicalExpression>> similarityArgs = new ArrayList<Mutable<ILogicalExpression>>();
for (int i = 0; i < inputExps.size(); ++i) {
Mutable<ILogicalExpression> inputExpRef = inputExps.get(i);
similarityArgs.add(inputExpRef);
}
FunctionIdentifier simFunctionIdentifier = FuzzyUtils.getFunctionIdentifier(simFuncName);
ScalarFunctionCallExpression similarityExp = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(simFunctionIdentifier), similarityArgs);
// Add annotations from the original fuzzy-eq function.
similarityExp.getAnnotations().putAll(funcExp.getAnnotations());
ArrayList<Mutable<ILogicalExpression>> cmpArgs = new ArrayList<Mutable<ILogicalExpression>>();
cmpArgs.add(new MutableObject<ILogicalExpression>(similarityExp));
IAObject simThreshold = FuzzyUtils.getSimThreshold(metadataProvider, simFuncName);
cmpArgs.add(new MutableObject<ILogicalExpression>(new ConstantExpression(new AsterixConstantValue(simThreshold))));
ScalarFunctionCallExpression cmpExpr = FuzzyUtils.getComparisonExpr(simFuncName, cmpArgs);
expRef.setValue(cmpExpr);
return true;
} else if (fi.equals(AlgebricksBuiltinFunctions.AND) || fi.equals(AlgebricksBuiltinFunctions.OR)) {
for (int i = 0; i < 2; i++) {
if (expandFuzzyEq(funcExp.getArguments().get(i), context, env, metadataProvider)) {
expanded = true;
}
}
}
return expanded;
}
Aggregations