org.apache.flink.table.client.gateway.Executor Java Examples

The following examples show how to use org.apache.flink.table.client.gateway.Executor. 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
private List<String> retrieveTableResult(
		Executor executor,
		String sessionId,
		String resultID) throws InterruptedException {

	final List<String> actualResults = new ArrayList<>();
	while (true) {
		Thread.sleep(50); // slow the processing down
		final TypedResult<Integer> result = executor.snapshotResult(sessionId, resultID, 2);
		if (result.getType() == TypedResult.ResultType.PAYLOAD) {
			actualResults.clear();
			IntStream.rangeClosed(1, result.getPayload()).forEach((page) -> {
				for (Row row : executor.retrieveResultPage(resultID, page)) {
					actualResults.add(row.toString());
				}
			});
		} else if (result.getType() == TypedResult.ResultType.EOS) {
			break;
		}
	}

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

	final List<String> actualTables = executor.listTables(sessionId);

	final List<String> expectedTables = Arrays.asList(
		"TableNumber1",
		"TableNumber2",
		"TableSourceSink",
		"TestView1",
		"TestView2");
	assertEquals(expectedTables, actualTables);
	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 testTableSchema() 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);

	final TableSchema actualTableSchema = executor.getTableSchema(sessionId, "TableNumber2");

	final TableSchema expectedTableSchema = new TableSchema(
		new String[]{"IntegerField2", "StringField2", "TimestampField2"},
		new TypeInformation[]{Types.INT, Types.STRING, Types.SQL_TIMESTAMP});

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

	final List<String> expectedTableHints = Arrays.asList(
		"default_catalog.default_database.TableNumber1",
		"default_catalog.default_database.TableNumber2",
		"default_catalog.default_database.TableSourceSink");
	assertEquals(expectedTableHints, executor.completeStatement(sessionId, "SELECT * FROM Ta", 16));

	final List<String> expectedClause = Collections.singletonList("WHERE");
	assertEquals(expectedClause, executor.completeStatement(sessionId, "SELECT * FROM TableNumber2 WH", 29));

	final List<String> expectedField = Arrays.asList("IntegerField1");
	assertEquals(expectedField, executor.completeStatement(sessionId, "SELECT * FROM TableNumber1 WHERE Inte", 37));
	executor.closeSession(sessionId);
}
 
Example #5
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 #6
Source File: LocalExecutorITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private List<String> retrieveChangelogResult(
		Executor executor,
		SessionContext session,
		String resultID) throws InterruptedException {

	final List<String> actualResults = new ArrayList<>();
	while (true) {
		Thread.sleep(50); // slow the processing down
		final TypedResult<List<Tuple2<Boolean, Row>>> result =
				executor.retrieveResultChanges(session, resultID);
		if (result.getType() == TypedResult.ResultType.PAYLOAD) {
			for (Tuple2<Boolean, Row> change : result.getPayload()) {
				actualResults.add(change.toString());
			}
		} else if (result.getType() == TypedResult.ResultType.EOS) {
			break;
		}
	}
	return actualResults;
}
 
Example #7
Source File: LocalExecutorITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private List<String> retrieveTableResult(
		Executor executor,
		SessionContext session,
		String resultID) throws InterruptedException {

	final List<String> actualResults = new ArrayList<>();
	while (true) {
		Thread.sleep(50); // slow the processing down
		final TypedResult<Integer> result = executor.snapshotResult(session, resultID, 2);
		if (result.getType() == TypedResult.ResultType.PAYLOAD) {
			actualResults.clear();
			IntStream.rangeClosed(1, result.getPayload()).forEach((page) -> {
				for (Row row : executor.retrieveResultPage(resultID, page)) {
					actualResults.add(row.toString());
				}
			});
		} else if (result.getType() == TypedResult.ResultType.EOS) {
			break;
		}
	}

	return actualResults;
}
 
Example #8
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 #9
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 #10
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
private void executeStreamQueryTable(
		Map<String, String> replaceVars,
		String query,
		List<String> expectedResults) throws Exception {

	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 {
		// start job and retrieval
		final ResultDescriptor desc = executor.executeQuery(sessionId, query);

		assertTrue(desc.isMaterialized());

		final List<String> actualResults = retrieveTableResult(executor, sessionId, desc.getResultId());

		TestBaseUtils.compareResultCollections(expectedResults, actualResults, Comparator.naturalOrder());
	} finally {
		executor.closeSession(sessionId);
	}
}
 
