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 Project: flink   Author: apache   File: ExecutionContextTest.java    License: 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 #2
Source Project: flink   Author: apache   File: CliClientTest.java    License: 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 #3
Source Project: flink   Author: apache   File: ExecutionContextTest.java    License: 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 #4
Source Project: flink   Author: apache   File: LocalExecutorITCase.java    License: 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 #5
Source Project: flink   Author: flink-tpc-ds   File: LocalExecutorITCase.java    License: 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 #6
Source Project: flink   Author: flink-tpc-ds   File: LocalExecutorITCase.java    License: 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 #7
Source Project: flink   Author: apache   File: LocalExecutorITCase.java    License: 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 #8
Source Project: flink   Author: flink-tpc-ds   File: CliClientTest.java    License: 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 #9
Source Project: flink   Author: apache   File: LocalExecutorITCase.java    License: 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 #10
Source Project: flink   Author: apache   File: LocalExecutorITCase.java    License: 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 Project: flink   Author: apache   File: ExecutionContext.java    License: 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 #12
Source Project: flink   Author: apache   File: LocalExecutor.java    License: 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 #13
Source Project: flink   Author: apache   File: DependencyTest.java    License: 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 #14
Source Project: flink   Author: apache   File: CliClientTest.java    License: 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 #15
Source Project: flink   Author: apache   File: LocalExecutorITCase.java    License: 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 Project: flink   Author: apache   File: LocalExecutorITCase.java    License: 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 #17
Source Project: Flink-CEPplus   Author: ljygz   File: ExecutionContext.java    License: 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 #18
Source Project: Flink-CEPplus   Author: ljygz   File: LocalExecutor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, String> getSessionProperties(SessionContext session) throws SqlExecutionException {
	final Environment env = getOrCreateExecutionContext(session)
		.getMergedEnvironment();
	final Map<String, String> properties = new HashMap<>();
	properties.putAll(env.getExecution().asTopLevelMap());
	properties.putAll(env.getDeployment().asTopLevelMap());
	return properties;
}
 
Example #19
Source Project: Flink-CEPplus   Author: ljygz   File: ResultStore.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a result. Might start threads or opens sockets so every created result must be closed.
 */
public <T> DynamicResult<T> createResult(Environment env, TableSchema schema, ExecutionConfig config) {

	final TypeInformation<Row> outputType = Types.ROW_NAMED(schema.getFieldNames(), schema.getFieldTypes());

	if (env.getExecution().isStreamingExecution()) {
		// determine gateway address (and port if possible)
		final InetAddress gatewayAddress = getGatewayAddress(env.getDeployment());
		final int gatewayPort = getGatewayPort(env.getDeployment());

		if (env.getExecution().isChangelogMode()) {
			return new ChangelogCollectStreamResult<>(outputType, config, gatewayAddress, gatewayPort);
		} else {
			return new MaterializedCollectStreamResult<>(
				outputType,
				config,
				gatewayAddress,
				gatewayPort,
				env.getExecution().getMaxTableResultRows());
		}

	} else {
		// Batch Execution
		if (!env.getExecution().isTableMode()) {
			throw new SqlExecutionException("Results of batch queries can only be served in table mode.");
		}
		return new MaterializedCollectBatchResult<>(outputType, config);
	}
}
 
Example #20
Source Project: Flink-CEPplus   Author: ljygz   File: SessionContext.java    License: Apache License 2.0 5 votes vote down vote up
public SessionContext(String name, Environment defaultEnvironment) {
	this.name = name;
	this.defaultEnvironment = defaultEnvironment;
	this.sessionProperties = new HashMap<>();
	// the order of how views are registered matters because
	// they might reference each other
	this.views = new LinkedHashMap<>();
}
 
Example #21
Source Project: Flink-CEPplus   Author: ljygz   File: LocalExecutorITCase.java    License: Apache License 2.0 5 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());

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

	final List<String> expectedTables = Arrays.asList(
		"TableNumber1",
		"TableNumber2",
		"TableSourceSink",
		"TestView1",
		"TestView2");
	assertEquals(expectedTables, actualTables);
}
 
Example #22
Source Project: Flink-CEPplus   Author: ljygz   File: LocalExecutorITCase.java    License: 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 #23
Source Project: Flink-CEPplus   Author: ljygz   File: LocalExecutorITCase.java    License: 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.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("deployment.response-timeout", "5000");

	assertEquals(expectedProperties, actualProperties);
}
 
Example #24
Source Project: Flink-CEPplus   Author: ljygz   File: LocalExecutorITCase.java    License: Apache License 2.0 5 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());

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

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

	assertEquals(expectedTableSchema, actualTableSchema);
}
 
