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/03/08 18:09:42 UTC

[GitHub] [beam] kennknowles commented on a change in pull request #14141: [BEAM-10861] Add RunnerImplementedSource and RunnerImplementedSink to Pubsub

kennknowles commented on a change in pull request #14141:
URL: https://github.com/apache/beam/pull/14141#discussion_r589635846



##########
File path: runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/DataflowRunner.java
##########
@@ -1538,68 +1504,68 @@ public DataflowReadFromPubsubForRunnerV2(PubsubUnboundedSource transform) {
 
     @Override
     public PCollection<PubsubMessage> expand(PBegin input) {
+      PCollection<byte[]> outputFromRunner =
+          input.apply(
+              "DataflowReadFromPubsubRunnerV2", new RunnerImplementedSource(this.transform));

Review comment:
       I believe this part of the `PubsubIO.Read` composite should have a URN and Payload but also a composite expansion. This way a runner can override it or run it directly based only on the portable graph.
   
   It seems the logic after this transform is all about parsing and mapping into expected messages. That can be a separate part of the `PubsubIO.Read` composite.

##########
File path: sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/pubsub/RunnerImplementedSource.java
##########
@@ -0,0 +1,81 @@
+/*
+ * 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.sdk.io.gcp.pubsub;
+
+import org.apache.beam.sdk.coders.ByteArrayCoder;
+import org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.SubscriptionPath;
+import org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.TopicPath;
+import org.apache.beam.sdk.options.ValueProvider;
+import org.apache.beam.sdk.transforms.PTransform;
+import org.apache.beam.sdk.values.PBegin;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.PCollection.IsBounded;
+import org.apache.beam.sdk.values.WindowingStrategy;
+
+@SuppressWarnings({
+  "rawtypes", // TODO(https://issues.apache.org/jira/browse/BEAM-10556)
+  "nullness" // TODO(https://issues.apache.org/jira/browse/BEAM-10402)
+})
+/**
+ * A {@link PTransform} which represents a runner implemented Pubsub source. {@link
+ * RunnerImplementedSourceTranslator} will translate this transform into well-known composite.
+ */
+public class RunnerImplementedSource extends PTransform<PBegin, PCollection<byte[]>> {
+  private final PubsubUnboundedSource source;
+
+  public RunnerImplementedSource(PubsubUnboundedSource source) {
+    this.source = source;
+  }
+
+  public PubsubUnboundedSource getOverriddenSource() {
+    return source;
+  }
+
+  public ValueProvider<TopicPath> getTopicProvider() {
+    return source.getTopicProvider();
+  }
+
+  public ValueProvider<SubscriptionPath> getSubscriptionProvider() {
+    return source.getSubscriptionProvider();
+  }
+
+  public String getTimestampAttribute() {
+    return source.getTimestampAttribute();
+  }
+
+  public String getIdAttribute() {
+    return source.getIdAttribute();
+  }
+
+  public boolean isWithAttributes() {
+    return source.getNeedsAttributes() || source.getNeedsMessageId();
+  }
+
+  @Override
+  public PCollection<byte[]> expand(PBegin input) {
+    ByteArrayCoder coder = ByteArrayCoder.of();
+    return PCollection.createPrimitiveOutputInternal(

Review comment:
       Same here.

##########
File path: runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/DataflowRunner.java
##########
@@ -1451,24 +1455,19 @@ void recordViewUsesNonDeterministicKeyCoder(PTransform<?, ?> ptransform) {
     }
   }
 
-  private interface PubsubUnboundedSourceOverrider {
-    PubsubUnboundedSource getOverriddenTransform();
-  }
-
   /**
    * Suppress application of {@link PubsubUnboundedSource#expand} in streaming mode so that we can
    * instead defer to Windmill's implementation.
    */
-  private static class StreamingPubsubIORead extends PTransform<PBegin, PCollection<PubsubMessage>>
-      implements PubsubUnboundedSourceOverrider {
+  private static class StreamingPubsubIORead
+      extends PTransform<PBegin, PCollection<PubsubMessage>> {

Review comment:
       With portable submission, it would be preferable to not have any override, and handle it in the service. Mostly the overrides seem trivial so we don't need them in the SDK.

##########
File path: sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/pubsub/RunnerImplementedSink.java
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.sdk.io.gcp.pubsub;
+
+import org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.TopicPath;
+import org.apache.beam.sdk.options.ValueProvider;
+import org.apache.beam.sdk.transforms.PTransform;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.PDone;
+
+@SuppressWarnings({
+  "rawtypes", // TODO(https://issues.apache.org/jira/browse/BEAM-10556)
+  "nullness" // TODO(https://issues.apache.org/jira/browse/BEAM-10402)
+})
+/**
+ * A {@link PTransform} which represents a runner implemented Pubsub sink. {@link
+ * RunnerImplementedSinkTranslator} will translate this transform into well-known composite.
+ */
+public class RunnerImplementedSink extends PTransform<PCollection<byte[]>, PDone> {
+  private final PubsubUnboundedSink sink;
+
+  public RunnerImplementedSink(PubsubUnboundedSink sink) {
+    this.sink = sink;
+  }
+
+  public PubsubUnboundedSink getOverrideSink() {
+    return sink;
+  }
+
+  public ValueProvider<TopicPath> getTopicProvider() {
+    return sink.getTopicProvider();
+  }
+
+  public String getTimestampAttribute() {
+    return sink.getTimestampAttribute();
+  }
+
+  public String getIdAttribute() {
+    return sink.getIdAttribute();
+  }
+
+  @Override
+  public PDone expand(PCollection<byte[]> input) {
+    return PDone.in(input.getPipeline());

Review comment:
       Instead of being a runner primitive, this should be a composite so that the `expand()` method implements the equivalent functionality. I assume a similar piece of logic already exists in the `PubsubIO.Read` transform?




----------------------------------------------------------------
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.

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