@Test public final void testDropFunction() throws Exception { assertFalse(catalog.containFunction("test3", CatalogUtil.newSimpleDataTypeArray(Type.INT4))); FunctionDesc meta = new FunctionDesc( "test3", TestFunc1.class, FunctionType.UDF, CatalogUtil.newSimpleDataType(Type.INT4), CatalogUtil.newSimpleDataTypeArray(Type.INT4)); catalog.createFunction(meta); assertTrue(catalog.containFunction("test3", CatalogUtil.newSimpleDataTypeArray(Type.INT4))); catalog.dropFunction("test3"); assertFalse(catalog.containFunction("test3", CatalogUtil.newSimpleDataTypeArray(Type.INT4))); assertFalse( catalog.containFunction("test3", CatalogUtil.newSimpleDataTypeArray(Type.INT4, Type.BLOB))); FunctionDesc overload = new FunctionDesc( "test3", TestFunc2.class, FunctionType.GENERAL, CatalogUtil.newSimpleDataType(Type.INT4), CatalogUtil.newSimpleDataTypeArray(Type.INT4, Type.BLOB)); catalog.createFunction(overload); assertTrue( catalog.containFunction("test3", CatalogUtil.newSimpleDataTypeArray(Type.INT4, Type.BLOB))); }
@Test public final void testRegisterAndFindFunc() throws Exception { assertFalse(catalog.containFunction("test10", FunctionType.GENERAL)); FunctionDesc meta = new FunctionDesc( "test10", TestFunc2.class, FunctionType.GENERAL, CatalogUtil.newSimpleDataType(Type.INT4), CatalogUtil.newSimpleDataTypeArray(Type.INT4, Type.BLOB)); catalog.createFunction(meta); assertTrue( catalog.containFunction( "test10", CatalogUtil.newSimpleDataTypeArray(Type.INT4, Type.BLOB))); FunctionDesc retrived = catalog.getFunction("test10", CatalogUtil.newSimpleDataTypeArray(Type.INT4, Type.BLOB)); assertEquals(retrived.getFunctionName(), "test10"); assertEquals(retrived.getLegacyFuncClass(), TestFunc2.class); assertEquals(retrived.getFuncType(), FunctionType.GENERAL); assertFalse( catalog.containFunction( "test10", CatalogUtil.newSimpleDataTypeArray(Type.BLOB, Type.INT4))); }
@Test public final void testFindAnyTypeParamFunc() throws Exception { assertFalse(catalog.containFunction("testany", FunctionType.GENERAL)); FunctionDesc meta = new FunctionDesc( "testany", TestAnyParamFunc.class, FunctionType.GENERAL, CatalogUtil.newSimpleDataType(Type.INT4), CatalogUtil.newSimpleDataTypeArray(Type.ANY)); catalog.createFunction(meta); FunctionDesc retrieved = catalog.getFunction("testany", CatalogUtil.newSimpleDataTypeArray(Type.INT1)); assertEquals(retrieved.getFunctionName(), "testany"); assertEquals(retrieved.getParamTypes()[0], CatalogUtil.newSimpleDataType(Type.ANY)); retrieved = catalog.getFunction("testany", CatalogUtil.newSimpleDataTypeArray(Type.INT8)); assertEquals(retrieved.getFunctionName(), "testany"); assertEquals(retrieved.getParamTypes()[0], CatalogUtil.newSimpleDataType(Type.ANY)); retrieved = catalog.getFunction("testany", CatalogUtil.newSimpleDataTypeArray(Type.FLOAT4)); assertEquals(retrieved.getFunctionName(), "testany"); assertEquals(retrieved.getParamTypes()[0], CatalogUtil.newSimpleDataType(Type.ANY)); retrieved = catalog.getFunction("testany", CatalogUtil.newSimpleDataTypeArray(Type.TEXT)); assertEquals(retrieved.getFunctionName(), "testany"); assertEquals(retrieved.getParamTypes()[0], CatalogUtil.newSimpleDataType(Type.ANY)); }
@Test(expected = UndefinedFunctionException.class) public final void testFindIntInvalidFunc() throws Exception { assertFalse(catalog.containFunction("testintinvalid", FunctionType.GENERAL)); FunctionDesc meta = new FunctionDesc( "testintinvalid", TestIntFunc.class, FunctionType.GENERAL, CatalogUtil.newSimpleDataType(Type.INT4), CatalogUtil.newSimpleDataTypeArray(Type.INT4, Type.INT4)); catalog.createFunction(meta); // UPGRADE TO INT8 WILL FAIL ==> LOOK AT SECOND PARAM BELOW catalog.getFunction("testintinvalid", CatalogUtil.newSimpleDataTypeArray(Type.INT4, Type.INT8)); }
@Test(expected = UndefinedFunctionException.class) public final void testFindFloatInvalidFunc() throws Exception { assertFalse(catalog.containFunction("testfloatinvalid", FunctionType.GENERAL)); FunctionDesc meta = new FunctionDesc( "testfloatinvalid", TestFloatFunc.class, FunctionType.GENERAL, CatalogUtil.newSimpleDataType(Type.INT4), CatalogUtil.newSimpleDataTypeArray(Type.FLOAT8, Type.INT4)); catalog.createFunction(meta); // UPGRADE TO DECIMAL WILL FAIL ==> LOOK AT FIRST PARAM BELOW catalog.getFunction( "testfloatinvalid", CatalogUtil.newSimpleDataTypeArray(Type.NUMERIC, Type.INT4)); }
@Test public final void testFindIntFunc() throws Exception { assertFalse(catalog.containFunction("testint", FunctionType.GENERAL)); FunctionDesc meta = new FunctionDesc( "testint", TestIntFunc.class, FunctionType.GENERAL, CatalogUtil.newSimpleDataType(Type.INT4), CatalogUtil.newSimpleDataTypeArray(Type.INT4, Type.INT4)); catalog.createFunction(meta); // UPGRADE TO INT4 SUCCESS==> LOOK AT SECOND PARAM BELOW FunctionDesc retrieved = catalog.getFunction("testint", CatalogUtil.newSimpleDataTypeArray(Type.INT4, Type.INT2)); assertEquals(retrieved.getFunctionName(), "testint"); assertEquals(retrieved.getParamTypes()[0], CatalogUtil.newSimpleDataType(Type.INT4)); assertEquals(retrieved.getParamTypes()[1], CatalogUtil.newSimpleDataType(Type.INT4)); }