beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Work logged] (BEAM-4269) Implement Assign Windows in the Java SDK Harness
Date Mon, 14 May 2018 18:23:00 GMT

     [ https://issues.apache.org/jira/browse/BEAM-4269?focusedWorklogId=101816&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-101816
]

ASF GitHub Bot logged work on BEAM-4269:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 14/May/18 18:22
            Start Date: 14/May/18 18:22
    Worklog Time Spent: 10m 
      Work Description: lukecwik commented on a change in pull request #5329: [BEAM-4269,
BEAM-3970] Implement AssignWindows in the Java SDK harness
URL: https://github.com/apache/beam/pull/5329#discussion_r188050919
 
 

 ##########
 File path: sdks/java/harness/src/test/java/org/apache/beam/fn/harness/AssignWindowsRunnerTest.java
 ##########
 @@ -0,0 +1,363 @@
+/*
+ * 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.beam.fn.harness;
+
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.ListMultimap;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import org.apache.beam.fn.harness.AssignWindowsRunner.AssignWindowsMapFnFactory;
+import org.apache.beam.model.pipeline.v1.RunnerApi.FunctionSpec;
+import org.apache.beam.model.pipeline.v1.RunnerApi.PTransform;
+import org.apache.beam.model.pipeline.v1.RunnerApi.WindowIntoPayload;
+import org.apache.beam.runners.core.construction.PTransformTranslation;
+import org.apache.beam.runners.core.construction.SdkComponents;
+import org.apache.beam.runners.core.construction.WindowingStrategyTranslation;
+import org.apache.beam.sdk.coders.Coder;
+import org.apache.beam.sdk.fn.data.FnDataReceiver;
+import org.apache.beam.sdk.fn.function.ThrowingFunction;
+import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
+import org.apache.beam.sdk.transforms.windowing.FixedWindows;
+import org.apache.beam.sdk.transforms.windowing.GlobalWindow;
+import org.apache.beam.sdk.transforms.windowing.IntervalWindow;
+import org.apache.beam.sdk.transforms.windowing.IntervalWindow.IntervalWindowCoder;
+import org.apache.beam.sdk.transforms.windowing.PaneInfo;
+import org.apache.beam.sdk.transforms.windowing.PartitioningWindowFn;
+import org.apache.beam.sdk.transforms.windowing.Sessions;
+import org.apache.beam.sdk.transforms.windowing.SlidingWindows;
+import org.apache.beam.sdk.transforms.windowing.WindowFn;
+import org.apache.beam.sdk.transforms.windowing.WindowMappingFn;
+import org.apache.beam.sdk.util.WindowedValue;
+import org.joda.time.Duration;
+import org.joda.time.Instant;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Tests for {@link org.apache.beam.fn.harness.AssignWindowsRunner}. */
+@RunWith(JUnit4.class)
+public class AssignWindowsRunnerTest implements Serializable {
+  @Rule public transient ExpectedException thrown = ExpectedException.none();
+
+  @Test
+  public void singleInputSingleOutputSucceeds() throws Exception {
+    FixedWindows windowFn = FixedWindows.of(Duration.standardMinutes(10L));
+
+    AssignWindowsRunner<Integer, IntervalWindow> runner = AssignWindowsRunner.create(windowFn);
+
+    assertThat(
+        runner.assignWindows(WindowedValue.valueInGlobalWindow(1)),
+        equalTo(
+            WindowedValue.of(
+                1,
+                BoundedWindow.TIMESTAMP_MIN_VALUE,
+                windowFn.assignWindow(BoundedWindow.TIMESTAMP_MIN_VALUE),
+                PaneInfo.NO_FIRING)));
+    assertThat(
+        runner.assignWindows(
+            WindowedValue.of(
+                2,
+                new Instant(-10L),
+                new IntervalWindow(new Instant(-120000L), Duration.standardMinutes(3L)),
+                PaneInfo.ON_TIME_AND_ONLY_FIRING)),
+        equalTo(
+            WindowedValue.of(
+                2,
+                new Instant(-10L),
+                windowFn.assignWindow(new Instant(-10L)),
+                PaneInfo.ON_TIME_AND_ONLY_FIRING)));
+  }
+
+  @Test
+  public void singleInputMultipleOutputSucceeds() throws Exception {
+    WindowFn<Object, IntervalWindow> windowFn =
+        SlidingWindows.of(Duration.standardMinutes(4L)).every(Duration.standardMinutes(2L));
+
+    AssignWindowsRunner<Integer, IntervalWindow> runner = AssignWindowsRunner.create(windowFn);
+
+    IntervalWindow firstWindow =
+        new IntervalWindow(
+            new Instant(0).minus(Duration.standardMinutes(4L)), Duration.standardMinutes(4L));
+    IntervalWindow secondWindow =
+        new IntervalWindow(
+            new Instant(0).minus(Duration.standardMinutes(2L)), Duration.standardMinutes(4L));
+    IntervalWindow thirdWindow =
+        new IntervalWindow(
+            new Instant(0).minus(Duration.standardMinutes(0L)), Duration.standardMinutes(4L));
+
+    WindowedValue<Integer> firstValue =
+        WindowedValue.timestampedValueInGlobalWindow(-3, new Instant(-12));
+    assertThat(
+        runner.assignWindows(firstValue),
+        equalTo(
+            WindowedValue.of(
+                -3,
+                new Instant(-12),
+                ImmutableSet.of(firstWindow, secondWindow),
+                firstValue.getPane())));
+    WindowedValue<Integer> secondValue =
+        WindowedValue.of(
+            3,
+            new Instant(12),
+            new IntervalWindow(new Instant(-12), Duration.standardMinutes(24)),
+            PaneInfo.ON_TIME_AND_ONLY_FIRING);
+
+    assertThat(
+        runner.assignWindows(secondValue),
+        equalTo(
+            WindowedValue.of(
+                3,
+                new Instant(12),
+                ImmutableSet.of(secondWindow, thirdWindow),
+                secondValue.getPane())));
+  }
+
+  @Test
+  public void multipleInputWindowsAsMapFnSucceeds() throws Exception {
+    IntervalWindow intervalWindow =
+        new IntervalWindow(new Instant(-500), Duration.standardMinutes(3));
+    WindowFn<Object, BoundedWindow> windowFn =
+        new WindowFn<Object, BoundedWindow>() {
+          @Override
+          public Collection<BoundedWindow> assignWindows(AssignContext c) throws Exception
{
+            return ImmutableList.of(GlobalWindow.INSTANCE, intervalWindow);
+          }
+
+          @Override
+          public void mergeWindows(MergeContext c) throws Exception {
+            throw new UnsupportedOperationException();
+          }
+
+          @Override
+          public WindowMappingFn<BoundedWindow> getDefaultWindowMappingFn() {
+            throw new UnsupportedOperationException();
+          }
+
+          @Override
+          public boolean isCompatible(WindowFn<?, ?> other) {
+            throw new UnsupportedOperationException();
+          }
+
+          @Override
+          public Coder<BoundedWindow> windowCoder() {
+            throw new UnsupportedOperationException();
+          }
+        };
+    Collection<WindowedValue<?>> outputs = new ArrayList<>();
+    ListMultimap<String, FnDataReceiver<WindowedValue<?>>> receivers =
ArrayListMultimap.create();
+    receivers.put("output", outputs::add);
+    MapFnRunners.forWindowedValueMapFnFactory(new AssignWindowsMapFnFactory<>())
+        .createRunnerForPTransform(
+            null,
 
 Review comment:
   can you label the parameters or pass in realistic representations?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 101816)
    Time Spent: 2h 50m  (was: 2h 40m)

> Implement Assign Windows in the Java SDK Harness
> ------------------------------------------------
>
>                 Key: BEAM-4269
>                 URL: https://issues.apache.org/jira/browse/BEAM-4269
>             Project: Beam
>          Issue Type: New Feature
>          Components: sdk-java-harness
>            Reporter: Thomas Groh
>            Assignee: Thomas Groh
>            Priority: Major
>             Fix For: Not applicable
>
>          Time Spent: 2h 50m
>  Remaining Estimate: 0h
>
> This allows execution of Java WindowFns over the Fn API



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message