I would like to declare a flink mapState as below which value type is a pojo arraylist, what should I set its value class type?
private transient MapState<String, List<pojo>> mapState;
mapState = getRuntimeContext().getMapState(
new MapStateDescriptor<String, List<pojo>>(
"RIGHT_BUFFER",
String.class,
???
)
);
it's not okay when I set value type to pojo.class
or List.class
. how to handle it?
private final MapStateDescriptor<String, List<Pojo>> mapStateDesc =
new MapStateDescriptor<>(
"RIGHT_BUFFER",
BasicTypeInfo.STRING_TYPE_INFO,
new ListTypeInfo<>(Pojo.class));
You need to use TypeInformation
with TypeHint
to handle generic classes. Something like:
mapState = getRuntimeContext().getMapState(
new MapStateDescriptor<String, List<pojo>>(
"RIGHT_BUFFER",
TypeInformation.of(String.class),
TypeInformation.of(new TypeHint<List<pojo>>() {})
)
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.