[
https://issues.apache.org/jira/browse/BEAM-4269?focusedWorklogId=100799&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-100799
]
ASF GitHub Bot logged work on BEAM-4269:
----------------------------------------
Author: ASF GitHub Bot
Created on: 10/May/18 20:08
Start Date: 10/May/18 20:08
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_r187441268
##########
File path:
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/AssignWindowsRunner.java
##########
@@ -0,0 +1,111 @@
+/*
+ * 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 com.google.common.base.Preconditions.checkArgument;
+
+import com.google.auto.service.AutoService;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Map;
+import org.apache.beam.fn.harness.MapFnRunner.WindowedValueMapFnFactory;
+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.WindowingStrategyTranslation;
+import org.apache.beam.sdk.fn.function.ThrowingFunction;
+import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
+import org.apache.beam.sdk.transforms.windowing.Window;
+import org.apache.beam.sdk.transforms.windowing.WindowFn;
+import org.apache.beam.sdk.util.WindowedValue;
+import org.joda.time.Instant;
+
+/** The Java SDK Harness implementation of the {@link Window.Assign}
primitive. */
+public class AssignWindowsRunner<T, W extends BoundedWindow> {
+
+ /** A registrar which provides a factory to handle Java {@link WindowFn
WindowFns}. */
+ @AutoService(PTransformRunnerFactory.Registrar.class)
+ public static class Registrar implements PTransformRunnerFactory.Registrar {
+ @Override
+ public Map<String, PTransformRunnerFactory> getPTransformRunnerFactories()
{
+ return ImmutableMap.of(
+ PTransformTranslation.ASSIGN_WINDOWS_TRANSFORM_URN,
+ MapFnRunner.forMapFnFactory(new AssignWindowsMapFnFactory<>()));
+ }
+ }
+
+ @VisibleForTesting
+ static class AssignWindowsMapFnFactory<T> implements
WindowedValueMapFnFactory<T, T> {
+ @Override
+ public ThrowingFunction<WindowedValue<T>, WindowedValue<T>> forPTransform(
+ String ptransformId, PTransform ptransform) throws IOException {
+ checkArgument(
+
PTransformTranslation.ASSIGN_WINDOWS_TRANSFORM_URN.equals(ptransform.getSpec().getUrn()));
+ checkArgument(ptransform.getInputsCount() == 1, "Expected only one
input");
+ checkArgument(ptransform.getOutputsCount() == 1, "Expected only one
output");
+ WindowIntoPayload payload =
WindowIntoPayload.parseFrom(ptransform.getSpec().getPayload());
+
+ WindowFn<T, ?> windowFn =
+ (WindowFn<T, ?>)
WindowingStrategyTranslation.windowFnFromProto(payload.getWindowFn());
+
+ return AssignWindowsRunner.create(windowFn)::assignWindows;
+ }
+ }
+
+
////////////////////////////////////////////////////////////////////////////////////////////////
+
+ public static <T, W extends BoundedWindow> AssignWindowsRunner<T, W> create(
Review comment:
This doesn't need to be made public
----------------------------------------------------------------
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:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 100799)
Time Spent: 1h (was: 50m)
> 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: 1h
> Remaining Estimate: 0h
>
> This allows execution of Java WindowFns over the Fn API
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)