Github user rmetzger commented on a diff in the pull request:

    https://github.com/apache/flink/pull/605#discussion_r28528360
  
    --- Diff: 
flink-core/src/main/java/org/apache/flink/api/common/accumulators/OperatorStatsAccumulator.java
 ---
    @@ -0,0 +1,98 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.flink.api.common.accumulators;
    +
    +import org.apache.flink.statistics.OperatorStatistics;
    +import java.io.IOException;
    +import java.io.ObjectInputStream;
    +import java.io.ObjectOutputStream;
    +
    +/**
    + * This accumulator wraps the class {@link 
org.apache.flink.api.common.accumulators.OperatorStatisticsResult} to track
    + * estimated values for count distinct and heavy hitters. It has lower 
memory requirements than
    + * {@link org.apache.flink.api.common.accumulators.Histogram}.
    + * Our goal in accumulating stats per operator is to not only track global 
stats, but also know the local stats of the
    + * subtasks of a task. For this purpose, {@link 
org.apache.flink.api.common.accumulators.OperatorStatisticsResult}
    + * encapsulates one global accumulator and an array of local accumulators.
    + *
    + * The constructor of the class receives a subTaskIndex, and the total 
number of subtasks.
    + * Both parameters are found in the
    + * {@link org.apache.flink.api.common.functions.RuntimeContext} from where 
the constructor is called.
    + */
    +public class OperatorStatsAccumulator implements Accumulator<Object, 
OperatorStatisticsResult> {
    +
    +
    +   private OperatorStatisticsResult localValue;
    +
    +   public OperatorStatsAccumulator(int subTaskIndex, int numSubtasks){
    +           localValue = new OperatorStatisticsResult(subTaskIndex, 
numSubtasks);
    +   }
    +
    +   @Override
    +   public void add(Object value) {
    +           localValue.add(value);
    +   }
    +
    +   @Override
    +   public OperatorStatisticsResult getLocalValue() {
    +           return localValue;
    +   }
    +
    +   @Override
    +   public void resetLocal() {
    +           localValue.resetLocal();
    +   }
    +
    +   @Override
    +   public void merge(Accumulator<Object, OperatorStatisticsResult> other) {
    +           localValue.merge(other.getLocalValue());
    +   }
    +
    +   //todo this has not been tested
    +   public void write(ObjectOutputStream out) throws IOException {
    +           out.writeObject(localValue.getLocal());
    +
    +   }
    +
    +   //todo this has not been tested
    +   public void read(ObjectInputStream in) throws IOException {
    +           try {
    +                   localValue.setLocal((OperatorStatistics) 
in.readObject());
    +           } catch (ClassNotFoundException e) {
    +                   e.printStackTrace();
    --- End diff --
    
    Just doing e.printStackTrace() will make it extremely hard to debug the 
error. You'll find a stacktrace without any message in the stderr file ... The 
flink programm will continue running in an erroneous state.
    I would recommend re-throwing the exception as a runtime exception.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to