xuefuz commented on a change in pull request #8212: [FLINK-11519][table] Add
function related catalog APIs
URL: https://github.com/apache/flink/pull/8212#discussion_r278722342
##########
File path:
flink-table/flink-table-api-java/src/test/java/org/apache/flink/table/catalog/GenericInMemoryCatalogTest.java
##########
@@ -562,6 +568,158 @@ public void testRenameView() throws Exception {
catalog.dropTable(viewPath2, false);
}
+ // ------ functions ------
+
+ @Test
+ public void testCreateFunction() throws Exception {
+ catalog.createDatabase(db1, createDb(), false);
+
+ assertFalse(catalog.functionExists(path1));
+
+ catalog.createFunction(path1, createFunction(), false);
+
+ assertTrue(catalog.functionExists(path1));
+
+ catalog.dropFunction(path1, false);
+ catalog.dropDatabase(db1, false);
+ }
+
+ @Test
+ public void testCreateFunction_DatabaseNotExistException() throws
Exception {
+ assertFalse(catalog.databaseExists(db1));
+
+ exception.expect(DatabaseNotExistException.class);
+ exception.expectMessage("Database db1 does not exist in
Catalog");
+ catalog.createFunction(path1, createFunction(), false);
+ }
+
+ @Test
+ public void testCreateFunction_FunctionAlreadyExistException() throws
Exception {
+ catalog.createDatabase(db1, createDb(), false);
+ catalog.createFunction(path1, createFunction(), false);
+
+ exception.expect(FunctionAlreadyExistException.class);
+ exception.expectMessage("Function db1.t1 already exists in
Catalog");
+ catalog.createFunction(path1, createFunction(), false);
+ }
+
+ @Test
+ public void testCreateFunction_FunctionAlreadyExist_ignored() throws
Exception {
+ catalog.createDatabase(db1, createDb(), false);
+
+ CatalogFunction func = createFunction();
+ catalog.createFunction(path1, func, false);
+
+ CatalogTestUtil.checkEquals(func, catalog.getFunction(path1));
+
+ catalog.createFunction(path1, createAnotherFunction(), true);
+
+ CatalogTestUtil.checkEquals(func, catalog.getFunction(path1));
+
+ catalog.dropFunction(path1, false);
+ catalog.dropDatabase(db1, false);
+ }
+
+ @Test
+ public void testAlterFunction() throws Exception {
+ catalog.createDatabase(db1, createDb(), false);
+
+ CatalogFunction func = createFunction();
+ catalog.createFunction(path1, func, false);
+
+ CatalogTestUtil.checkEquals(func, catalog.getFunction(path1));
+
+ CatalogFunction newFunc = createAnotherFunction();
+ catalog.alterFunction(path1, newFunc, false);
+
+ assertNotEquals(func, catalog.getFunction(path1));
+ CatalogTestUtil.checkEquals(newFunc,
catalog.getFunction(path1));
+
+ catalog.dropFunction(path1, false);
+ catalog.dropDatabase(db1, false);
+ }
+
+ @Test
+ public void testAlterFunction_FunctionNotExistException() throws
Exception {
+ exception.expect(FunctionNotExistException.class);
+ exception.expectMessage("Function db1.nonexist does not exist
in Catalog");
+ catalog.alterFunction(nonExistObjectPath, createFunction(),
false);
+ }
+
+ @Test
+ public void testAlterFunction_FunctionNotExist_ignored() throws
Exception {
+ catalog.createDatabase(db1, createDb(), false);
+ catalog.alterFunction(nonExistObjectPath, createFunction(),
true);
+
+ assertFalse(catalog.functionExists(nonExistObjectPath));
+
+ catalog.dropDatabase(db1, false);
+ }
+
+ @Test
+ public void testListFunctions() throws Exception {
+ catalog.createDatabase(db1, createDb(), false);
+
+ CatalogFunction func = createFunction();
+ catalog.createFunction(path1, func, false);
+
+ assertEquals(path1.getObjectName(),
catalog.listFunctions(db1).get(0));
+
+ catalog.dropFunction(path1, false);
+ catalog.dropDatabase(db1, false);
+ }
+
+ @Test
+ public void testListFunctions_DatabaseNotExistException() throws
Exception{
+ exception.expect(DatabaseNotExistException.class);
+ exception.expectMessage("Database db1 does not exist in
Catalog");
+ catalog.listFunctions(db1);
+ }
+
+ @Test
+ public void testGetFunction_FunctionNotExistException() throws
Exception {
+ catalog.createDatabase(db1, createDb(), false);
+
+ exception.expect(FunctionNotExistException.class);
+ exception.expectMessage("Function db1.nonexist does not exist
in Catalog");
+ catalog.getFunction(nonExistObjectPath);
+ }
+
+ @Test
+ public void testGetFunction_FunctionNotExistException_NoDb() throws
Exception {
+ exception.expect(FunctionNotExistException.class);
+ exception.expectMessage("Function db1.nonexist does not exist
in Catalog");
Review comment:
Same as above.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services