org.apache.flink.table.client.config.entries.TemporalTableEntry Java Examples

The following examples show how to use org.apache.flink.table.client.config.entries.TemporalTableEntry. 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-CEPplus with Apache License 2.0 6 votes vote down vote up
private void registerTemporalTable(TemporalTableEntry temporalTableEntry) {
	try {
		final Table table = tableEnv.scan(temporalTableEntry.getHistoryTable());
		final TableFunction<?> function = table.createTemporalTableFunction(
			temporalTableEntry.getTimeAttribute(),
			String.join(",", temporalTableEntry.getPrimaryKeyFields()));
		if (tableEnv instanceof StreamTableEnvironment) {
			StreamTableEnvironment streamTableEnvironment = (StreamTableEnvironment) tableEnv;
			streamTableEnvironment.registerFunction(temporalTableEntry.getName(), function);
		} else {
			BatchTableEnvironment batchTableEnvironment = (BatchTableEnvironment) tableEnv;
			batchTableEnvironment.registerFunction(temporalTableEntry.getName(), function);
		}
	} catch (Exception e) {
		throw new SqlExecutionException(
			"Invalid temporal table '" + temporalTableEntry.getName() + "' over table '" +
				temporalTableEntry.getHistoryTable() + ".\nCause: " + e.getMessage());
	}
}
 
Example #2
Source File: ExecutionContext.java    From flink with Apache License 2.0 6 votes vote down vote up
private void registerTemporalTable(TemporalTableEntry temporalTableEntry) {
	try {
		final Table table = tableEnv.scan(temporalTableEntry.getHistoryTable());
		final TableFunction<?> function = table.createTemporalTableFunction(
			temporalTableEntry.getTimeAttribute(),
			String.join(",", temporalTableEntry.getPrimaryKeyFields()));
		if (tableEnv instanceof StreamTableEnvironment) {
			StreamTableEnvironment streamTableEnvironment = (StreamTableEnvironment) tableEnv;
			streamTableEnvironment.registerFunction(temporalTableEntry.getName(), function);
		} else {
			BatchTableEnvironment batchTableEnvironment = (BatchTableEnvironment) tableEnv;
			batchTableEnvironment.registerFunction(temporalTableEntry.getName(), function);
		}
	} catch (Exception e) {
		throw new SqlExecutionException(
			"Invalid temporal table '" + temporalTableEntry.getName() + "' over table '" +
				temporalTableEntry.getHistoryTable() + ".\nCause: " + e.getMessage());
	}
}
 
Example #3
Source File: ExecutionContext.java    From flink with Apache License 2.0 6 votes vote down vote up
private void registerTemporalTable(TemporalTableEntry temporalTableEntry) {
	try {
		final Table table = tableEnv.from(temporalTableEntry.getHistoryTable());
		List<String> primaryKeyFields = temporalTableEntry.getPrimaryKeyFields();
		if (primaryKeyFields.size() > 1) {
			throw new ValidationException("Temporal tables over a composite primary key are not supported yet.");
		}
		final TableFunction<?> function = table.createTemporalTableFunction(
			$(temporalTableEntry.getTimeAttribute()),
			$(primaryKeyFields.get(0)));
		if (tableEnv instanceof StreamTableEnvironment) {
			StreamTableEnvironment streamTableEnvironment = (StreamTableEnvironment) tableEnv;
			streamTableEnvironment.registerFunction(temporalTableEntry.getName(), function);
		} else {
			BatchTableEnvironment batchTableEnvironment = (BatchTableEnvironment) tableEnv;
			batchTableEnvironment.registerFunction(temporalTableEntry.getName(), function);
		}
	} catch (Exception e) {
		throw new SqlExecutionException(
			"Invalid temporal table '" + temporalTableEntry.getName() + "' over table '" +
				temporalTableEntry.getHistoryTable() + ".\nCause: " + e.getMessage());
	}
}
 
