Search in sources :

Example 1 with AccumulationMode

use of org.apache.beam.sdk.values.WindowingStrategy.AccumulationMode in project beam by apache.

the class WindowingStrategyTranslation method fromProto.

/**
   * Converts from {@link RunnerApi.WindowingStrategy} to the SDK's {@link WindowingStrategy} using
   * the provided components to dereferences identifiers found in the proto.
   */
public static WindowingStrategy<?, ?> fromProto(RunnerApi.WindowingStrategy proto, Components components) throws InvalidProtocolBufferException {
    SdkFunctionSpec windowFnSpec = proto.getWindowFn();
    WindowFn<?, ?> windowFn = windowFnFromProto(windowFnSpec);
    TimestampCombiner timestampCombiner = timestampCombinerFromProto(proto.getOutputTime());
    AccumulationMode accumulationMode = fromProto(proto.getAccumulationMode());
    Trigger trigger = TriggerTranslation.fromProto(proto.getTrigger());
    ClosingBehavior closingBehavior = fromProto(proto.getClosingBehavior());
    Duration allowedLateness = Duration.millis(proto.getAllowedLateness());
    return WindowingStrategy.of(windowFn).withAllowedLateness(allowedLateness).withMode(accumulationMode).withTrigger(trigger).withTimestampCombiner(timestampCombiner).withClosingBehavior(closingBehavior);
}
Also used : SdkFunctionSpec(org.apache.beam.sdk.common.runner.v1.RunnerApi.SdkFunctionSpec) Trigger(org.apache.beam.sdk.transforms.windowing.Trigger) TimestampCombiner(org.apache.beam.sdk.transforms.windowing.TimestampCombiner) AccumulationMode(org.apache.beam.sdk.values.WindowingStrategy.AccumulationMode) Duration(org.joda.time.Duration) ClosingBehavior(org.apache.beam.sdk.transforms.windowing.Window.ClosingBehavior)

Example 2 with AccumulationMode

use of org.apache.beam.sdk.values.WindowingStrategy.AccumulationMode in project beam by apache.

the class TriggerStateMachineTester method forTrigger.

public static <W extends BoundedWindow> SimpleTriggerStateMachineTester<W> forTrigger(TriggerStateMachine stateMachine, WindowFn<Object, W> windowFn) throws Exception {
    ExecutableTriggerStateMachine executableTriggerStateMachine = ExecutableTriggerStateMachine.create(stateMachine);
    // Merging requires accumulation mode or early firings can break up a session.
    // Not currently an issue with the tester (because we never GC) but we don't want
    // mystery failures due to violating this need.
    AccumulationMode mode = windowFn.isNonMerging() ? AccumulationMode.DISCARDING_FIRED_PANES : AccumulationMode.ACCUMULATING_FIRED_PANES;
    return new SimpleTriggerStateMachineTester<>(executableTriggerStateMachine, windowFn, Duration.ZERO);
}
Also used : AccumulationMode(org.apache.beam.sdk.values.WindowingStrategy.AccumulationMode)

Example 3 with AccumulationMode

use of org.apache.beam.sdk.values.WindowingStrategy.AccumulationMode in project beam by apache.

the class TriggerStateMachineTester method forAdvancedTrigger.

public static <InputT, W extends BoundedWindow> TriggerStateMachineTester<InputT, W> forAdvancedTrigger(TriggerStateMachine stateMachine, WindowFn<Object, W> windowFn) throws Exception {
    ExecutableTriggerStateMachine executableTriggerStateMachine = ExecutableTriggerStateMachine.create(stateMachine);
    // Merging requires accumulation mode or early firings can break up a session.
    // Not currently an issue with the tester (because we never GC) but we don't want
    // mystery failures due to violating this need.
    AccumulationMode mode = windowFn.isNonMerging() ? AccumulationMode.DISCARDING_FIRED_PANES : AccumulationMode.ACCUMULATING_FIRED_PANES;
    return new TriggerStateMachineTester<>(executableTriggerStateMachine, windowFn, Duration.ZERO);
}
Also used : AccumulationMode(org.apache.beam.sdk.values.WindowingStrategy.AccumulationMode)

Example 4 with AccumulationMode

use of org.apache.beam.sdk.values.WindowingStrategy.AccumulationMode in project beam by apache.

the class WindowingStrategyTranslation method fromProto.

/**
 * Converts from {@link RunnerApi.WindowingStrategy} to the SDK's {@link WindowingStrategy} using
 * the provided components to dereferences identifiers found in the proto.
 */
public static WindowingStrategy<?, ?> fromProto(RunnerApi.WindowingStrategy proto, RehydratedComponents components) throws InvalidProtocolBufferException {
    FunctionSpec windowFnSpec = proto.getWindowFn();
    WindowFn<?, ?> windowFn = windowFnFromProto(windowFnSpec);
    TimestampCombiner timestampCombiner = timestampCombinerFromProto(proto.getOutputTime());
    AccumulationMode accumulationMode = fromProto(proto.getAccumulationMode());
    Trigger trigger = TriggerTranslation.fromProto(proto.getTrigger());
    ClosingBehavior closingBehavior = fromProto(proto.getClosingBehavior());
    Duration allowedLateness = Duration.millis(proto.getAllowedLateness());
    OnTimeBehavior onTimeBehavior = fromProto(proto.getOnTimeBehavior());
    String environmentId = proto.getEnvironmentId();
    return WindowingStrategy.of(windowFn).withAllowedLateness(allowedLateness).withMode(accumulationMode).withTrigger(trigger).withTimestampCombiner(timestampCombiner).withClosingBehavior(closingBehavior).withOnTimeBehavior(onTimeBehavior).withEnvironmentId(environmentId);
}
Also used : Trigger(org.apache.beam.sdk.transforms.windowing.Trigger) TimestampCombiner(org.apache.beam.sdk.transforms.windowing.TimestampCombiner) FunctionSpec(org.apache.beam.model.pipeline.v1.RunnerApi.FunctionSpec) AccumulationMode(org.apache.beam.sdk.values.WindowingStrategy.AccumulationMode) Duration(org.joda.time.Duration) ByteString(org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString) OnTimeBehavior(org.apache.beam.sdk.transforms.windowing.Window.OnTimeBehavior) ClosingBehavior(org.apache.beam.sdk.transforms.windowing.Window.ClosingBehavior)

