private static class DataFilterFunImpl extends RichCoFlatMapFunction<KVTuple6, String, KVTuple6> {
private JSONParser parser;
private Map<String, Map<String, ControlJsonConfig>> whiteListMap = new HashMap<>();
@Override
// tuple5(domain, device_type, type, key, count_or_sum)
public void flatMap1(KVTuple6 dataTuple, Collector<KVTuple6> collector) throws Exception {
String type = dataTuple.f2;
String[] keyValue = dataTuple.f3.split(RawEventExtractor.Constants.DEFAULT_VALUE_SP);
String key = keyValue[0];
switch (type) {
case RawEventExtractor.Constants.VALUE_COUNT: {
if (whiteListMap.containsKey(key)) {
ControlJsonConfig ruleConfig = whiteListMap.get(key).get(RawEventExtractor.Constants.VALUE_COUNT);
if (ruleConfig != null) {
String value = keyValue.length > 1 ? keyValue[1] : "";
String bucket = ruleConfig.getBucketName(value);
if (bucket != null) {
dataTuple.setField(String.join(RawEventExtractor.Constants.DEFAULT_VALUE_SP, key, bucket), 3);
collector.collect(dataTuple);
}
} else {
collector.collect(dataTuple);
}
}
break;
}
case RawEventExtractor.Constants.VALUE_SUM: {
if (whiteListMap.containsKey(key) && whiteListMap.get(key).containsKey(RawEventExtractor.Constants.VALUE_SUM)) {
collector.collect(dataTuple);
}
break;
}
default: collector.collect(dataTuple);
}
}
@Override
public void flatMap2(String jsonStr, Collector<KVTuple6> collector) throws Exception {
// Map<String, Map<String, ControlJsonConfig>> whiteListMap = whiteListMapState.value();
try {
if (parser == null) {
parser = new JSONParser();
}
JSONObject jsonConfig = (JSONObject) parser.parse(jsonStr);
Tuple2<String, Map<String, ControlJsonConfig>> config = RawEventExtractor.getKeyConfig(jsonConfig);
if (config.f1 == null) {
whiteListMap.remove(config.f0);
} else {
whiteListMap.put(config.f0, config.f1);
}
} catch (Exception e) {}
}
}
FYI, if I setParallelism of both the control stream and data stream, the window function works. Is it necessary to do so for broadcast() function?