Java Code Examples for org.apache.beam.sdk.util.WindowedValue#explodeWindows()

The following examples show how to use org.apache.beam.sdk.util.WindowedValue#explodeWindows() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimplePushbackSideInputDoFnRunner.java    From beam with Apache License 2.0 6 votes vote down vote up
@Override
public Iterable<WindowedValue<InputT>> processElementInReadyWindows(WindowedValue<InputT> elem) {
  if (views.isEmpty()) {
    // When there are no side inputs, we can preserve the compressed representation.
    underlying.processElement(elem);
    return Collections.emptyList();
  }
  ImmutableList.Builder<WindowedValue<InputT>> pushedBack = ImmutableList.builder();
  for (WindowedValue<InputT> windowElem : elem.explodeWindows()) {
    BoundedWindow mainInputWindow = Iterables.getOnlyElement(windowElem.getWindows());
    if (isReady(mainInputWindow)) {
      // When there are any side inputs, we have to process the element in each window
      // individually, to disambiguate access to per-window side inputs.
      underlying.processElement(windowElem);
    } else {
      notReadyWindows.add(mainInputWindow);
      pushedBack.add(windowElem);
    }
  }
  return pushedBack.build();
}
 
Example 2
Source File: StatefulDoFnRunner.java    From beam with Apache License 2.0 6 votes vote down vote up
@Override
public void processElement(WindowedValue<InputT> input) {

  // StatefulDoFnRunner always observes windows, so we need to explode
  for (WindowedValue<InputT> value : input.explodeWindows()) {
    BoundedWindow window = value.getWindows().iterator().next();
    if (isLate(window)) {
      // The element is too late for this window.
      reportDroppedElement(value, window);
    } else if (requiresTimeSortedInput) {
      processElementOrdered(window, value);
    } else {
      processElementUnordered(window, value);
    }
  }
}
 
Example 3
Source File: FlinkStreamingTransformTranslators.java    From beam with Apache License 2.0 6 votes vote down vote up
@Override
public void flatMap(
    WindowedValue<KV<K, InputT>> inWithMultipleWindows,
    Collector<WindowedValue<SingletonKeyedWorkItem<K, InputT>>> out)
    throws Exception {

  // we need to wrap each one work item per window for now
  // since otherwise the PushbackSideInputRunner will not correctly
  // determine whether side inputs are ready
  //
  // this is tracked as https://issues.apache.org/jira/browse/BEAM-1850
  for (WindowedValue<KV<K, InputT>> in : inWithMultipleWindows.explodeWindows()) {
    SingletonKeyedWorkItem<K, InputT> workItem =
        new SingletonKeyedWorkItem<>(
            in.getValue().getKey(), in.withValue(in.getValue().getValue()));

    out.collect(WindowedValue.valueInGlobalWindow(workItem));
  }
}
 
Example 4
Source File: FlinkStreamingTransformTranslators.java    From beam with Apache License 2.0 6 votes vote down vote up
@Override
public void flatMap(
    WindowedValue<KV<K, InputT>> inWithMultipleWindows,
    Collector<WindowedValue<SingletonKeyedWorkItem<K, InputT>>> out)
    throws Exception {

  // we need to wrap each one work item per window for now
  // since otherwise the PushbackSideInputRunner will not correctly
  // determine whether side inputs are ready
  //
  // this is tracked as https://issues.apache.org/jira/browse/BEAM-1850
  for (WindowedValue<KV<K, InputT>> in : inWithMultipleWindows.explodeWindows()) {
    SingletonKeyedWorkItem<K, InputT> workItem =
        new SingletonKeyedWorkItem<>(
            in.getValue().getKey(), in.withValue(in.getValue().getValue()));

    out.collect(in.withValue(workItem));
  }
}
 
Example 5
Source File: SimpleDoFnRunner.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public void processElement(WindowedValue<InputT> compressedElem) {
  if (observesWindow) {
    for (WindowedValue<InputT> elem : compressedElem.explodeWindows()) {
      invokeProcessElement(elem);
    }
  } else {
    invokeProcessElement(compressedElem);
  }
}
 
Example 6
Source File: SparkCombineFn.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public void add(WindowedValue<InputT> value, SparkCombineFn<InputT, ValueT, AccumT, ?> context)
    throws Exception {
  for (WindowedValue<InputT> v : value.explodeWindows()) {
    SparkCombineContext ctx = context.ctxtForValue(v);
    BoundedWindow window = getWindow(v);
    TimestampCombiner combiner = context.windowingStrategy.getTimestampCombiner();
    Instant windowTimestamp =
        combiner.assign(
            window,
            context.windowingStrategy.getWindowFn().getOutputTime(v.getTimestamp(), window));
    map.compute(
        window,
        (w, windowAccumulator) -> {
          final AccumT acc;
          final Instant timestamp;
          if (windowAccumulator == null) {
            acc = context.combineFn.createAccumulator(ctx);
            timestamp = windowTimestamp;
          } else {
            acc = windowAccumulator.getValue();
            timestamp = windowAccumulator.getTimestamp();
          }
          AccumT result = context.combineFn.addInput(acc, toValue(v), ctx);
          Instant timestampCombined = combiner.combine(windowTimestamp, timestamp);
          return WindowedValue.of(result, timestampCombined, window, PaneInfo.NO_FIRING);
        });
  }
  mergeWindows(context);
}
 
Example 7
Source File: KvToKeyedWorkItemOp.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public void processElement(
    WindowedValue<KV<K, V>> inputElement, OpEmitter<KeyedWorkItem<K, V>> emitter) {
  final KV<K, V> kv = inputElement.getValue();
  for (WindowedValue<KV<K, V>> windowedValue : inputElement.explodeWindows()) {
    final KeyedWorkItem<K, V> workItem =
        new SingletonKeyedWorkItem<>(kv.getKey(), windowedValue.withValue(kv.getValue()));
    emitter.emitElement(windowedValue.withValue(workItem));
  }
}
 
Example 8
Source File: StreamingSideInputDoFnRunner.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public void processElement(WindowedValue<InputT> compressedElem) {
  for (WindowedValue<InputT> elem : compressedElem.explodeWindows()) {
    if (!sideInputFetcher.storeIfBlocked(elem)) {
      simpleDoFnRunner.processElement(elem);
    }
  }
}
 
Example 9
Source File: GroupAlsoByWindowFnRunner.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public void processElement(WindowedValue<InputT> elem) {
  if (elem.getWindows().size() <= 1 || sideInputReader.isEmpty()) {
    invokeProcessElement(elem);
  } else {
    // We could modify the windowed value (and the processContext) to
    // avoid repeated allocations, but this is more straightforward.
    for (WindowedValue<InputT> windowedValue : elem.explodeWindows()) {
      invokeProcessElement(windowedValue);
    }
  }
}
 
Example 10
Source File: WindowEvaluatorFactory.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public void processElement(WindowedValue<InputT> compressedElement) throws Exception {
  for (WindowedValue<InputT> element : compressedElement.explodeWindows()) {
    Collection<? extends BoundedWindow> windows = assignWindows(windowFn, element);
    outputBundle.add(
        WindowedValue.of(
            element.getValue(), element.getTimestamp(), windows, element.getPane()));
  }
}