org.apache.flink.table.client.config.Environment Java Examples

The following examples show how to use org.apache.flink.table.client.config.Environment. 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 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 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 #3
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 #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());

	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 #5
Source File: CliClientTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testHistoryFile() throws Exception {
	final SessionContext context = new SessionContext("test-session", new Environment());
	final MockExecutor mockExecutor = new MockExecutor();
	String sessionId = mockExecutor.openSession(context);

	InputStream inputStream = new ByteArrayInputStream("help;\nuse catalog cat;\n".getBytes());
	CliClient cliClient = null;
	try (Terminal terminal = new DumbTerminal(inputStream, new MockOutputStream())) {
		Path historyFilePath = File.createTempFile("history", "tmp").toPath();
		cliClient = new CliClient(terminal, sessionId, mockExecutor, historyFilePath);
		cliClient.open();
		List<String> content = Files.readAllLines(historyFilePath);
		assertEquals(2, content.size());
		assertTrue(content.get(0).contains("help"));
		assertTrue(content.get(1).contains("use catalog cat"));
	} finally {
		if (cliClient != null) {
			cliClient.close();
		}
	}
}
 
Example #6
Source File: ExecutionContextTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private <T> ExecutionContext<T> createExecutionContext(String file, Map<String, String> replaceVars) throws Exception {
	final Environment env = EnvironmentFileUtil.parseModified(
		file,
		replaceVars);
	final Configuration flinkConfig = new Configuration();
	return (ExecutionContext<T>) ExecutionContext.builder(
			env,
			new SessionContext("test-session", new Environment()),
			Collections.emptyList(),
			flinkConfig,
			new DefaultClusterClientServiceLoader(),
			new Options(),
			Collections.singletonList(new DefaultCLI(flinkConfig)))
			.build();
}
 
Example #7
Source File: CliClientTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private void verifyUpdateSubmission(String statement, boolean failExecution, boolean testFailure) {
	final SessionContext context = new SessionContext("test-session", new Environment());

	final MockExecutor mockExecutor = new MockExecutor();
	mockExecutor.failExecution = failExecution;

	CliClient cli = null;
	try {
		cli = new CliClient(TerminalUtils.createDummyTerminal(), context, mockExecutor);
		if (testFailure) {
			assertFalse(cli.submitUpdate(statement));
		} else {
			assertTrue(cli.submitUpdate(statement));
			assertEquals(statement, mockExecutor.receivedStatement);
			assertEquals(context, mockExecutor.receivedContext);
		}
	} finally {
		if (cli != null) {
			cli.close();
		}
	}
}
 
Example #8
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 #9
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 #10
Source File: ExecutionContext.java    From flink with Apache License 2.0 6 votes vote down vote up
public ExecutionContext<?> build() {
	try {
		return new ExecutionContext<>(
				this.currentEnv == null
						? Environment.merge(defaultEnv, sessionContext.getSessionEnv())
						: this.currentEnv,
				this.sessionContext,
				this.sessionState,
				this.dependencies,
				this.configuration,
				this.serviceLoader,
				this.commandLineOptions,
				this.commandLines);
	} catch (Throwable t) {
		// catch everything such that a configuration does not crash the executor
		throw new SqlExecutionException("Could not create execution context.", t);
	}
}
 
Example #11
Source File: LocalExecutor.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor for testing purposes.
 */
public LocalExecutor(
		Environment defaultEnvironment,
		List<URL> dependencies,
		Configuration flinkConfig,
		CustomCommandLine commandLine,
		ClusterClientServiceLoader clusterClientServiceLoader) {
	this.defaultEnvironment = defaultEnvironment;
	this.dependencies = dependencies;
	this.flinkConfig = flinkConfig;
	this.commandLines = Collections.singletonList(commandLine);
	this.commandLineOptions = collectCommandLineOptions(commandLines);
	this.contextMap = new ConcurrentHashMap<>();

	// prepare result store
	this.resultStore = new ResultStore(flinkConfig);
	this.clusterClientServiceLoader = checkNotNull(clusterClientServiceLoader);
}
 