Example 5 with AccumulationMode

use of org.apache.beam.sdk.values.WindowingStrategy.AccumulationMode in project beam by apache.

the class JoinTest method testBuild_OptionalWindowing.

@Test
public void testBuild_OptionalWindowing() {
    final Pipeline pipeline = TestUtils.createTestPipeline();
    final PCollection<String> left = TestUtils.createMockDataset(pipeline, TypeDescriptors.strings());
    final PCollection<String> right = TestUtils.createMockDataset(pipeline, TypeDescriptors.strings());
    final PCollection<KV<Integer, String>> joined = Join.named("Join1").of(left, right).by(String::length, String::length).using((String l, String r, Collector<String> c) -> c.collect(l + r)).applyIf(true, b -> b.windowBy(FixedWindows.of(org.joda.time.Duration.standardHours(1))).triggeredBy(AfterWatermark.pastEndOfWindow()).accumulationMode(AccumulationMode.DISCARDING_FIRED_PANES)).output();
    final Join join = (Join) TestUtils.getProducer(joined);
    assertTrue(join.getWindow().isPresent());
    final Window<?> window = (Window) join.getWindow().get();
    assertEquals(FixedWindows.of(org.joda.time.Duration.standardHours(1)), window.getWindowFn());
    assertEquals(AfterWatermark.pastEndOfWindow(), WindowDesc.of(window).getTrigger());
    assertEquals(AccumulationMode.DISCARDING_FIRED_PANES, WindowDesc.of(window).getAccumulationMode());
}
Also used : KV(org.apache.beam.sdk.values.KV) TypeDescriptor(org.apache.beam.sdk.values.TypeDescriptor) AccumulationMode(org.apache.beam.sdk.values.WindowingStrategy.AccumulationMode) AfterWatermark(org.apache.beam.sdk.transforms.windowing.AfterWatermark) Assert.assertNotNull(org.junit.Assert.assertNotNull) WindowDesc(org.apache.beam.sdk.transforms.windowing.WindowDesc) Duration(org.joda.time.Duration) RunWith(org.junit.runner.RunWith) Assert.assertTrue(org.junit.Assert.assertTrue) FixedWindows(org.apache.beam.sdk.transforms.windowing.FixedWindows) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) PCollection(org.apache.beam.sdk.values.PCollection) Rule(org.junit.Rule) Assert.assertFalse(org.junit.Assert.assertFalse) TestPipeline(org.apache.beam.sdk.testing.TestPipeline) TypeDescriptors(org.apache.beam.sdk.values.TypeDescriptors) TypePropagationAssert(org.apache.beam.sdk.extensions.euphoria.core.client.type.TypePropagationAssert) Window(org.apache.beam.sdk.transforms.windowing.Window) Optional(java.util.Optional) Pipeline(org.apache.beam.sdk.Pipeline) Assert.assertEquals(org.junit.Assert.assertEquals) Collector(org.apache.beam.sdk.extensions.euphoria.core.client.io.Collector) Window(org.apache.beam.sdk.transforms.windowing.Window) Collector(org.apache.beam.sdk.extensions.euphoria.core.client.io.Collector) KV(org.apache.beam.sdk.values.KV) TestPipeline(org.apache.beam.sdk.testing.TestPipeline) Pipeline(org.apache.beam.sdk.Pipeline) Test(org.junit.Test)

Aggregations

AccumulationMode (org.apache.beam.sdk.values.WindowingStrategy.AccumulationMode)5 Duration (org.joda.time.Duration)3 TimestampCombiner (org.apache.beam.sdk.transforms.windowing.TimestampCombiner)2 Trigger (org.apache.beam.sdk.transforms.windowing.Trigger)2 ClosingBehavior (org.apache.beam.sdk.transforms.windowing.Window.ClosingBehavior)2 Optional (java.util.Optional)1 FunctionSpec (org.apache.beam.model.pipeline.v1.RunnerApi.FunctionSpec)1 Pipeline (org.apache.beam.sdk.Pipeline)1 SdkFunctionSpec (org.apache.beam.sdk.common.runner.v1.RunnerApi.SdkFunctionSpec)1 Collector (org.apache.beam.sdk.extensions.euphoria.core.client.io.Collector)1 TypePropagationAssert (org.apache.beam.sdk.extensions.euphoria.core.client.type.TypePropagationAssert)1 TestPipeline (org.apache.beam.sdk.testing.TestPipeline)1 AfterWatermark (org.apache.beam.sdk.transforms.windowing.AfterWatermark)1 FixedWindows (org.apache.beam.sdk.transforms.windowing.FixedWindows)1 Window (org.apache.beam.sdk.transforms.windowing.Window)1 OnTimeBehavior (org.apache.beam.sdk.transforms.windowing.Window.OnTimeBehavior)1 WindowDesc (org.apache.beam.sdk.transforms.windowing.WindowDesc)1 KV (org.apache.beam.sdk.values.KV)1 PCollection (org.apache.beam.sdk.values.PCollection)1 TypeDescriptor (org.apache.beam.sdk.values.TypeDescriptor)1