
com.google.cloud.dataflow.sdk.util.GroupAlsoByWindowsAndCombineDoFn Maven / Gradle / Ivy
/*
* Copyright (C) 2015 Google Inc.
*
* Licensed 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 com.google.cloud.dataflow.sdk.util;
import static com.google.common.base.Preconditions.checkState;
import com.google.cloud.dataflow.sdk.transforms.Combine.KeyedCombineFn;
import com.google.cloud.dataflow.sdk.transforms.windowing.BoundedWindow;
import com.google.cloud.dataflow.sdk.transforms.windowing.DefaultTrigger;
import com.google.cloud.dataflow.sdk.transforms.windowing.PaneInfo;
import com.google.cloud.dataflow.sdk.transforms.windowing.WindowFn;
import com.google.cloud.dataflow.sdk.util.WindowingStrategy.AccumulationMode;
import com.google.cloud.dataflow.sdk.values.KV;
import com.google.common.collect.Maps;
import org.joda.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
/**
* {@link GroupAlsoByWindowsDoFn} that uses combiner to accumulate input elements for non-merging
* window functions with the default triggering strategy.
*
* @param key type
* @param value input type
* @param accumulator type
* @param value output type
* @param window type
*/
@SuppressWarnings("serial")
@SystemDoFnInternal
class GroupAlsoByWindowsAndCombineDoFn
extends GroupAlsoByWindowsDoFn {
public static boolean isSupported(WindowingStrategy, ?> strategy) {
// TODO: Add support for other triggers.
if (!(strategy.getTrigger().getSpec() instanceof DefaultTrigger)) {
return false;
}
// Right now, we support ACCUMULATING_FIRED_PANES because it is the same as
// DISCARDING_FIRED_PANES. In Batch mode there is no late data so the default
// trigger (after watermark) will only fire once.
if (!strategy.getMode().equals(AccumulationMode.DISCARDING_FIRED_PANES)
&& !strategy.getMode().equals(AccumulationMode.ACCUMULATING_FIRED_PANES)) {
return false;
}
return true;
}
private final KeyedCombineFn combineFn;
private WindowFn
© 2015 - 2025 Weber Informatics LLC | Privacy Policy