Java Code Examples for org.apache.flink.table.client.gateway.Executor#setSessionProperty()
The following examples show how to use
org.apache.flink.table.client.gateway.Executor#setSessionProperty() .
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 | 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 2
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 3
Source File: LocalExecutorITCase.java From flink with Apache License 2.0 | 4 votes |
@Test public void testGetSessionProperties() throws Exception { final Executor executor = createDefaultExecutor(clusterClient); final SessionContext session = new SessionContext("test-session", new Environment()); session.getSessionEnv().setExecution(ImmutableMap.of("result-mode", "changelog")); // Open the session and get the sessionId. String sessionId = executor.openSession(session); try { assertEquals("test-session", sessionId); assertEquals(executor.getSessionProperties(sessionId).get("execution.result-mode"), "changelog"); // modify defaults executor.setSessionProperty(sessionId, "execution.result-mode", "table"); final Map<String, String> actualProperties = executor.getSessionProperties(sessionId); final Map<String, String> expectedProperties = new HashMap<>(); expectedProperties.put("execution.planner", planner); expectedProperties.put("execution.type", "batch"); expectedProperties.put("execution.time-characteristic", "event-time"); expectedProperties.put("execution.periodic-watermarks-interval", "99"); expectedProperties.put("execution.parallelism", "1"); expectedProperties.put("execution.max-parallelism", "16"); expectedProperties.put("execution.max-idle-state-retention", "600000"); expectedProperties.put("execution.min-idle-state-retention", "1000"); expectedProperties.put("execution.result-mode", "table"); expectedProperties.put("execution.max-table-result-rows", "100"); expectedProperties.put("execution.restart-strategy.type", "failure-rate"); expectedProperties.put("execution.restart-strategy.max-failures-per-interval", "10"); expectedProperties.put("execution.restart-strategy.failure-rate-interval", "99000"); expectedProperties.put("execution.restart-strategy.delay", "1000"); expectedProperties.put("table.optimizer.join-reorder-enabled", "false"); expectedProperties.put("deployment.response-timeout", "5000"); assertEquals(expectedProperties, actualProperties); // Reset session properties executor.resetSessionProperties(sessionId); assertEquals(executor.getSessionProperties(sessionId).get("execution.result-mode"), "changelog"); } finally { executor.closeSession(sessionId); } }
Example 4
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 5
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); } }