flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mbalassi <...@git.apache.org>
Subject [GitHub] flink pull request: Windowing features / fixes
Date Mon, 09 Mar 2015 17:31:14 GMT
Github user mbalassi commented on a diff in the pull request:

    https://github.com/apache/flink/pull/465#discussion_r26056710
  
    --- Diff: flink-staging/flink-streaming/flink-streaming-core/src/main/java/org/apache/flink/streaming/api/windowing/windowbuffer/SlidingPreReducer.java
---
    @@ -0,0 +1,174 @@
    +/*
    + * 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.streaming.api.windowing.windowbuffer;
    +
    +import java.util.LinkedList;
    +
    +import org.apache.flink.api.common.functions.ReduceFunction;
    +import org.apache.flink.api.common.typeutils.TypeSerializer;
    +import org.apache.flink.streaming.api.windowing.StreamWindow;
    +import org.apache.flink.util.Collector;
    +
    +public abstract class SlidingPreReducer<T> implements WindowBuffer<T>, CompletePreAggregator
{
    +
    +	private static final long serialVersionUID = 1L;
    +
    +	protected ReduceFunction<T> reducer;
    +
    +	protected T currentReduced;
    +	protected LinkedList<T> reduced = new LinkedList<T>();
    +	protected LinkedList<Integer> elementsPerPreAggregate = new LinkedList<Integer>();
    +
    +	protected TypeSerializer<T> serializer;
    +
    +	protected int toRemove = 0;
    +
    +	protected int elementsSinceLastPreAggregate = 0;
    +
    +	public SlidingPreReducer(ReduceFunction<T> reducer, TypeSerializer<T> serializer)
{
    +		this.reducer = reducer;
    +		this.serializer = serializer;
    +	}
    +
    +	public boolean emitWindow(Collector<StreamWindow<T>> collector) {
    +		StreamWindow<T> currentWindow = new StreamWindow<T>();
    +
    +		try {
    +			if (addFinalAggregate(currentWindow)) {
    +				collector.collect(currentWindow);
    +				afterEmit();
    +				return true;
    +			} else {
    +				afterEmit();
    +				return false;
    +			}
    +		} catch (Exception e) {
    +			throw new RuntimeException(e);
    +		}
    +
    +	}
    +
    +	protected void afterEmit() {
    +		// Do nothing by default
    +	}
    +
    +	public boolean addFinalAggregate(StreamWindow<T> currentWindow) throws Exception
{
    +		T finalReduce = null;
    +
    +		if (!reduced.isEmpty()) {
    +			finalReduce = reduced.get(0);
    +			for (int i = 1; i < reduced.size(); i++) {
    +				finalReduce = reducer.reduce(finalReduce, serializer.copy(reduced.get(i)));
    +
    +			}
    +			if (currentReduced != null) {
    +				finalReduce = reducer.reduce(finalReduce, serializer.copy(currentReduced));
    +			}
    +
    +		} else {
    +			finalReduce = currentReduced;
    +		}
    +
    +		if (finalReduce != null) {
    +			currentWindow.add(finalReduce);
    +			return true;
    +		} else {
    +			return false;
    +		}
    +
    +	}
    +
    +	public void store(T element) throws Exception {
    +		addToBufferIfEligible(element);
    +		afterStore();
    +	}
    +
    +	protected void afterStore() {
    +		// Do nothing by default
    +	}
    --- End diff --
    
    What is the rationale behind this method?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message