Example #25
Source Project: flink   Author: apache   File: LocalExecutorITCase.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateFunction() throws Exception {
	final Executor executor = createDefaultExecutor(clusterClient);
	final SessionContext session = new SessionContext("test-session", new Environment());
	String sessionId = executor.openSession(session);
	// arguments: [TEMPORARY|TEMPORARY SYSTEM], [IF NOT EXISTS], func_name
	final String ddlTemplate = "create %s function %s %s \n"
			+ "as 'org.apache.flink.table.client.gateway.local.LocalExecutorITCase$TestScalaFunction' LANGUAGE JAVA";
	try {
		// Test create table with simple name.
		executor.useCatalog(sessionId, "catalog1");
		executor.executeSql(sessionId, String.format(ddlTemplate, "", "", "func1"));
		assertThat(executor.listFunctions(sessionId), hasItems("func1"));
		executor.executeSql(sessionId, String.format(ddlTemplate, "TEMPORARY", "IF NOT EXISTS", "func2"));
		assertThat(executor.listFunctions(sessionId), hasItems("func1", "func2"));

		// Test create function with full qualified name.
		executor.useCatalog(sessionId, "catalog1");
		executor.createTable(sessionId, String.format(ddlTemplate, "", "", "`simple-catalog`.`default_database`.func3"));
		executor.createTable(sessionId, String.format(ddlTemplate, "TEMPORARY", "IF NOT EXISTS", "`simple-catalog`.`default_database`.func4"));
		assertThat(executor.listFunctions(sessionId), hasItems("func1", "func2"));
		executor.useCatalog(sessionId, "simple-catalog");
		assertThat(executor.listFunctions(sessionId), hasItems("func3", "func4"));

		// Test create function with db and table name.
		executor.useCatalog(sessionId, "catalog1");
		executor.createTable(sessionId, String.format(ddlTemplate, "TEMPORARY", "", "`default`.func5"));
		executor.createTable(sessionId, String.format(ddlTemplate, "TEMPORARY", "", "`default`.func6"));
		assertThat(executor.listFunctions(sessionId), hasItems("func1", "func2", "func5", "func6"));
	} finally {
		executor.closeSession(sessionId);
	}
}
 
Example #26
Source Project: Flink-CEPplus   Author: ljygz   File: LocalExecutorITCase.java    License: Apache License 2.0 5 votes vote down vote up
@Test(timeout = 30_000L)
public void testStreamQueryExecutionChangelog() throws Exception {
	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_RESULT_MODE", "changelog");
	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 and retrieval
		final ResultDescriptor desc = executor.executeQuery(
			session,
			"SELECT scalarUDF(IntegerField1), StringField1 FROM TableNumber1");

		assertFalse(desc.isMaterialized());

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

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

		TestBaseUtils.compareResultCollections(expectedResults, actualResults, Comparator.naturalOrder());
	} finally {
		executor.stop(session);
	}
}
 
Example #27
Source Project: Flink-CEPplus   Author: ljygz   File: LocalExecutorITCase.java    License: Apache License 2.0 5 votes vote down vote up
@Test(timeout = 30_000L)
public void testBatchQueryExecution() throws Exception {
	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", "batch");
	replaceVars.put("$VAR_RESULT_MODE", "table");
	replaceVars.put("$VAR_UPDATE_MODE", "");
	replaceVars.put("$VAR_MAX_ROWS", "100");

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

	try {
		final ResultDescriptor desc = executor.executeQuery(session, "SELECT * FROM TestView1");

		assertTrue(desc.isMaterialized());

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

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

		TestBaseUtils.compareResultCollections(expectedResults, actualResults, Comparator.naturalOrder());
	} finally {
		executor.stop(session);
	}
}
 
Example #28
Source Project: flink   Author: apache   File: EnvironmentTest.java    License: 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 #29
Source Project: Flink-CEPplus   Author: ljygz   File: DependencyTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testTableFactoryDiscovery() throws Exception {
	// create environment
	final Map<String, String> replaceVars = new HashMap<>();
	replaceVars.put("$VAR_CONNECTOR_TYPE", CONNECTOR_TYPE_VALUE);
	replaceVars.put("$VAR_CONNECTOR_PROPERTY", TEST_PROPERTY);
	replaceVars.put("$VAR_CONNECTOR_PROPERTY_VALUE", "test-value");
	final Environment env = EnvironmentFileUtil.parseModified(FACTORY_ENVIRONMENT_FILE, replaceVars);

	// create executor with dependencies
	final URL dependency = Paths.get("target", TABLE_FACTORY_JAR_FILE).toUri().toURL();
	final LocalExecutor executor = new LocalExecutor(
		env,
		Collections.singletonList(dependency),
		new Configuration(),
		new DefaultCLI(new Configuration()));

	final SessionContext session = new SessionContext("test-session", new Environment());

	final TableSchema result = executor.getTableSchema(session, "TableNumber1");
	final TableSchema expected = TableSchema.builder()
		.field("IntegerField1", Types.INT())
		.field("StringField1", Types.STRING())
		.field("rowtimeField", Types.SQL_TIMESTAMP())
		.build();

	assertEquals(expected, result);
}
 
Example #30
Source Project: Flink-CEPplus   Author: ljygz   File: EnvironmentTest.java    License: 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());
}