Java Code Examples for org.apache.flink.table.client.config.Environment#merge()

The following examples show how to use org.apache.flink.table.client.config.Environment#merge() . 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: 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 2
Source File: EnvironmentTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testModuleOrder() {
	Environment env1 = new Environment();
	Environment env2 = new Environment();
	env1.setModules(Arrays.asList(
		createModule("b", "test"),
		createModule("d", "test")));

	env2.setModules(Arrays.asList(
		createModule("c", "test"),
		createModule("a", "test")));

	assertEquals(
		Arrays.asList("b", "d"), new ArrayList<>(env1.getModules().keySet())
	);

	assertEquals(
		Arrays.asList("c", "a"), new ArrayList<>(env2.getModules().keySet())
	);

	Environment env = Environment.merge(env1, env2);

	assertEquals(
		Arrays.asList("b", "d", "c", "a"), new ArrayList<>(env.getModules().keySet())
	);
}
 
Example 3
Source File: ExecutionContext.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public ExecutionContext(Environment defaultEnvironment, SessionContext sessionContext, List<URL> dependencies,
		Configuration flinkConfig, Options commandLineOptions, List<CustomCommandLine<?>> availableCommandLines) {
	this.sessionContext = sessionContext.copy(); // create internal copy because session context is mutable
	this.mergedEnv = Environment.merge(defaultEnvironment, sessionContext.getEnvironment());
	this.dependencies = dependencies;
	this.flinkConfig = flinkConfig;

	// create class loader
	classLoader = FlinkUserCodeClassLoaders.parentFirst(
		dependencies.toArray(new URL[dependencies.size()]),
		this.getClass().getClassLoader());

	// create table sources & sinks.
	tableSources = new HashMap<>();
	tableSinks = new HashMap<>();
	mergedEnv.getTables().forEach((name, entry) -> {
		if (entry instanceof SourceTableEntry || entry instanceof SourceSinkTableEntry) {
			tableSources.put(name, createTableSource(mergedEnv.getExecution(), entry.asMap(), classLoader));
		}
		if (entry instanceof SinkTableEntry || entry instanceof SourceSinkTableEntry) {
			tableSinks.put(name, createTableSink(mergedEnv.getExecution(), entry.asMap(), classLoader));
		}
	});

	// create user-defined functions
	functions = new HashMap<>();
	mergedEnv.getFunctions().forEach((name, entry) -> {
		final UserDefinedFunction function = FunctionService.createFunction(entry.getDescriptor(), classLoader, false);
		functions.put(name, function);
	});

	// convert deployment options into command line options that describe a cluster
	commandLine = createCommandLine(mergedEnv.getDeployment(), commandLineOptions);
	activeCommandLine = findActiveCommandLine(availableCommandLines, commandLine);
	runOptions = createRunOptions(commandLine);
	clusterId = activeCommandLine.getClusterId(commandLine);
	clusterSpec = createClusterSpecification(activeCommandLine, commandLine);
}
 
Example 4
Source File: EnvironmentTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testMerging() throws Exception {
	final Map<String, String> replaceVars1 = new HashMap<>();
	replaceVars1.put("$VAR_EXECUTION_TYPE", "batch");
	replaceVars1.put("$VAR_RESULT_MODE", "table");
	replaceVars1.put("$VAR_UPDATE_MODE", "");
	replaceVars1.put("$VAR_MAX_ROWS", "100");
	final Environment env1 = EnvironmentFileUtil.parseModified(
		DEFAULTS_ENVIRONMENT_FILE,
		replaceVars1);

	final Map<String, String> replaceVars2 = new HashMap<>(replaceVars1);
	replaceVars2.put("TableNumber1", "NewTable");
	final Environment env2 = EnvironmentFileUtil.parseModified(
		FACTORY_ENVIRONMENT_FILE,
		replaceVars2);

	final Environment merged = Environment.merge(env1, env2);

	final Set<String> tables = new HashSet<>();
	tables.add("TableNumber1");
	tables.add("TableNumber2");
	tables.add("NewTable");
	tables.add("TableSourceSink");
	tables.add("TestView1");
	tables.add("TestView2");

	assertEquals(tables, merged.getTables().keySet());
	assertTrue(merged.getExecution().isStreamingExecution());
	assertEquals(16, merged.getExecution().getMaxParallelism());
}
 