Example #12
Source File: DependencyTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testTableFactoryDiscovery() throws Exception {
	final LocalExecutor executor = createExecutor();
	final SessionContext session = new SessionContext("test-session", new Environment());
	String sessionId = executor.openSession(session);
	try {
		final TableSchema result = executor.getTableSchema(sessionId, "TableNumber1");
		final TableSchema expected = TableSchema.builder()
			.field("IntegerField1", Types.INT())
			.field("StringField1", Types.STRING())
			.field("rowtimeField", Types.SQL_TIMESTAMP())
			.build();

		assertEquals(expected, result);
	} finally {
		executor.closeSession(sessionId);
	}
}
 
Example #13
Source File: CliClientTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testUseNonExistingCatalog() throws Exception {
	TestingExecutor executor = new TestingExecutorBuilder()
		.setUseCatalogConsumer((ignored1, ignored2) -> {
			throw new SqlExecutionException("mocked exception");
		})
		.build();

	InputStream inputStream = new ByteArrayInputStream("use catalog cat;\n".getBytes());
	CliClient cliClient = null;
	SessionContext sessionContext = new SessionContext("test-session", new Environment());
	String sessionId = executor.openSession(sessionContext);

	try (Terminal terminal = new DumbTerminal(inputStream, new MockOutputStream())) {
		cliClient = new CliClient(terminal, sessionId, executor, File.createTempFile("history", "tmp").toPath());
		cliClient.open();
		assertThat(executor.getNumUseCatalogCalls(), is(1));
	} finally {
		if (cliClient != null) {
			cliClient.close();
		}
	}
}
 
Example #14
Source File: ExecutionContextTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testInitCatalogs() throws Exception{
	final Map<String, String> replaceVars = createDefaultReplaceVars();
	Environment env = EnvironmentFileUtil.parseModified(DEFAULTS_ENVIRONMENT_FILE, replaceVars);

	Map<String, Object> catalogProps = new HashMap<>();
	catalogProps.put("name", "test");
	catalogProps.put("type", "test_cl_catalog");
	env.getCatalogs().clear();
	env.getCatalogs().put("test", CatalogEntry.create(catalogProps));
	Configuration flinkConfig = new Configuration();
	ExecutionContext.builder(env,
			new SessionContext("test-session", new Environment()),
			Collections.emptyList(),
			flinkConfig,
			new DefaultClusterClientServiceLoader(),
			new Options(),
			Collections.singletonList(new DefaultCLI(flinkConfig))).build();
}
 
Example #15
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 #16
Source File: CliClientTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private void verifySqlCompletion(String statement, int position, List<String> expectedHints, List<String> notExpectedHints) throws IOException {
	final SessionContext context = new SessionContext("test-session", new Environment());
	final MockExecutor mockExecutor = new MockExecutor();

	final SqlCompleter completer = new SqlCompleter(context, mockExecutor);
	final SqlMultiLineParser parser = new SqlMultiLineParser();

	try (Terminal terminal = TerminalUtils.createDummyTerminal()) {
		final LineReader reader = LineReaderBuilder.builder().terminal(terminal).build();

		final ParsedLine parsedLine = parser.parse(statement, position, Parser.ParseContext.COMPLETE);
		final List<Candidate> candidates = new ArrayList<>();
		final List<String> results = new ArrayList<>();
		completer.complete(reader, parsedLine, candidates);
		candidates.forEach(item -> results.add(item.value()));

		assertTrue(results.containsAll(expectedHints));

		assertEquals(statement, mockExecutor.receivedStatement);
		assertEquals(context, mockExecutor.receivedContext);
		assertEquals(position, mockExecutor.receivedPosition);
		assertTrue(results.contains("HintA"));
		assertTrue(results.contains("Hint B"));

		results.retainAll(notExpectedHints);
		assertEquals(0, results.size());
	}
}
 
