Java Code Examples for org.apache.flink.table.client.gateway.Executor#useCatalog()
The following examples show how to use
org.apache.flink.table.client.gateway.Executor#useCatalog() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalExecutorITCase.java From flink with Apache License 2.0 | 6 votes |
@Test public void testAlterTable() throws Exception { final Executor executor = createDefaultExecutor(clusterClient); final LocalExecutor localExecutor = (LocalExecutor) executor; final SessionContext session = new SessionContext("test-session", new Environment()); String sessionId = executor.openSession(session); assertEquals("test-session", sessionId); executor.useCatalog(sessionId, "simple-catalog"); executor.useDatabase(sessionId, "default_database"); List<String> actualTables = executor.listTables(sessionId); List<String> expectedTables = Arrays.asList("test-table"); assertEquals(expectedTables, actualTables); executor.executeUpdate(sessionId, "alter table `test-table` rename to t1"); actualTables = executor.listTables(sessionId); expectedTables = Arrays.asList("t1"); assertEquals(expectedTables, actualTables); //todo: we should add alter table set test when we support create table in executor. executor.closeSession(sessionId); }
Example 2
Source File: LocalExecutorITCase.java From flink with Apache License 2.0 | 5 votes |
@Test public void testUseCatalogAndUseDatabase() throws Exception { final String csvOutputPath = new File(tempFolder.newFolder().getAbsolutePath(), "test-out.csv").toURI().toString(); final URL url = getClass().getClassLoader().getResource("test-data.csv"); Objects.requireNonNull(url); final Map<String, String> replaceVars = new HashMap<>(); replaceVars.put("$VAR_PLANNER", planner); replaceVars.put("$VAR_SOURCE_PATH1", url.getPath()); replaceVars.put("$VAR_EXECUTION_TYPE", "streaming"); replaceVars.put("$VAR_SOURCE_SINK_PATH", csvOutputPath); replaceVars.put("$VAR_UPDATE_MODE", "update-mode: append"); replaceVars.put("$VAR_MAX_ROWS", "100"); final Executor executor = createModifiedExecutor(CATALOGS_ENVIRONMENT_FILE, clusterClient, replaceVars); final SessionContext session = new SessionContext("test-session", new Environment()); try { assertEquals(Arrays.asList("mydatabase"), executor.listDatabases(session)); executor.useCatalog(session, "hivecatalog"); assertEquals( Arrays.asList(DependencyTest.TestHiveCatalogFactory.ADDITIONAL_TEST_DATABASE, HiveCatalog.DEFAULT_DB), executor.listDatabases(session)); assertEquals(Collections.emptyList(), executor.listTables(session)); executor.useDatabase(session, DependencyTest.TestHiveCatalogFactory.ADDITIONAL_TEST_DATABASE); assertEquals(Arrays.asList(DependencyTest.TestHiveCatalogFactory.TEST_TABLE), executor.listTables(session)); } finally { executor.stop(session); } }
Example 3
Source File: LocalExecutorITCase.java From flink with Apache License 2.0 | 5 votes |
@Test public void testUseNonExistingCatalog() throws Exception { final Executor executor = createDefaultExecutor(clusterClient); final SessionContext session = new SessionContext("test-session", new Environment()); exception.expect(SqlExecutionException.class); executor.useCatalog(session, "nonexistingcatalog"); }
Example 4
Source File: LocalExecutorITCase.java From flink with Apache License 2.0 | 5 votes |
@Test public void testUseCatalogAndUseDatabase() throws Exception { final String csvOutputPath = new File(tempFolder.newFolder().getAbsolutePath(), "test-out.csv").toURI().toString(); final URL url1 = getClass().getClassLoader().getResource("test-data.csv"); final URL url2 = getClass().getClassLoader().getResource("test-data-1.csv"); Objects.requireNonNull(url1); Objects.requireNonNull(url2); final Map<String, String> replaceVars = new HashMap<>(); replaceVars.put("$VAR_PLANNER", planner); replaceVars.put("$VAR_SOURCE_PATH1", url1.getPath()); replaceVars.put("$VAR_SOURCE_PATH2", url2.getPath()); replaceVars.put("$VAR_EXECUTION_TYPE", "streaming"); replaceVars.put("$VAR_SOURCE_SINK_PATH", csvOutputPath); replaceVars.put("$VAR_UPDATE_MODE", "update-mode: append"); replaceVars.put("$VAR_MAX_ROWS", "100"); final Executor executor = createModifiedExecutor(CATALOGS_ENVIRONMENT_FILE, clusterClient, replaceVars); final SessionContext session = new SessionContext("test-session", new Environment()); String sessionId = executor.openSession(session); assertEquals("test-session", sessionId); try { assertEquals(Collections.singletonList("mydatabase"), executor.listDatabases(sessionId)); executor.useCatalog(sessionId, "hivecatalog"); assertEquals( Arrays.asList(DependencyTest.TestHiveCatalogFactory.ADDITIONAL_TEST_DATABASE, HiveCatalog.DEFAULT_DB), executor.listDatabases(sessionId)); assertEquals(Collections.singletonList(DependencyTest.TestHiveCatalogFactory.TABLE_WITH_PARAMETERIZED_TYPES), executor.listTables(sessionId)); executor.useDatabase(sessionId, DependencyTest.TestHiveCatalogFactory.ADDITIONAL_TEST_DATABASE); assertEquals(Collections.singletonList(DependencyTest.TestHiveCatalogFactory.TEST_TABLE), executor.listTables(sessionId)); } finally { executor.closeSession(sessionId); } }
Example 5
Source File: LocalExecutorITCase.java From flink with Apache License 2.0 | 5 votes |
@Test public void testUseNonExistingCatalog() throws Exception { final Executor executor = createDefaultExecutor(clusterClient); final SessionContext session = new SessionContext("test-session", new Environment()); String sessionId = executor.openSession(session); assertEquals("test-session", sessionId); exception.expect(SqlExecutionException.class); executor.useCatalog(sessionId, "nonexistingcatalog"); executor.closeSession(sessionId); }
Example 6
Source File: LocalExecutorITCase.java From flink with Apache License 2.0 | 5 votes |
@Test public void testParameterizedTypes() throws Exception { // only blink planner supports parameterized types Assume.assumeTrue(planner.equals("blink")); final URL url1 = getClass().getClassLoader().getResource("test-data.csv"); final URL url2 = getClass().getClassLoader().getResource("test-data-1.csv"); Objects.requireNonNull(url1); Objects.requireNonNull(url2); final Map<String, String> replaceVars = new HashMap<>(); replaceVars.put("$VAR_PLANNER", planner); replaceVars.put("$VAR_SOURCE_PATH1", url1.getPath()); replaceVars.put("$VAR_SOURCE_PATH2", url2.getPath()); replaceVars.put("$VAR_EXECUTION_TYPE", "batch"); replaceVars.put("$VAR_UPDATE_MODE", "update-mode: append"); replaceVars.put("$VAR_MAX_ROWS", "100"); replaceVars.put("$VAR_RESULT_MODE", "table"); final Executor executor = createModifiedExecutor(CATALOGS_ENVIRONMENT_FILE, clusterClient, replaceVars); final SessionContext session = new SessionContext("test-session", new Environment()); String sessionId = executor.openSession(session); assertEquals("test-session", sessionId); executor.useCatalog(sessionId, "hivecatalog"); String resultID = executor.executeQuery(sessionId, "select * from " + DependencyTest.TestHiveCatalogFactory.TABLE_WITH_PARAMETERIZED_TYPES).getResultId(); retrieveTableResult(executor, sessionId, resultID); // make sure legacy types still work executor.useCatalog(sessionId, "default_catalog"); resultID = executor.executeQuery(sessionId, "select * from TableNumber3").getResultId(); retrieveTableResult(executor, sessionId, resultID); executor.closeSession(sessionId); }
Example 7
Source File: LocalExecutorITCase.java From flink with Apache License 2.0 | 5 votes |
@Test public void testCreateTable() throws Exception { final Executor executor = createDefaultExecutor(clusterClient); final SessionContext session = new SessionContext("test-session", new Environment()); String sessionId = executor.openSession(session); final String ddlTemplate = "create table %s(\n" + " a int,\n" + " b bigint,\n" + " c varchar\n" + ") with (\n" + " 'connector.type'='filesystem',\n" + " 'format.type'='csv',\n" + " 'connector.path'='xxx'\n" + ")\n"; try { // Test create table with simple name. executor.useCatalog(sessionId, "catalog1"); executor.createTable(sessionId, String.format(ddlTemplate, "MyTable1")); assertEquals(Collections.singletonList("MyTable1"), executor.listTables(sessionId)); executor.createTable(sessionId, String.format(ddlTemplate, "MyTable2")); assertEquals(Arrays.asList("MyTable1", "MyTable2"), executor.listTables(sessionId)); // Test create table with full qualified name. executor.useCatalog(sessionId, "catalog1"); executor.createTable(sessionId, String.format(ddlTemplate, "`simple-catalog`.`default_database`.MyTable3")); executor.createTable(sessionId, String.format(ddlTemplate, "`simple-catalog`.`default_database`.MyTable4")); assertEquals(Arrays.asList("MyTable1", "MyTable2"), executor.listTables(sessionId)); executor.useCatalog(sessionId, "simple-catalog"); assertEquals(Arrays.asList("MyTable3", "MyTable4", "test-table"), executor.listTables(sessionId)); // Test create table with db and table name. executor.useCatalog(sessionId, "catalog1"); executor.createTable(sessionId, String.format(ddlTemplate, "`default`.MyTable5")); executor.createTable(sessionId, String.format(ddlTemplate, "`default`.MyTable6")); assertEquals(Arrays.asList("MyTable1", "MyTable2", "MyTable5", "MyTable6"), executor.listTables(sessionId)); } finally { executor.closeSession(sessionId); } }
Example 8
Source File: LocalExecutorITCase.java From flink with Apache License 2.0 | 5 votes |
@Test @Ignore // TODO: reopen when FLINK-15075 was fixed. public void testCreateTableWithComputedColumn() throws Exception { Assume.assumeTrue(planner.equals("blink")); final Map<String, String> replaceVars = new HashMap<>(); replaceVars.put("$VAR_PLANNER", planner); replaceVars.put("$VAR_SOURCE_PATH1", "file:///fakePath1"); replaceVars.put("$VAR_SOURCE_PATH2", "file:///fakePath2"); replaceVars.put("$VAR_EXECUTION_TYPE", "batch"); replaceVars.put("$VAR_UPDATE_MODE", "update-mode: append"); replaceVars.put("$VAR_MAX_ROWS", "100"); replaceVars.put("$VAR_RESULT_MODE", "table"); final Executor executor = createModifiedExecutor(clusterClient, replaceVars); final String ddlTemplate = "create table %s(\n" + " a int,\n" + " b bigint,\n" + " c as a + 1\n" + ") with (\n" + " 'connector.type'='filesystem',\n" + " 'format.type'='csv',\n" + " 'connector.path'='xxx'\n" + ")\n"; final SessionContext session = new SessionContext("test-session", new Environment()); String sessionId = executor.openSession(session); try { executor.useCatalog(sessionId, "catalog1"); executor.createTable(sessionId, String.format(ddlTemplate, "MyTable1")); assertEquals(Collections.singletonList("MyTable1"), executor.listTables(sessionId)); executor.createTable(sessionId, String.format(ddlTemplate, "MyTable2")); assertEquals(Arrays.asList("MyTable1", "MyTable2"), executor.listTables(sessionId)); } finally { executor.closeSession(sessionId); } }
Example 9
Source File: LocalExecutorITCase.java From flink with Apache License 2.0 | 5 votes |
@Test @Ignore // TODO: reopen when FLINK-15075 was fixed. public void testCreateTableWithWatermark() throws Exception { final Map<String, String> replaceVars = new HashMap<>(); replaceVars.put("$VAR_PLANNER", planner); replaceVars.put("$VAR_SOURCE_PATH1", "file:///fakePath1"); replaceVars.put("$VAR_SOURCE_PATH2", "file:///fakePath2"); replaceVars.put("$VAR_EXECUTION_TYPE", "batch"); replaceVars.put("$VAR_UPDATE_MODE", "update-mode: append"); replaceVars.put("$VAR_MAX_ROWS", "100"); replaceVars.put("$VAR_RESULT_MODE", "table"); final Executor executor = createModifiedExecutor(clusterClient, replaceVars); final String ddlTemplate = "create table %s(\n" + " a int,\n" + " b timestamp(3),\n" + " watermark for b as b - INTERVAL '5' second\n" + ") with (\n" + " 'connector.type'='filesystem',\n" + " 'format.type'='csv',\n" + " 'connector.path'='xxx'\n" + ")\n"; final SessionContext session = new SessionContext("test-session", new Environment()); String sessionId = executor.openSession(session); try { executor.useCatalog(sessionId, "catalog1"); executor.createTable(sessionId, String.format(ddlTemplate, "MyTable1")); assertEquals(Collections.singletonList("MyTable1"), executor.listTables(sessionId)); executor.createTable(sessionId, String.format(ddlTemplate, "MyTable2")); assertEquals(Arrays.asList("MyTable1", "MyTable2"), executor.listTables(sessionId)); } finally { executor.closeSession(sessionId); } }
Example 10
Source File: LocalExecutorITCase.java From flink with Apache License 2.0 | 5 votes |
@Test public void testCreateTableWithPropertiesChanged() throws Exception { final Executor executor = createDefaultExecutor(clusterClient); final SessionContext session = new SessionContext("test-session", new Environment()); String sessionId = executor.openSession(session); try { executor.useCatalog(sessionId, "catalog1"); executor.setSessionProperty(sessionId, "execution.type", "batch"); final String ddlTemplate = "create table %s(\n" + " a int,\n" + " b bigint,\n" + " c varchar\n" + ") with (\n" + " 'connector.type'='filesystem',\n" + " 'format.type'='csv',\n" + " 'connector.path'='xxx',\n" + " 'update-mode'='append'\n" + ")\n"; executor.createTable(sessionId, String.format(ddlTemplate, "MyTable1")); // Change the session property to trigger `new ExecutionContext`. executor.setSessionProperty(sessionId, "execution.restart-strategy.failure-rate-interval", "12345"); executor.createTable(sessionId, String.format(ddlTemplate, "MyTable2")); assertEquals(Arrays.asList("MyTable1", "MyTable2"), executor.listTables(sessionId)); // Reset the session properties. executor.resetSessionProperties(sessionId); executor.createTable(sessionId, String.format(ddlTemplate, "MyTable3")); assertEquals(Arrays.asList("MyTable1", "MyTable2", "MyTable3"), executor.listTables(sessionId)); } finally { executor.closeSession(sessionId); } }
Example 11
Source File: LocalExecutorITCase.java From flink with Apache License 2.0 | 5 votes |
@Test public void testCreateFunction() throws Exception { final Executor executor = createDefaultExecutor(clusterClient); final SessionContext session = new SessionContext("test-session", new Environment()); String sessionId = executor.openSession(session); // arguments: [TEMPORARY|TEMPORARY SYSTEM], [IF NOT EXISTS], func_name final String ddlTemplate = "create %s function %s %s \n" + "as 'org.apache.flink.table.client.gateway.local.LocalExecutorITCase$TestScalaFunction' LANGUAGE JAVA"; try { // Test create table with simple name. executor.useCatalog(sessionId, "catalog1"); executor.executeSql(sessionId, String.format(ddlTemplate, "", "", "func1")); assertThat(executor.listFunctions(sessionId), hasItems("func1")); executor.executeSql(sessionId, String.format(ddlTemplate, "TEMPORARY", "IF NOT EXISTS", "func2")); assertThat(executor.listFunctions(sessionId), hasItems("func1", "func2")); // Test create function with full qualified name. executor.useCatalog(sessionId, "catalog1"); executor.createTable(sessionId, String.format(ddlTemplate, "", "", "`simple-catalog`.`default_database`.func3")); executor.createTable(sessionId, String.format(ddlTemplate, "TEMPORARY", "IF NOT EXISTS", "`simple-catalog`.`default_database`.func4")); assertThat(executor.listFunctions(sessionId), hasItems("func1", "func2")); executor.useCatalog(sessionId, "simple-catalog"); assertThat(executor.listFunctions(sessionId), hasItems("func3", "func4")); // Test create function with db and table name. executor.useCatalog(sessionId, "catalog1"); executor.createTable(sessionId, String.format(ddlTemplate, "TEMPORARY", "", "`default`.func5")); executor.createTable(sessionId, String.format(ddlTemplate, "TEMPORARY", "", "`default`.func6")); assertThat(executor.listFunctions(sessionId), hasItems("func1", "func2", "func5", "func6")); } finally { executor.closeSession(sessionId); } }
Example 12
Source File: LocalExecutorITCase.java From flink with Apache License 2.0 | 5 votes |
@Test public void testAlterFunction() throws Exception { final Executor executor = createDefaultExecutor(clusterClient); final SessionContext session = new SessionContext("test-session", new Environment()); String sessionId = executor.openSession(session); try { executor.useCatalog(sessionId, "catalog1"); executor.setSessionProperty(sessionId, "execution.type", "batch"); // arguments: [TEMPORARY|TEMPORARY SYSTEM], [IF NOT EXISTS], func_name final String createTemplate = "create %s function %s %s \n" + "as 'org.apache.flink.table.client.gateway.local.LocalExecutorITCase$TestScalaFunction' LANGUAGE JAVA"; // arguments: [TEMPORARY|TEMPORARY SYSTEM], [IF EXISTS], func_name, func_class final String alterTemplate = "alter %s function %s %s AS %s"; // Test alter function. executor.executeSql(sessionId, String.format(createTemplate, "", "", "func1")); assertThat(executor.listFunctions(sessionId), hasItems("func1")); executor.executeSql(sessionId, String.format(alterTemplate, "", "IF EXISTS", "`default`.func1", "'newClass'")); assertThat(executor.listFunctions(sessionId), hasItems("func1")); // Test alter non temporary function with TEMPORARY keyword. try { executor.executeSql(sessionId, String.format(alterTemplate, "TEMPORARY", "IF EXISTS", "`default`.func2", "'func3'")); fail("unexpected exception"); } catch (Exception var1) { assertThat(var1.getCause().getMessage(), is("Alter temporary catalog function is not supported")); } } finally { executor.closeSession(sessionId); } }
Example 13
Source File: LocalExecutorITCase.java From flink with Apache License 2.0 | 4 votes |
@Test(timeout = 90_000L) public void testStreamQueryExecutionSink() throws Exception { final String csvOutputPath = new File(tempFolder.newFolder().getAbsolutePath(), "test-out.csv").toURI().toString(); final URL url = getClass().getClassLoader().getResource("test-data.csv"); Objects.requireNonNull(url); final Map<String, String> replaceVars = new HashMap<>(); replaceVars.put("$VAR_PLANNER", planner); replaceVars.put("$VAR_SOURCE_PATH1", url.getPath()); replaceVars.put("$VAR_EXECUTION_TYPE", "streaming"); replaceVars.put("$VAR_SOURCE_SINK_PATH", csvOutputPath); replaceVars.put("$VAR_UPDATE_MODE", "update-mode: append"); replaceVars.put("$VAR_MAX_ROWS", "100"); final Executor executor = createModifiedExecutor(clusterClient, replaceVars); final SessionContext session = new SessionContext("test-session", new Environment()); String sessionId = executor.openSession(session); assertEquals("test-session", sessionId); try { executor.executeSql(sessionId, "CREATE FUNCTION LowerUDF AS 'LowerUDF'"); // Case 1: Registered sink // Case 1.1: Registered sink with uppercase insert into keyword. // FLINK-18302: wrong classloader when INSERT INTO with UDF final String statement1 = "INSERT INTO TableSourceSink SELECT IntegerField1 = 42," + " LowerUDF(StringField1), TimestampField1 FROM TableNumber1"; executeAndVerifySinkResult(executor, sessionId, statement1, csvOutputPath); // Case 1.2: Registered sink with lowercase insert into keyword. final String statement2 = "insert Into TableSourceSink \n " + "SELECT IntegerField1 = 42, LowerUDF(StringField1), TimestampField1 " + "FROM TableNumber1"; executeAndVerifySinkResult(executor, sessionId, statement2, csvOutputPath); // Case 1.3: Execute the same statement again, the results should expect to be the same. executeAndVerifySinkResult(executor, sessionId, statement2, csvOutputPath); // Case 2: Temporary sink executor.useCatalog(sessionId, "simple-catalog"); executor.useDatabase(sessionId, "default_database"); // all queries are pipelined to an in-memory sink, check it is properly registered final ResultDescriptor otherCatalogDesc = executor.executeQuery(sessionId, "SELECT * FROM `test-table`"); final List<String> otherCatalogResults = retrieveTableResult( executor, sessionId, otherCatalogDesc.getResultId()); TestBaseUtils.compareResultCollections( SimpleCatalogFactory.TABLE_CONTENTS.stream().map(Row::toString).collect(Collectors.toList()), otherCatalogResults, Comparator.naturalOrder()); } finally { executor.closeSession(sessionId); } }
Example 14
Source File: LocalExecutorITCase.java From flink with Apache License 2.0 | 4 votes |
@Test public void testDropTable() throws Exception { final Executor executor = createDefaultExecutor(clusterClient); final SessionContext session = new SessionContext("test-session", new Environment()); String sessionId = executor.openSession(session); try { executor.useCatalog(sessionId, "catalog1"); executor.setSessionProperty(sessionId, "execution.type", "batch"); final String ddlTemplate = "create table %s(\n" + " a int,\n" + " b bigint,\n" + " c varchar\n" + ") with (\n" + " 'connector.type'='filesystem',\n" + " 'format.type'='csv',\n" + " 'connector.path'='xxx',\n" + " 'update-mode'='append'\n" + ")\n"; // Test drop table. executor.createTable(sessionId, String.format(ddlTemplate, "MyTable1")); assertEquals(Collections.singletonList("MyTable1"), executor.listTables(sessionId)); executor.dropTable(sessionId, "DROP TABLE MyTable1"); assertEquals(Collections.emptyList(), executor.listTables(sessionId)); // Test drop table if exists. executor.createTable(sessionId, String.format(ddlTemplate, "MyTable1")); assertEquals(Collections.singletonList("MyTable1"), executor.listTables(sessionId)); executor.dropTable(sessionId, "DROP TABLE IF EXISTS MyTable1"); assertEquals(Collections.emptyList(), executor.listTables(sessionId)); // Test drop table with full qualified name. executor.createTable(sessionId, String.format(ddlTemplate, "MyTable1")); assertEquals(Collections.singletonList("MyTable1"), executor.listTables(sessionId)); executor.dropTable(sessionId, "DROP TABLE catalog1.`default`.MyTable1"); assertEquals(Collections.emptyList(), executor.listTables(sessionId)); // Test drop table with db and table name. executor.createTable(sessionId, String.format(ddlTemplate, "MyTable1")); assertEquals(Collections.singletonList("MyTable1"), executor.listTables(sessionId)); executor.dropTable(sessionId, "DROP TABLE `default`.MyTable1"); assertEquals(Collections.emptyList(), executor.listTables(sessionId)); // Test drop table that does not exist. executor.createTable(sessionId, String.format(ddlTemplate, "MyTable1")); assertEquals(Collections.singletonList("MyTable1"), executor.listTables(sessionId)); executor.dropTable(sessionId, "DROP TABLE IF EXISTS catalog2.`default`.MyTable1"); assertEquals(Collections.singletonList("MyTable1"), executor.listTables(sessionId)); executor.dropTable(sessionId, "DROP TABLE `default`.MyTable1"); // Test drop table with properties changed. executor.createTable(sessionId, String.format(ddlTemplate, "MyTable1")); // Change the session property to trigger `new ExecutionContext`. executor.setSessionProperty(sessionId, "execution.restart-strategy.failure-rate-interval", "12345"); executor.createTable(sessionId, String.format(ddlTemplate, "MyTable2")); assertEquals(Arrays.asList("MyTable1", "MyTable2"), executor.listTables(sessionId)); executor.dropTable(sessionId, "DROP TABLE MyTable1"); executor.dropTable(sessionId, "DROP TABLE MyTable2"); assertEquals(Collections.emptyList(), executor.listTables(sessionId)); // Test drop table with properties reset. // Reset the session properties. executor.createTable(sessionId, String.format(ddlTemplate, "MyTable1")); executor.createTable(sessionId, String.format(ddlTemplate, "MyTable2")); executor.resetSessionProperties(sessionId); executor.createTable(sessionId, String.format(ddlTemplate, "MyTable3")); assertEquals(Arrays.asList("MyTable1", "MyTable2", "MyTable3"), executor.listTables(sessionId)); executor.dropTable(sessionId, "DROP TABLE MyTable1"); executor.dropTable(sessionId, "DROP TABLE MyTable2"); executor.dropTable(sessionId, "DROP TABLE MyTable3"); assertEquals(Collections.emptyList(), executor.listTables(sessionId)); } finally { executor.closeSession(sessionId); } }
Example 15
Source File: LocalExecutorITCase.java From flink with Apache License 2.0 | 4 votes |
@Test public void testDropFunction() throws Exception { final Executor executor = createDefaultExecutor(clusterClient); final SessionContext session = new SessionContext("test-session", new Environment()); String sessionId = executor.openSession(session); try { executor.useCatalog(sessionId, "catalog1"); executor.setSessionProperty(sessionId, "execution.type", "batch"); // arguments: [TEMPORARY|TEMPORARY SYSTEM], [IF NOT EXISTS], func_name final String createTemplate = "create %s function %s %s \n" + "as 'org.apache.flink.table.client.gateway.local.LocalExecutorITCase$TestScalaFunction' LANGUAGE JAVA"; // arguments: [TEMPORARY|TEMPORARY SYSTEM], [IF EXISTS], func_name final String dropTemplate = "drop %s function %s %s"; // Test drop function. executor.executeSql(sessionId, String.format(createTemplate, "", "", "func1")); assertThat(executor.listFunctions(sessionId), hasItems("func1")); executor.executeSql(sessionId, String.format(dropTemplate, "", "", "func1")); assertThat(executor.listFunctions(sessionId), not(hasItems("func1"))); // Test drop function if exists. executor.executeSql(sessionId, String.format(createTemplate, "", "", "func1")); assertThat(executor.listFunctions(sessionId), hasItems("func1")); executor.executeSql(sessionId, String.format(dropTemplate, "", "IF EXISTS", "func1")); assertThat(executor.listFunctions(sessionId), not(hasItems("func1"))); // Test drop function with full qualified name. executor.executeSql(sessionId, String.format(createTemplate, "", "", "func1")); assertThat(executor.listFunctions(sessionId), hasItems("func1")); executor.executeSql(sessionId, String.format(dropTemplate, "", "IF EXISTS", "catalog1.`default`.func1")); assertThat(executor.listFunctions(sessionId), not(hasItems("func1"))); // Test drop function with db and function name. executor.executeSql(sessionId, String.format(createTemplate, "", "", "func1")); assertThat(executor.listFunctions(sessionId), hasItems("func1")); executor.executeSql(sessionId, String.format(dropTemplate, "", "IF EXISTS", "`default`.func1")); assertThat(executor.listFunctions(sessionId), not(hasItems("func1"))); // Test drop function that does not exist. executor.executeSql(sessionId, String.format(createTemplate, "", "", "func1")); assertThat(executor.listFunctions(sessionId), hasItems("func1")); try { executor.executeSql(sessionId, String.format(dropTemplate, "", "IF EXISTS", "catalog2.`default`.func1")); fail("unexpected"); } catch (Exception e) { assertThat(e.getCause().getMessage(), is("Catalog catalog2 does not exist")); } assertThat(executor.listFunctions(sessionId), hasItems("func1")); executor.executeSql(sessionId, String.format(dropTemplate, "", "", "`default`.func1")); // Test drop function with properties changed. executor.executeSql(sessionId, String.format(createTemplate, "", "", "func1")); // Change the session property to trigger `new ExecutionContext`. executor.setSessionProperty(sessionId, "execution.restart-strategy.failure-rate-interval", "12345"); executor.executeSql(sessionId, String.format(createTemplate, "", "", "func2")); assertThat(executor.listFunctions(sessionId), hasItems("func1", "func2")); executor.executeSql(sessionId, String.format(dropTemplate, "", "", "func1")); executor.executeSql(sessionId, String.format(dropTemplate, "", "", "func2")); assertThat(executor.listFunctions(sessionId), not(hasItems("func1", "func2"))); // Test drop function with properties reset. // Reset the session properties. executor.executeSql(sessionId, String.format(createTemplate, "", "", "func1")); executor.executeSql(sessionId, String.format(createTemplate, "", "", "func2")); executor.resetSessionProperties(sessionId); executor.executeSql(sessionId, String.format(createTemplate, "", "", "func3")); assertThat(executor.listFunctions(sessionId), hasItems("func1", "func2", "func3")); executor.executeSql(sessionId, String.format(dropTemplate, "", "", "func1")); executor.executeSql(sessionId, String.format(dropTemplate, "", "", "func2")); executor.executeSql(sessionId, String.format(dropTemplate, "", "", "func3")); assertThat(executor.listFunctions(sessionId), not(hasItems("func1", "func2", "func3"))); } finally { executor.closeSession(sessionId); } }