Google cloud platform 为异常动态创建聚合器
我们使用聚合器在处理过程中对异常进行计数Google cloud platform 为异常动态创建聚合器,google-cloud-platform,google-cloud-dataflow,Google Cloud Platform,Google Cloud Dataflow,我们使用聚合器在处理过程中对异常进行计数 public class BigTableWriter extends DoFn<String, Void> { private Aggregator<Integer, Integer> errorAggregator; public BigTableWriter(CloudBigtableOptions options) { errorAggregator = createAggregator("
public class BigTableWriter extends DoFn<String, Void> {
private Aggregator<Integer, Integer> errorAggregator;
public BigTableWriter(CloudBigtableOptions options) {
errorAggregator = createAggregator("errors",new Sum.SumIntegerFn());
}
@Override
public void processElement(DoFn<String, Void>.ProcessContext c){
try {
....do work here
}
catch(Exception ex){
errorAggregator.addValue(1);
}
}
}
公共类BigTableWriter扩展了DoFn{
专用聚合器错误聚合器;
公共BigTableWriter(CloudBigtableOptions){
errorAggregator=CreateAgregator(“errors”,new Sum.SumIntegerFn());
}
@凌驾
public void processElement(DoFn.ProcessContext c){
试一试{
……在这里工作
}
捕获(例外情况除外){
errorAggregator.addValue(1);
}
}
}
我们希望使其更细粒度,而不是保留单个聚合器来收集错误。文档说明聚合器通常是在构造函数中创建的。是否可以为catch块中的每个异常类型创建聚合器?例如,我们想做一些类似的事情
public class BigTableWriter extends DoFn<String, Void> {
private Map<String, Aggregator<Integer, Integer> aggregatorMap;
public BigTableWriter(CloudBigtableOptions options) {
aggregatorMap = new HashMap<>();
}
@Override
public void processElement(DoFn<String, Void>.ProcessContext c){
try {
....do work here
}
catch(Exception ex){
aggregateException(ex.getCause().getMessage());
}
}
public void aggregateException(String exceptionMessage) {
Aggregator<Integer, Integer> aggregator = null;
if(!aggregatorMap.containsKey(exceptionMessage){
aggregator = createAggregator(exceptionMessage,new Sum.SumIntegerFn());
}
else {
aggregator = aggregatorMap.get(exceptionMessage);
}
aggregator.put(exceptionMessage, aggregator);
}
}
公共类BigTableWriter扩展了DoFn{
私有映射不幸的是,没有。当前初始化聚合器的逻辑要求它们在图形构造时已知(即在DoFn构造期间创建)。这是一个很好的功能请求。在此处创建了一个问题来跟踪它:没有直接回答您的问题,但我看到您正在向Bigtable写信。您是否尝试过Bigtable团队开发的本机连接器?@jfkk,我们正在使用本机连接器。它是从此类调用的