本文整理匯總了Java中org.apache.flink.streaming.api.datastream.DataStream.connect方法的典型用法代碼示例。如果您正苦於以下問題:Java DataStream.connect方法的具體用法?Java DataStream.connect怎麽用?Java DataStream.connect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.flink.streaming.api.datastream.DataStream
的用法示例。
在下文中一共展示了DataStream.connect方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testOutputTypeConfigurationWithTwoInputTransformation
import org.apache.flink.streaming.api.datastream.DataStream; //導入方法依賴的package包/類
@Test
public void testOutputTypeConfigurationWithTwoInputTransformation() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
DataStream<Integer> source1 = env.fromElements(1, 10);
DataStream<Integer> source2 = env.fromElements(2, 11);
ConnectedStreams<Integer, Integer> connectedSource = source1.connect(source2);
OutputTypeConfigurableOperationWithTwoInputs outputTypeConfigurableOperation = new OutputTypeConfigurableOperationWithTwoInputs();
DataStream<Integer> result = connectedSource.transform(
"Two input and output type configurable operation",
BasicTypeInfo.INT_TYPE_INFO,
outputTypeConfigurableOperation);
result.addSink(new DiscardingSink<Integer>());
env.getStreamGraph();
assertEquals(BasicTypeInfo.INT_TYPE_INFO, outputTypeConfigurableOperation.getTypeInformation());
}
示例2: main
import org.apache.flink.streaming.api.datastream.DataStream; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
final AppConfiguration config = AppConfigurator.loadConfiguration(args);
final StreamExecutionEnvironment env = EnvConfigurator.setupExecutionEnvironment(config);
EnvConfigurator.initializeRedis(config.getRedisHostname(), config.getRedisPort());
DataStream<EventCommentFriendshipLike> events = EventCommentFriendshipLikeStreamgen.getStreamOfEvents(env, config);
SplitStream<EventCommentFriendshipLike> splitted = events.split(new FriendshipSplitter());
DataStream<Friendship> friendships = splitted.select(FriendshipSplitter.FRIENDSHIP_ONLY).map(new FriendshipOperator()).setParallelism(1).broadcast();
DataStream<EventCommentLike> eventsStream = splitted.select(FriendshipSplitter.EVENT_ALL).map(new EventCommentLikeExtractor()).keyBy(new EventCommentLikeKeyer());
ConnectedStreams<EventCommentLike, Friendship> process = eventsStream.connect(friendships);
DataStream<CommentScore> scores = process.flatMap(new CommentScoreUpdater(config.getD())).setParallelism(config.getParallelism());
DataStream<CommentRank> bests = scores.keyBy(new CommentScoreKeyer()).flatMap(new CommentRankerSort(config.getK())).setParallelism(config.getParallelism());
DataStream<CommentRank> tops = null;
if (config.getParallelism() == 1) {
tops = bests;
} else {
tops = bests.flatMap(new CommentRankMergerSort(config.getK())).setParallelism(1);
}
DataStream<CommentRank> newtops = tops.filter(new CommentRankUpdateFilter(config.getK())).setParallelism(1);
newtops.addSink(new AsStringSink<CommentRank>(config.getSinkPath(JOB_NAME)));
JobExecutionResult res = env.execute(JOB_NAME);
PerformanceWriter.write(res, config.getPerformancePath(JOB_NAME));
}