You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2021/08/23 21:21:19 UTC

[GitHub] [beam] xinyuiscool commented on a change in pull request #15349: [BEAM-12724][BEAM-12349] Support user timers in Samza portable runner

xinyuiscool commented on a change in pull request #15349:
URL: https://github.com/apache/beam/pull/15349#discussion_r694315340



##########
File path: runners/samza/src/main/java/org/apache/beam/runners/samza/runtime/SamzaDoFnRunners.java
##########
@@ -312,7 +345,27 @@ private void emitResults() {
         BoundedWindow window,
         Instant timestamp,
         Instant outputTimestamp,
-        TimeDomain timeDomain) {}
+        TimeDomain timeDomain) {
+      KV<String, String> timerReceiverKey =

Review comment:
       final

##########
File path: runners/samza/src/main/java/org/apache/beam/runners/samza/runtime/SamzaDoFnRunners.java
##########
@@ -250,6 +266,17 @@ private SdkHarnessDoFnRunner(
       this.stateRequestHandler = stateRequestHandler;
     }
 
+    @SuppressWarnings("unchecked")
+    void timerDataConsumer(Timer<?> timerElement, TimerInternals.TimerData timerData) {

Review comment:
       private?

##########
File path: runners/samza/src/main/java/org/apache/beam/runners/samza/runtime/SamzaDoFnRunners.java
##########
@@ -312,7 +345,27 @@ private void emitResults() {
         BoundedWindow window,
         Instant timestamp,
         Instant outputTimestamp,
-        TimeDomain timeDomain) {}
+        TimeDomain timeDomain) {
+      KV<String, String> timerReceiverKey =
+          TimerReceiverFactory.decodeTimerDataTimerId(timerFamilyId);
+      FnDataReceiver<Timer> timerReceiver = remoteBundle.getTimerReceivers().get(timerReceiverKey);

Review comment:
       final

##########
File path: runners/samza/src/main/java/org/apache/beam/runners/samza/util/WindowUtils.java
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.runners.samza.util;
+
+import java.io.IOException;
+import org.apache.beam.model.pipeline.v1.RunnerApi;
+import org.apache.beam.runners.core.construction.RehydratedComponents;
+import org.apache.beam.runners.core.construction.WindowingStrategyTranslation;
+import org.apache.beam.runners.core.construction.graph.PipelineNode;
+import org.apache.beam.runners.fnexecution.wire.WireCoders;
+import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
+import org.apache.beam.sdk.util.WindowedValue;
+import org.apache.beam.sdk.values.WindowingStrategy;
+
+public class WindowUtils {

Review comment:
       javadoc

##########
File path: runners/samza/src/main/java/org/apache/beam/runners/samza/runtime/DoFnRunnerWithKeyedInternals.java
##########
@@ -117,8 +100,10 @@ private void setKeyedInternals(Object value) {
       if (key != null) {
         keyedInternals.setKey(key);
       }
-    } else {
+    } else if (value instanceof KV) {
       keyedInternals.setKey(((KV<?, ?>) value).getKey());
+    } else {
+      keyedInternals.setKey(value);

Review comment:
       This change does make a differencec in processElement() as previously we only allow KV or KeyedWorkItem to be the type of elements. That means we explicitly ask the element to have a key. This change will actually treat any value as key if it falls through. Is there a better way here that we will throw if the element is not KV or KeyedWorkItem?

##########
File path: runners/samza/src/main/java/org/apache/beam/runners/samza/util/WindowUtils.java
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.runners.samza.util;
+
+import java.io.IOException;
+import org.apache.beam.model.pipeline.v1.RunnerApi;
+import org.apache.beam.runners.core.construction.RehydratedComponents;
+import org.apache.beam.runners.core.construction.WindowingStrategyTranslation;
+import org.apache.beam.runners.core.construction.graph.PipelineNode;
+import org.apache.beam.runners.fnexecution.wire.WireCoders;
+import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
+import org.apache.beam.sdk.util.WindowedValue;
+import org.apache.beam.sdk.values.WindowingStrategy;
+
+public class WindowUtils {
+
+  /** Get {@link WindowingStrategy} of given collection id from {@link RunnerApi.Components}. */
+  public static WindowingStrategy<?, BoundedWindow> getWindowStrategy(
+      String collectionId, RunnerApi.Components components) {
+    RehydratedComponents rehydratedComponents = RehydratedComponents.forComponents(components);
+
+    RunnerApi.WindowingStrategy windowingStrategyProto =
+        components.getWindowingStrategiesOrThrow(
+            components.getPcollectionsOrThrow(collectionId).getWindowingStrategyId());
+
+    WindowingStrategy<?, ?> windowingStrategy;
+    try {
+      windowingStrategy =
+          WindowingStrategyTranslation.fromProto(windowingStrategyProto, rehydratedComponents);
+    } catch (Exception e) {
+      throw new IllegalStateException(
+          String.format(
+              "Unable to hydrate GroupByKey windowing strategy %s.", windowingStrategyProto),
+          e);
+    }
+
+    @SuppressWarnings("unchecked")
+    WindowingStrategy<?, BoundedWindow> ret =
+        (WindowingStrategy<?, BoundedWindow>) windowingStrategy;
+    return ret;
+  }
+
+  /**
+   * Instantiate {@link WindowedValue.WindowedValueCoder} for given collection id from {@link
+   * RunnerApi.Components}.
+   */
+  public static <T> WindowedValue.WindowedValueCoder<T> instantiateWindowedCoder(

Review comment:
       Possible to add a unit test?

##########
File path: runners/samza/src/main/java/org/apache/beam/runners/samza/runtime/SamzaDoFnRunners.java
##########
@@ -312,7 +345,27 @@ private void emitResults() {
         BoundedWindow window,
         Instant timestamp,
         Instant outputTimestamp,
-        TimeDomain timeDomain) {}
+        TimeDomain timeDomain) {
+      KV<String, String> timerReceiverKey =
+          TimerReceiverFactory.decodeTimerDataTimerId(timerFamilyId);
+      FnDataReceiver<Timer> timerReceiver = remoteBundle.getTimerReceivers().get(timerReceiverKey);
+
+      Timer timerValue =

Review comment:
       final

##########
File path: runners/samza/src/main/java/org/apache/beam/runners/samza/util/WindowUtils.java
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.runners.samza.util;
+
+import java.io.IOException;
+import org.apache.beam.model.pipeline.v1.RunnerApi;
+import org.apache.beam.runners.core.construction.RehydratedComponents;
+import org.apache.beam.runners.core.construction.WindowingStrategyTranslation;
+import org.apache.beam.runners.core.construction.graph.PipelineNode;
+import org.apache.beam.runners.fnexecution.wire.WireCoders;
+import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
+import org.apache.beam.sdk.util.WindowedValue;
+import org.apache.beam.sdk.values.WindowingStrategy;
+
+public class WindowUtils {
+
+  /** Get {@link WindowingStrategy} of given collection id from {@link RunnerApi.Components}. */
+  public static WindowingStrategy<?, BoundedWindow> getWindowStrategy(

Review comment:
       Is is possible to add a unit test for this?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org