Example 5
Source File: EnvironmentTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testMerging() throws Exception {
	final Map<String, String> replaceVars1 = new HashMap<>();
	replaceVars1.put("$VAR_PLANNER", "old");
	replaceVars1.put("$VAR_EXECUTION_TYPE", "batch");
	replaceVars1.put("$VAR_RESULT_MODE", "table");
	replaceVars1.put("$VAR_UPDATE_MODE", "");
	replaceVars1.put("$VAR_MAX_ROWS", "100");
	final Environment env1 = EnvironmentFileUtil.parseModified(
		DEFAULTS_ENVIRONMENT_FILE,
		replaceVars1);

	final Map<String, String> replaceVars2 = new HashMap<>(replaceVars1);
	replaceVars2.put("TableNumber1", "NewTable");
	final Environment env2 = EnvironmentFileUtil.parseModified(
		FACTORY_ENVIRONMENT_FILE,
		replaceVars2);

	final Environment merged = Environment.merge(env1, env2);

	final Set<String> tables = new HashSet<>();
	tables.add("TableNumber1");
	tables.add("TableNumber2");
	tables.add("NewTable");
	tables.add("TableSourceSink");
	tables.add("TestView1");
	tables.add("TestView2");

	assertEquals(tables, merged.getTables().keySet());
	assertTrue(merged.getExecution().inStreamingMode());
	assertEquals(16, merged.getExecution().getMaxParallelism());

	final Map<String, String> configuration = new HashMap<>();
	configuration.put("table.optimizer.join-reorder-enabled", "true");

	assertEquals(configuration, merged.getConfiguration().asMap());
}
 
Example 6
Source File: EnvironmentTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testMerging() throws Exception {
	final Map<String, String> replaceVars1 = new HashMap<>();
	replaceVars1.put("$VAR_PLANNER", "old");
	replaceVars1.put("$VAR_EXECUTION_TYPE", "batch");
	replaceVars1.put("$VAR_RESULT_MODE", "table");
	replaceVars1.put("$VAR_UPDATE_MODE", "");
	replaceVars1.put("$VAR_MAX_ROWS", "100");
	replaceVars1.put("$VAR_RESTART_STRATEGY_TYPE", "failure-rate");
	final Environment env1 = EnvironmentFileUtil.parseModified(
		DEFAULTS_ENVIRONMENT_FILE,
		replaceVars1);

	final Map<String, String> replaceVars2 = new HashMap<>(replaceVars1);
	replaceVars2.put("TableNumber1", "NewTable");
	final Environment env2 = EnvironmentFileUtil.parseModified(
		FACTORY_ENVIRONMENT_FILE,
		replaceVars2);

	final Environment merged = Environment.merge(env1, env2);

	final Set<String> tables = new HashSet<>();
	tables.add("TableNumber1");
	tables.add("TableNumber2");
	tables.add("NewTable");
	tables.add("TableSourceSink");
	tables.add("TestView1");
	tables.add("TestView2");

	assertEquals(tables, merged.getTables().keySet());
	assertTrue(merged.getExecution().inStreamingMode());
	assertEquals(16, merged.getExecution().getMaxParallelism());

	final Map<String, String> configuration = new HashMap<>();
	configuration.put("table.optimizer.join-reorder-enabled", "true");

	assertEquals(configuration, merged.getConfiguration().asMap());
}
 
Example 7
Source File: ExecutionContext.java    From flink with Apache License 2.0 4 votes vote down vote up
public ExecutionContext(Environment defaultEnvironment, SessionContext sessionContext, List<URL> dependencies,
		Configuration flinkConfig, Options commandLineOptions, List<CustomCommandLine<?>> availableCommandLines) {
	this.sessionContext = sessionContext.copy(); // create internal copy because session context is mutable
	this.mergedEnv = Environment.merge(defaultEnvironment, sessionContext.getEnvironment());
	this.dependencies = dependencies;
	this.flinkConfig = flinkConfig;

	// create class loader
	classLoader = FlinkUserCodeClassLoaders.parentFirst(
		dependencies.toArray(new URL[dependencies.size()]),
		this.getClass().getClassLoader());

	// create catalogs
	catalogs = new LinkedHashMap<>();
	mergedEnv.getCatalogs().forEach((name, entry) ->
		catalogs.put(name, createCatalog(name, entry.asMap(), classLoader))
	);

	// create table sources & sinks.
	tableSources = new LinkedHashMap<>();
	tableSinks = new LinkedHashMap<>();
	mergedEnv.getTables().forEach((name, entry) -> {
		if (entry instanceof SourceTableEntry || entry instanceof SourceSinkTableEntry) {
			tableSources.put(name, createTableSource(mergedEnv.getExecution(), entry.asMap(), classLoader));
		}
		if (entry instanceof SinkTableEntry || entry instanceof SourceSinkTableEntry) {
			tableSinks.put(name, createTableSink(mergedEnv.getExecution(), entry.asMap(), classLoader));
		}
	});

	// create user-defined functions
	functions = new LinkedHashMap<>();
	mergedEnv.getFunctions().forEach((name, entry) -> {
		final UserDefinedFunction function = FunctionService.createFunction(entry.getDescriptor(), classLoader, false);
		functions.put(name, function);
	});

	// convert deployment options into command line options that describe a cluster
	commandLine = createCommandLine(mergedEnv.getDeployment(), commandLineOptions);
	activeCommandLine = findActiveCommandLine(availableCommandLines, commandLine);
	runOptions = createRunOptions(commandLine);
	clusterId = activeCommandLine.getClusterId(commandLine);
	clusterSpec = createClusterSpecification(activeCommandLine, commandLine);
}