Example #11
Source File: LocalExecutorITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testCompleteStatement() throws Exception {
	final Executor executor = createDefaultExecutor(clusterClient);
	final SessionContext session = new SessionContext("test-session", new Environment());

	final List<String> expectedTableHints = Arrays.asList(
		"TABLE",
		"TableNumber1",
		"TableNumber2",
		"TableSourceSink");
	assertEquals(expectedTableHints, executor.completeStatement(session, "SELECT * FROM Ta", 16));

	final List<String> expectedClause = Collections.singletonList("WHERE");
	assertEquals(expectedClause, executor.completeStatement(session, "SELECT * FROM TableNumber2 WH", 29));

	final List<String> expectedField = Arrays.asList("INTERVAL", "IntegerField1");
	assertEquals(expectedField, executor.completeStatement(session, "SELECT * FROM TableNumber1 WHERE Inte", 37));
}
 
Example #12
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
private List<String> retrieveChangelogResult(
		Executor executor,
		String sessionId,
		String resultID) throws InterruptedException {

	final List<String> actualResults = new ArrayList<>();
	while (true) {
		Thread.sleep(50); // slow the processing down
		final TypedResult<List<Tuple2<Boolean, Row>>> result =
			executor.retrieveResultChanges(sessionId, resultID);
		if (result.getType() == TypedResult.ResultType.PAYLOAD) {
			for (Tuple2<Boolean, Row> change : result.getPayload()) {
				actualResults.add(change.toString());
			}
		} else if (result.getType() == TypedResult.ResultType.EOS) {
			break;
		}
	}
	return actualResults;
}
 
Example #13
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
private void executeStreamQueryTable(
		Map<String, String> replaceVars,
		String query,
		List<String> expectedResults) throws Exception {

	final Executor executor = createModifiedExecutor(clusterClient, replaceVars);
	final SessionContext session = new SessionContext("test-session", new Environment());

	try {
		// start job and retrieval
		final ResultDescriptor desc = executor.executeQuery(session, query);

		assertTrue(desc.isMaterialized());

		final List<String> actualResults = retrieveTableResult(executor, session, desc.getResultId());

		TestBaseUtils.compareResultCollections(expectedResults, actualResults, Comparator.naturalOrder());
	} finally {
		executor.stop(session);
	}
}
 
Example #14
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
private List<String> retrieveTableResult(
		Executor executor,
		SessionContext session,
		String resultID) throws InterruptedException {

	final List<String> actualResults = new ArrayList<>();
	while (true) {
		Thread.sleep(50); // slow the processing down
		final TypedResult<Integer> result = executor.snapshotResult(session, resultID, 2);
		if (result.getType() == TypedResult.ResultType.PAYLOAD) {
			actualResults.clear();
			IntStream.rangeClosed(1, result.getPayload()).forEach((page) -> {
				for (Row row : executor.retrieveResultPage(resultID, page)) {
					actualResults.add(row.toString());
				}
			});
		} else if (result.getType() == TypedResult.ResultType.EOS) {
			break;
		}
	}

	return actualResults;
}
 
Example #15
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
private List<String> retrieveChangelogResult(
		Executor executor,
		SessionContext session,
		String resultID) throws InterruptedException {

	final List<String> actualResults = new ArrayList<>();
	while (true) {
		Thread.sleep(50); // slow the processing down
		final TypedResult<List<Tuple2<Boolean, Row>>> result =
				executor.retrieveResultChanges(session, resultID);
		if (result.getType() == TypedResult.ResultType.PAYLOAD) {
			for (Tuple2<Boolean, Row> change : result.getPayload()) {
				actualResults.add(change.toString());
			}
		} else if (result.getType() == TypedResult.ResultType.EOS) {
			break;
		}
	}
	return actualResults;
}
 
Example #16
Source File: CliClientTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testUseNonExistingDB() throws Exception {
	Executor executor = mock(Executor.class);
	doThrow(new SqlExecutionException("mocked exception")).when(executor).useDatabase(any(), any());
	InputStream inputStream = new ByteArrayInputStream("use db;\n".getBytes());
	// don't care about the output
	OutputStream outputStream = new OutputStream() {
		@Override
		public void write(int b) throws IOException {
		}
	};
	CliClient cliClient = null;
	try (Terminal terminal = new DumbTerminal(inputStream, outputStream)) {
		cliClient = new CliClient(terminal, new SessionContext("test-session", new Environment()), executor);
		cliClient.open();
		verify(executor).useDatabase(any(), any());
	} finally {
		if (cliClient != null) {
			cliClient.close();
		}
	}
}
 
