Github user tammymendt commented on a diff in the pull request: https://github.com/apache/flink/pull/605#discussion_r28776656 --- Diff: flink-core/src/main/java/org/apache/flink/statistics/OperatorStatistics.java --- @@ -0,0 +1,154 @@ +/* + * 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.statistics; + +import com.clearspring.analytics.stream.cardinality.CardinalityMergeException; +import com.clearspring.analytics.stream.cardinality.HyperLogLog; +import com.clearspring.analytics.stream.cardinality.ICardinality; +import com.clearspring.analytics.stream.cardinality.LinearCounting; +import org.apache.flink.statistics.heavyhitters.IHeavyHitter; +import org.apache.flink.statistics.heavyhitters.LossyCounting; +import org.apache.flink.statistics.heavyhitters.CountMinHeavyHitter; +import org.apache.flink.statistics.heavyhitters.HeavyHitterMergeException; + +import java.io.Serializable; +import java.util.Map; + +/** + * Data structure that encapsulates statistical information of data that has only been processed by one pass + * This statistical information is meant to help determine the distribution of the data that has been processed + * in an operator so that we can determine if it is necessary to repartition the data + * + * The statistics to be gathered are configurable and represented by a {@link OperatorStatisticsConfig} object. + * + * The information encapsulated in this class is min, max, a structure enabling estimation of count distinct and a + * structure holding the heavy hitters along with their frequency. + * + */ +public class OperatorStatistics implements Serializable { + + OperatorStatisticsConfig config; + + Object min; + Object max; + ICardinality countDistinct; + IHeavyHitter heavyHitter; + long cardinality = 0; + + public OperatorStatistics(OperatorStatisticsConfig config) { + this.config = config; + if (config.countDistinctAlgorithm.equals(OperatorStatisticsConfig.CountDistinctAlgorithm.LINEAR_COUNTING)) { + countDistinct = new LinearCounting(OperatorStatisticsConfig.COUNTD_BITMAP_SIZE); + } + if(config.countDistinctAlgorithm.equals(OperatorStatisticsConfig.CountDistinctAlgorithm.HYPERLOGLOG)){ + countDistinct = new HyperLogLog(OperatorStatisticsConfig.COUNTD_LOG2M); + } + if (config.heavyHitterAlgorithm.equals(OperatorStatisticsConfig.HeavyHitterAlgorithm.LOSSY_COUNTING)){ + heavyHitter = + new LossyCounting(OperatorStatisticsConfig.HEAVY_HITTER_FRACTION, OperatorStatisticsConfig.HEAVY_HITTER_ERROR); + } + if (config.heavyHitterAlgorithm.equals(OperatorStatisticsConfig.HeavyHitterAlgorithm.COUNT_MIN_SKETCH)){ + heavyHitter = + new CountMinHeavyHitter(OperatorStatisticsConfig.HEAVY_HITTER_FRACTION, + OperatorStatisticsConfig.HEAVY_HITTER_ERROR, + OperatorStatisticsConfig.HEAVY_HITTER_CONFIDENCE, + OperatorStatisticsConfig.HEAVY_HITTER_SEED); + } + } + + public void process(Object tupleObject){ --- End diff -- The problem with processing only every n-th element is that precision would be affected, and the algorithms are already estimating as it is. I am planning to measure performance overhead but haven't done it so far. I have removed unnecessary checks inside the "process" function. The point of them was to allow the user to configure which stats wished to be tracked, by means of the OperatorStatisticsConfig class. This way for example an OperatorStatisticsAccumulator could be defined, but only used to track count distinct. Do you think this makes sense, or is it preferable to create multiple accumulators, one for each type of statistic? I was avoiding this because the common case would be to want all 4 statistics (max, min, heavy hitters and count distinct), and I didn't want the user to have to create 4 separate accumulators for this purpose.
--- 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. ---