Example #4
Source File: ExecutionContext.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private EnvironmentInstance() {
	// create environments
	if (mergedEnv.getExecution().isStreamingExecution()) {
		streamExecEnv = createStreamExecutionEnvironment();
		execEnv = null;
		tableEnv = StreamTableEnvironment.create(streamExecEnv);
	} else if (mergedEnv.getExecution().isBatchExecution()) {
		streamExecEnv = null;
		execEnv = createExecutionEnvironment();
		tableEnv = BatchTableEnvironment.create(execEnv);
	} else {
		throw new SqlExecutionException("Unsupported execution type specified.");
	}

	// create query config
	queryConfig = createQueryConfig();

	// register table sources
	tableSources.forEach(tableEnv::registerTableSource);

	// register table sinks
	tableSinks.forEach(tableEnv::registerTableSink);

	// register user-defined functions
	registerFunctions();

	// register views and temporal tables in specified order
	mergedEnv.getTables().forEach((name, entry) -> {
		// if registering a view fails at this point,
		// it means that it accesses tables that are not available anymore
		if (entry instanceof ViewEntry) {
			final ViewEntry viewEntry = (ViewEntry) entry;
			registerView(viewEntry);
		} else if (entry instanceof TemporalTableEntry) {
			final TemporalTableEntry temporalTableEntry = (TemporalTableEntry) entry;
			registerTemporalTable(temporalTableEntry);
		}
	});
}
 
Example #5
Source File: ExecutionContext.java    From flink with Apache License 2.0 4 votes vote down vote up
private EnvironmentInstance() {
	// create settings
	final EnvironmentSettings settings = mergedEnv.getExecution().getEnvironmentSettings();

	// create environments
	if (mergedEnv.getExecution().isStreamingPlanner()) {
		streamExecEnv = createStreamExecutionEnvironment();
		execEnv = null;

		final Map<String, String> executorProperties = settings.toExecutorProperties();
		executor = lookupExecutor(executorProperties, streamExecEnv);
		tableEnv = createStreamTableEnvironment(streamExecEnv, settings, executor);
	} else if (mergedEnv.getExecution().isBatchPlanner()) {
		streamExecEnv = null;
		execEnv = createExecutionEnvironment();
		executor = null;
		tableEnv = BatchTableEnvironment.create(execEnv);
	} else {
		throw new SqlExecutionException("Unsupported execution type specified.");
	}

	// set table configuration
	mergedEnv.getConfiguration().asMap().forEach((k, v) ->
		tableEnv.getConfig().getConfiguration().setString(k, v));

	// register catalogs
	catalogs.forEach(tableEnv::registerCatalog);

	// create query config
	queryConfig = createQueryConfig();

	// register table sources
	tableSources.forEach(tableEnv::registerTableSource);

	// register table sinks
	tableSinks.forEach(tableEnv::registerTableSink);

	// register user-defined functions
	registerFunctions();

	// register views and temporal tables in specified order
	mergedEnv.getTables().forEach((name, entry) -> {
		// if registering a view fails at this point,
		// it means that it accesses tables that are not available anymore
		if (entry instanceof ViewEntry) {
			final ViewEntry viewEntry = (ViewEntry) entry;
			registerView(viewEntry);
		} else if (entry instanceof TemporalTableEntry) {
			final TemporalTableEntry temporalTableEntry = (TemporalTableEntry) entry;
			registerTemporalTable(temporalTableEntry);
		}
	});

	// set current catalog
	if (sessionContext.getCurrentCatalog().isPresent()) {
		tableEnv.useCatalog(sessionContext.getCurrentCatalog().get());
	} else if (mergedEnv.getExecution().getCurrentCatalog().isPresent()) {
		tableEnv.useCatalog(mergedEnv.getExecution().getCurrentCatalog().get());
	}

	// set current database
	if (sessionContext.getCurrentDatabase().isPresent()) {
		tableEnv.useDatabase(sessionContext.getCurrentDatabase().get());
	} else if (mergedEnv.getExecution().getCurrentDatabase().isPresent()) {
		tableEnv.useDatabase(mergedEnv.getExecution().getCurrentDatabase().get());
	}
}