Java Code Examples for org.apache.flink.table.client.gateway.Executor#executeUpdate()

The following examples show how to use org.apache.flink.table.client.gateway.Executor#executeUpdate() . 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 vote down vote up
@Test
public void testDropDatabase() 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);

	executor.executeUpdate(sessionId, "create database db1");

	List<String> actualDatabases = executor.listDatabases(sessionId);
	List<String> expectedDatabases = Arrays.asList("default_database", "db1");
	assertEquals(expectedDatabases, actualDatabases);

	executor.executeUpdate(sessionId, "drop database if exists db1");

	actualDatabases = executor.listDatabases(sessionId);
	expectedDatabases = Arrays.asList("default_database");
	assertEquals(expectedDatabases, actualDatabases);

	executor.closeSession(sessionId);
}
 
Example 2
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testAlterDatabase() 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);

	executor.executeUpdate(sessionId, "create database db1 comment 'db1_comment' with ('k1' = 'v1')");

	executor.executeUpdate(sessionId, "alter database db1 set ('k1' = 'a', 'k2' = 'b')");

	final List<String> actualDatabases = executor.listDatabases(sessionId);
	final List<String> expectedDatabases = Arrays.asList("default_database", "db1");
	assertEquals(expectedDatabases, actualDatabases);
	//todo: we should compare the new db1 properties after we support describe database in LocalExecutor.

	executor.closeSession(sessionId);
}
 
Example 3
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateDatabase() 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);

	executor.executeUpdate(sessionId, "create database db1");

	final List<String> actualDatabases = executor.listDatabases(sessionId);
	final List<String> expectedDatabases = Arrays.asList("default_database", "db1");
	assertEquals(expectedDatabases, actualDatabases);

	executor.closeSession(sessionId);
}
 
Example 5
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
private void executeAndVerifySinkResult(
		Executor executor,
		String sessionId,
		String statement,
		String resultPath) throws Exception {
	final ProgramTargetDescriptor targetDescriptor = executor.executeUpdate(
			sessionId,
			statement);

	// wait for job completion and verify result
	boolean isRunning = true;
	while (isRunning) {
		Thread.sleep(50); // slow the processing down
		final JobStatus jobStatus = clusterClient.getJobStatus(targetDescriptor.getJobId()).get();
		switch (jobStatus) {
		case CREATED:
		case RUNNING:
			continue;
		case FINISHED:
			isRunning = false;
			verifySinkResult(resultPath);
			break;
		default:
			fail("Unexpected job status.");
		}
	}
}
 
Example 6
Source File: LocalExecutorITCase.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 30_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_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());

	try {
		// start job
		final ProgramTargetDescriptor targetDescriptor = executor.executeUpdate(
			session,
			"INSERT INTO TableSourceSink SELECT IntegerField1 = 42, StringField1 FROM TableNumber1");

		// wait for job completion and verify result
		boolean isRunning = true;
		while (isRunning) {
			Thread.sleep(50); // slow the processing down
			final JobStatus jobStatus = clusterClient.getJobStatus(JobID.fromHexString(targetDescriptor.getJobId())).get();
			switch (jobStatus) {
				case CREATED:
				case RUNNING:
					continue;
				case FINISHED:
					isRunning = false;
					verifySinkResult(csvOutputPath);
					break;
				default:
					fail("Unexpected job status.");
			}
		}
	} finally {
		executor.stop(session);
	}
}
 
Example 7
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 30_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());

	try {
		// Case 1: Registered sink
		final ProgramTargetDescriptor targetDescriptor = executor.executeUpdate(
			session,
			"INSERT INTO TableSourceSink SELECT IntegerField1 = 42, StringField1 FROM TableNumber1");

		// wait for job completion and verify result
		boolean isRunning = true;
		while (isRunning) {
			Thread.sleep(50); // slow the processing down
			final JobStatus jobStatus = clusterClient.getJobStatus(JobID.fromHexString(targetDescriptor.getJobId())).get();
			switch (jobStatus) {
				case CREATED:
				case RUNNING:
					continue;
				case FINISHED:
					isRunning = false;
					verifySinkResult(csvOutputPath);
					break;
				default:
					fail("Unexpected job status.");
			}
		}

		// Case 2: Temporary sink
		session.setCurrentCatalog("simple-catalog");
		session.setCurrentDatabase("default_database");
		// all queries are pipelined to an in-memory sink, check it is properly registered
		final ResultDescriptor otherCatalogDesc = executor.executeQuery(session, "SELECT * FROM `test-table`");

		final List<String> otherCatalogResults = retrieveTableResult(
			executor,
			session,
			otherCatalogDesc.getResultId());

		TestBaseUtils.compareResultCollections(
			SimpleCatalogFactory.TABLE_CONTENTS.stream().map(Row::toString).collect(Collectors.toList()),
			otherCatalogResults,
			Comparator.naturalOrder());
	} finally {
		executor.stop(session);
	}
}