Example #17
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 #18
Source File: CliResultViewTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private void testResultViewClearResult(TypedResult<?> typedResult, boolean isTableMode, int expectedCancellationCount) throws Exception {
	final CountDownLatch cancellationCounterLatch = new CountDownLatch(expectedCancellationCount);
	final SessionContext session = new SessionContext("test-session", new Environment());
	final MockExecutor executor = new MockExecutor(typedResult, cancellationCounterLatch);
	final ResultDescriptor descriptor = new ResultDescriptor(
		"result-id",
		TableSchema.builder().field("Null Field", Types.STRING()).build(),
		false);

	Thread resultViewRunner = null;
	CliClient cli = null;
	try {
		cli = new CliClient(TerminalUtils.createDummyTerminal(), session, executor);
		resultViewRunner = new Thread(new TestingCliResultView(cli, descriptor, isTableMode));
		resultViewRunner.start();
	} finally {
		if (resultViewRunner != null && !resultViewRunner.isInterrupted()) {
			resultViewRunner.interrupt();
		}
		if (cli != null) {
			cli.close();
		}
	}

	assertTrue(
		"Invalid number of cancellations.",
		cancellationCounterLatch.await(10, TimeUnit.SECONDS));
}
 
Example #19
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@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 #20
Source File: EnvironmentTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testDuplicateModules() {
	exception.expect(SqlClientException.class);
	Environment env = new Environment();
	env.setModules(Arrays.asList(
		createModule("module1", "test"),
		createModule("module2", "test"),
		createModule("module2", "test")));
}
 
Example #21
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@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 #22
Source File: EnvironmentTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testDuplicateCatalog() {
	exception.expect(SqlClientException.class);
	exception.expectMessage("Cannot create catalog 'catalog2' because a catalog with this name is already registered.");
	Environment env = new Environment();
	env.setCatalogs(Arrays.asList(
		createCatalog("catalog1", "test"),
		createCatalog("catalog2", "test"),
		createCatalog("catalog2", "test")));
}
 
Example #23
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 #24
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 90_000L)
public void ensureExceptionOnFaultySourceInBatch() throws Exception {
	final String missingFileName = "missing-source";

	final Map<String, String> replaceVars = new HashMap<>();
	replaceVars.put("$VAR_PLANNER", planner);
	replaceVars.put("$VAR_SOURCE_PATH1", missingFileName);
	replaceVars.put("$VAR_EXECUTION_TYPE", "batch");
	replaceVars.put("$VAR_RESULT_MODE", "table");
	replaceVars.put("$VAR_UPDATE_MODE", "");
	replaceVars.put("$VAR_MAX_ROWS", "100");
	replaceVars.put("$VAR_RESTART_STRATEGY_TYPE", "none");

	final Executor executor = createModifiedExecutor(clusterClient, replaceVars);
	final SessionContext session = new SessionContext("test-session", new Environment());
	String sessionId = executor.openSession(session);
	assertEquals("test-session", sessionId);

	Optional<Throwable> throwableWithMessage = Optional.empty();
	try {
		final ResultDescriptor desc = executor.executeQuery(sessionId, "SELECT * FROM TestView1");
		retrieveTableResult(executor, sessionId, desc.getResultId());
	} catch (SqlExecutionException e) {
		throwableWithMessage = findMissingFileException(e, missingFileName);
	} finally {
		executor.closeSession(sessionId);
	}
	assertTrue(throwableWithMessage.isPresent());
}
 
Example #25
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 #26
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetSessionProperties() throws Exception {
	final Executor executor = createDefaultExecutor(clusterClient);
	final SessionContext session = new SessionContext("test-session", new Environment());

	session.setSessionProperty("execution.result-mode", "changelog");

	executor.getSessionProperties(session);

	// modify defaults
	session.setSessionProperty("execution.result-mode", "table");

	final Map<String, String> actualProperties = executor.getSessionProperties(session);

	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", "0");
	expectedProperties.put("execution.min-idle-state-retention", "0");
	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);
}
 
Example #27
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testListUserDefinedFunctions() throws Exception {
	final Executor executor = createDefaultExecutor(clusterClient);
	final SessionContext session = new SessionContext("test-session", new Environment());

	final List<String> actualTables = executor.listUserDefinedFunctions(session);

	final List<String> expectedTables = Arrays.asList("aggregateUDF", "tableUDF", "scalarUDF");
	assertEquals(expectedTables, actualTables);
}
 
Example #28
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 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 #29
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());

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

	final List<String> expectedDatabases = Collections.singletonList("default_database");
	assertEquals(expectedDatabases, actualDatabases);
}
 
Example #30
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 5 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());

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

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