Java Code Examples for org.apache.flink.table.client.gateway.Executor#useDatabase()
The following examples show how to use
org.apache.flink.table.client.gateway.Executor#useDatabase() .
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 testUseNonExistingDatabase() throws Exception { final Executor executor = createDefaultExecutor(clusterClient); final SessionContext session = new SessionContext("test-session", new Environment()); exception.expect(SqlExecutionException.class); executor.useDatabase(session, "nonexistingdb"); }
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 testUseNonExistingDatabase() 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.useDatabase(sessionId, "nonexistingdb"); }
Example 6
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); } }