private void typeAffinity(String methodName, TypeInfo inputType, int expectedNumFoundMethods, Class expectedFoundType) { List<Method> mlist = getMethods(TestUDF.class, methodName); assertEquals(true, 1 < mlist.size()); List<TypeInfo> inputTypes = new ArrayList<TypeInfo>(); inputTypes.add(inputType); // narrow down the possible choices based on type affinity FunctionRegistry.filterMethodsByTypeAffinity(mlist, inputTypes); assertEquals(expectedNumFoundMethods, mlist.size()); if (expectedNumFoundMethods == 1) { assertEquals(expectedFoundType, mlist.get(0).getParameterTypes()[0]); } }
private void verify(Class udf, String name, TypeInfo ta, TypeInfo tb, Class a, Class b, boolean throwException) { List<TypeInfo> args = new LinkedList<TypeInfo>(); args.add(ta); args.add(tb); Method result = null; try { result = FunctionRegistry.getMethodInternal(udf, name, false, args); } catch (UDFArgumentException e) { assert(throwException); return; } assert(!throwException); assertEquals(2, result.getParameterTypes().length); assertEquals(a, result.getParameterTypes()[0]); assertEquals(b, result.getParameterTypes()[1]); }
private void unionAll(TypeInfo a, TypeInfo b, TypeInfo result) { assertEquals(result, FunctionRegistry.getCommonClassForUnionAll(a,b)); }
private void implicit(TypeInfo a, TypeInfo b, boolean convertible) { assertEquals(convertible, TypeInfoUtils.implicitConvertible(a, b)); }
private void comparison(TypeInfo a, TypeInfo b, TypeInfo result) { assertEquals(result, FunctionRegistry.getCommonClassForComparison(a,b)); }
private void common(TypeInfo a, TypeInfo b, TypeInfo result) { assertEquals(result, FunctionRegistry.getCommonClass(a,b)); }
public void testGetTypeInfoForPrimitiveCategory() { // varchar should take string length into account. // varchar(5), varchar(10) => varchar(10) assertEquals(varchar10, FunctionRegistry.getTypeInfoForPrimitiveCategory( (PrimitiveTypeInfo) varchar5, (PrimitiveTypeInfo) varchar10, PrimitiveCategory.VARCHAR)); assertEquals(varchar10, FunctionRegistry.getTypeInfoForPrimitiveCategory( (PrimitiveTypeInfo) varchar10, (PrimitiveTypeInfo) varchar5, PrimitiveCategory.VARCHAR)); assertEquals(char10, FunctionRegistry.getTypeInfoForPrimitiveCategory( (PrimitiveTypeInfo) char5, (PrimitiveTypeInfo) char10, PrimitiveCategory.CHAR)); assertEquals(char10, FunctionRegistry.getTypeInfoForPrimitiveCategory( (PrimitiveTypeInfo) char10, (PrimitiveTypeInfo) char5, PrimitiveCategory.CHAR)); assertEquals(varchar10, FunctionRegistry.getTypeInfoForPrimitiveCategory( (PrimitiveTypeInfo) varchar5, (PrimitiveTypeInfo) char10, PrimitiveCategory.VARCHAR)); // non-qualified types should simply return the TypeInfo associated with that type assertEquals(TypeInfoFactory.stringTypeInfo, FunctionRegistry.getTypeInfoForPrimitiveCategory( (PrimitiveTypeInfo) varchar10, TypeInfoFactory.stringTypeInfo, PrimitiveCategory.STRING)); assertEquals(TypeInfoFactory.stringTypeInfo, FunctionRegistry.getTypeInfoForPrimitiveCategory( TypeInfoFactory.stringTypeInfo, TypeInfoFactory.stringTypeInfo, PrimitiveCategory.STRING)); assertEquals(TypeInfoFactory.doubleTypeInfo, FunctionRegistry.getTypeInfoForPrimitiveCategory( TypeInfoFactory.doubleTypeInfo, TypeInfoFactory.stringTypeInfo, PrimitiveCategory.DOUBLE)); }