Example #17
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testCompleteStatement() throws Exception {
	final Executor executor = createDefaultExecutor(clusterClient);
	final SessionContext session = new SessionContext("test-session", new Environment());

	final List<String> expectedTableHints = Arrays.asList(
		"default_catalog.default_database.TableNumber1",
		"default_catalog.default_database.TableNumber2",
		"default_catalog.default_database.TableSourceSink");
	assertEquals(expectedTableHints, executor.completeStatement(session, "SELECT * FROM Ta", 16));

	final List<String> expectedClause = Collections.singletonList("WHERE");
	assertEquals(expectedClause, executor.completeStatement(session, "SELECT * FROM TableNumber2 WH", 29));

	final List<String> expectedField = Arrays.asList("IntegerField1");
	assertEquals(expectedField, executor.completeStatement(session, "SELECT * FROM TableNumber1 WHERE Inte", 37));
}
 
Example #18
Source File: CliClientTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testUseNonExistingCatalog() throws Exception {
	Executor executor = mock(Executor.class);
	doThrow(new SqlExecutionException("mocked exception")).when(executor).useCatalog(any(), any());
	InputStream inputStream = new ByteArrayInputStream("use catalog cat;\n".getBytes());
	// don't care about the output
	OutputStream outputStream = new OutputStream() {
		@Override
		public void write(int b) throws IOException {
		}
	};
	CliClient cliClient = null;
	try (Terminal terminal = new DumbTerminal(inputStream, outputStream)) {
		cliClient = new CliClient(terminal, new SessionContext("test-session", new Environment()), executor);
		cliClient.open();
		verify(executor).useCatalog(any(), any());
	} finally {
		if (cliClient != null) {
			cliClient.close();
		}
	}
}
 
Example #19
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testListCatalogs() 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);

	final List<String> actualCatalogs = executor.listCatalogs(sessionId);

	final List<String> expectedCatalogs = Arrays.asList(
		"catalog1",
		"default_catalog",
		"simple-catalog");
	assertEquals(expectedCatalogs, actualCatalogs);

	executor.closeSession(sessionId);
}
 
Example #20
Source File: CliTableauResultView.java    From flink with Apache License 2.0 5 votes vote down vote up
public CliTableauResultView(
		final Terminal terminal,
		final Executor sqlExecutor,
		final String sessionId,
		final ResultDescriptor resultDescriptor) {
	this.terminal = terminal;
	this.sqlExecutor = sqlExecutor;
	this.sessionId = sessionId;
	this.resultDescriptor = resultDescriptor;
	this.displayResultExecutorService = Executors.newSingleThreadExecutor(new ExecutorThreadFactory("CliTableauResultView"));
}
 
Example #21
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 #22
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testListDatabases() 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);

	final List<String> actualDatabases = executor.listDatabases(sessionId);

	final List<String> expectedDatabases = Collections.singletonList("default_database");
	assertEquals(expectedDatabases, actualDatabases);

	executor.closeSession(sessionId);
}
 
Example #23
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 90_000L)
public void testStreamQueryExecutionTableMultipleTimes() throws Exception {
	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_RESULT_MODE", "table");
	replaceVars.put("$VAR_UPDATE_MODE", "update-mode: append");
	replaceVars.put("$VAR_MAX_ROWS", "100");

	final String query = "SELECT scalarUDF(IntegerField1), StringField1 FROM TableNumber1";

	final List<String> expectedResults = new ArrayList<>();
	expectedResults.add("47,Hello World");
	expectedResults.add("27,Hello World");
	expectedResults.add("37,Hello World");
	expectedResults.add("37,Hello World");
	expectedResults.add("47,Hello World");
	expectedResults.add("57,Hello World!!!!");

	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 {
		for (int i = 0; i < 3; i++) {
			executeStreamQueryTable(replaceVars, query, expectedResults);
		}
	} finally {
		executor.closeSession(sessionId);
	}
}
 
Example #24
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@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 #25
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@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 #26
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@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 #27
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@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 #28
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@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 #29
Source File: SqlClient.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private static void validateEnvironment(SessionContext context, Executor executor) {
	System.out.print("Validating current environment...");
	try {
		executor.validateSession(context);
		System.out.println("done.");
	} catch (SqlExecutionException e) {
		throw new SqlClientException(
			"The configured environment is invalid. Please check your environment files again.", e);
	}
}
 
Example #30
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@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");
}