connect flink_聊聊flink DataStream的connect操作

本文主要研究一下flink DataStream的connect操作

1e150f51c70d395cecd4f35b4a18bfee.png

DataStream.connect

flink-streaming-java_2.11-1.7.0-sources.jar!/org/apache/flink/streaming/api/datastream/DataStream.java

@Publicpublic class DataStream {​ //......​ public  ConnectedStreams connect(DataStream dataStream) { return new ConnectedStreams<>(environment, this, dataStream); }​ @PublicEvolving public  BroadcastConnectedStream connect(BroadcastStream broadcastStream) { return new BroadcastConnectedStream<>( environment, this, Preconditions.checkNotNull(broadcastStream), broadcastStream.getBroadcastStateDescriptor()); }​ //......}
  • DataStream的connect操作创建的是ConnectedStreams或BroadcastConnectedStream,它用了两个泛型,即不要求两个dataStream的element是同一类型

ConnectedStreams

flink-streaming-java_2.11-1.7.0-sources.jar!/org/apache/flink/streaming/api/datastream/ConnectedStreams.java

@Publicpublic class ConnectedStreams {​ protected final StreamExecutionEnvironment environment; protected final DataStream inputStream1; protected final DataStream inputStream2;​ protected ConnectedStreams(StreamExecutionEnvironment env, DataStream input1, DataStream input2) { this.environment = requireNonNull(env); this.inputStream1 = requireNonNull(input1); this.inputStream2 = requireNonNull(input2); }​ public StreamExecutionEnvironment getExecutionEnvironment() { return environment; }​ public DataStream getFirstInput() { return inputStream1; }​ public DataStream getSecondInput() { return inputStream2; }​ public TypeInformation getType1() { return inputStream1.getType(); }​ public TypeInformation getType2() { return inputStream2.getType(); }​ public ConnectedStreams keyBy(int keyPosition1, int keyPosition2) { return new ConnectedStreams<>(this.environment, inputStream1.keyBy(keyPosition1), inputStream2.keyBy(keyPosition2)); }​ public ConnectedStreams keyBy(int[] keyPositions1, int[] keyPositions2) { return new ConnectedStreams<>(environment, inputStream1.keyBy(keyPositions1), inputStream2.keyBy(keyPositions2)); }​ public ConnectedStreams keyBy(String field1, String field2) { return new ConnectedStreams<>(environment, inputStream1.keyBy(field1), inputStream2.keyBy(field2)); }​ public ConnectedStreams keyBy(String[] fields1, String[] fields2) { return new ConnectedStreams<>(environment, inputStream1.keyBy(fields1), inputStream2.keyBy(fields2)); }​ public ConnectedStreams keyBy(KeySelector keySelector1, KeySelector keySelector2) { return new ConnectedStreams<>(environment, inputStream1.keyBy(keySelector1), inputStream2.keyBy(keySelector2)); }​ public  ConnectedStreams keyBy( KeySelector keySelector1, KeySelector keySelector2, TypeInformation keyType) { return new ConnectedStreams<>( environment, inputStream1.keyBy(keySelector1, keyType), inputStream2.keyBy(keySelector2, keyType)); }​ public  SingleOutputStreamOperator map(CoMapFunction coMapper) {​ TypeInformation outTypeInfo = TypeExtractor.getBinaryOperatorReturnType( coMapper, CoMapFunction.class, 0, 1, 2, TypeExtractor.NO_INDEX, getType1(), getType2(), Utils.getCallLocationName(), true);​ return transform("Co-Map
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值