Apache flink 如何使用可查询状态客户端获取flink中多个keyBy的状态?
我正在使用Flink 1.4.2,我有一个场景需要使用两个键。 例如Apache flink 如何使用可查询状态客户端获取flink中多个keyBy的状态?,apache-flink,flink-streaming,Apache Flink,Flink Streaming,我正在使用Flink 1.4.2,我有一个场景需要使用两个键。 例如 KeyedStream<UsageStatistics, Tuple> keyedStream = stream.keyBy("clusterId", "ssid"); usageCounts = keyedStream.process(new CustomProcessFunction(windowSize,queryableStateName)); 多个键的类型信息应该是什么?任何与此相关的建议/示例或参考都
KeyedStream<UsageStatistics, Tuple> keyedStream = stream.keyBy("clusterId", "ssid");
usageCounts = keyedStream.process(new CustomProcessFunction(windowSize,queryableStateName));
多个键的类型信息应该是什么?任何与此相关的建议/示例或参考都将非常有用。我找到了解决方案
我在valueStateDescription中给出了TypeHint
在弗林克工作:
TypeInformation<SsidTotalUsage> typeInformation = TypeInformation.of(new TypeHint<SsidTotalUsage>() {});
ValueStateDescriptor<SsidTotalUsage> descriptor = new ValueStateDescriptor(queryableStateName, typeInformation);
ValueStateDescriptor<SsidTotalUsage> descriptor = new ValueStateDescriptor(queryableStateName, typeInformation);
TypeInformation-TypeInformation=TypeInformation.of(new-TypeHint(){});
ValueStateDescriptor描述符=新的ValueStateDescriptor(queryableStateName,typeInformation);
在客户端:
TypeInformation<SsidTotalUsage> typeInformation = TypeInformation.of(new TypeHint<SsidTotalUsage>() {});
ValueStateDescriptor<SsidTotalUsage> descriptor = new ValueStateDescriptor(queryableStateName, typeInformation);
ValueStateDescriptor<SsidTotalUsage> descriptor = new ValueStateDescriptor(queryableStateName, typeInformation);
valuestatescriptor descriptor=新的valuestatescriptor(queryableStateName,typeInformation);
我有两个键,所以我使用了Tuple2类,并设置键的值,如下所示。
注意:如果有两个以上的键,则必须根据键选择Tuple3、Tuple4类
Tuple2<String, String> tuple = new Tuple2<>();
tuple.f0 = clusterId;
tuple.f1 = ssid;
Tuple2 tuple=new Tuple2();
tuple.f0=clusterId;
tuple.f1=ssid;
然后我提供了提示
TypeHint<Tuple2<String, String>> typeHint = new TypeHint<Tuple2<String, String>>() {};
CompletableFuture<ValueState<SsidTotalUsage>> kvState = queryableStateClient.getKvState(JobID.fromHexString(jobId), queryableStateName, tuple, typeHint, descriptor);
TypeHint-TypeHint=new-TypeHint(){};
CompletableFuture kvState=queryableStateClient.getKvState(JobID.fromHexString(JobID)、queryableStateName、元组、类型提示、描述符);
在上面的代码中,getState方法将返回ImmutableValueState
所以我需要像下面这样得到我的pojo
ImmutableValueState<SsidTotalUsage> state = (ImmutableValueState<SsidTotalUsage>) kvState.get();
totalUsage = state.value();
ImmutableValueState=(ImmutableValueState)kvState.get();
totalUsage=state.value();
感谢您为自己的问题发布解决方案,这对其他人很有帮助。Flink文档是否丢失了这些信息?如果是这样,请打开一个Jira问题来添加它,因为这样会使更多的人受益,谢谢