[
https://issues.apache.org/jira/browse/BEAM-4125?focusedWorklogId=94888&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-94888
]
ASF GitHub Bot logged work on BEAM-4125:
----------------------------------------
Author: ASF GitHub Bot
Created on: 25/Apr/18 00:15
Start Date: 25/Apr/18 00:15
Worklog Time Spent: 10m
Work Description: youngoli commented on a change in pull request #5172:
[BEAM-4125] Add ProtoOverrides
URL: https://github.com/apache/beam/pull/5172#discussion_r183907831
##########
File path:
runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/graph/ProtoOverrides.java
##########
@@ -0,0 +1,103 @@
+/*
+ * 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.core.construction.graph;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.beam.model.pipeline.v1.RunnerApi.Components;
+import org.apache.beam.model.pipeline.v1.RunnerApi.ComponentsOrBuilder;
+import org.apache.beam.model.pipeline.v1.RunnerApi.MessageWithComponents;
+import org.apache.beam.model.pipeline.v1.RunnerApi.PTransform;
+import org.apache.beam.model.pipeline.v1.RunnerApi.Pipeline;
+import org.apache.beam.sdk.annotations.Experimental;
+import org.apache.beam.sdk.runners.PTransformOverride;
+
+/**
+ * A way to apply a Proto-based {@link PTransformOverride}.
+ *
+ * <p>This should generally be used to replace runner-executed transforms with
runner-executed
+ * composites and simpler runner-executed primitives. It is generically less
powerful than the
+ * native {@link org.apache.beam.sdk.Pipeline#replaceAll(List)} and more
error-prone, so should only
+ * be used for relatively simple replacements.
+ */
+@Experimental
+public class ProtoOverrides {
+ /**
+ * Update all composites present in the {@code originalPipeline} have an URN
equal to the provided
+ * {@code urn} using the provide {@link TransformReplacement}.
+ */
+ public static Pipeline updateTransform(
+ String urn, Pipeline originalPipeline, TransformReplacement
compositeBuilder) {
+ Components.Builder resultComponents =
originalPipeline.getComponents().toBuilder();
+ for (Map.Entry<String, PTransform> pt :
+ originalPipeline.getComponents().getTransformsMap().entrySet()) {
+ if (pt.getValue().getSpec() != null &&
urn.equals(pt.getValue().getSpec().getUrn())) {
+ MessageWithComponents updated =
+ compositeBuilder.getReplacement(pt.getKey(),
originalPipeline.getComponents());
+ checkArgument(
+
updated.getPtransform().getOutputsMap().equals(pt.getValue().getOutputsMap()),
+ "A %s must produce all of the outputs of the original %s",
+ TransformReplacement.class.getSimpleName(),
+ PTransform.class.getSimpleName());
+ removeSubtransforms(pt.getValue(), resultComponents);
+ resultComponents
+ .mergeFrom(updated.getComponents())
+ .putTransforms(pt.getKey(), updated.getPtransform());
+ }
+ }
+ return
originalPipeline.toBuilder().setComponents(resultComponents).build();
+ }
+
+ /**
+ * Remove any subtransforms that are produced by them but not by the
enclosing transform.
Review comment:
Awkward function description; I don't know what "them" refers to.
----------------------------------------------------------------
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: 94888)
Time Spent: 0.5h (was: 20m)
> Add a library to manipulate the proto representation of a pipeline
> ------------------------------------------------------------------
>
> Key: BEAM-4125
> URL: https://issues.apache.org/jira/browse/BEAM-4125
> Project: Beam
> Issue Type: New Feature
> Components: runner-core
> Reporter: Thomas Groh
> Assignee: Thomas Groh
> Priority: Major
> Labels: portability
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> This is important for a transform which includes in-environment transforms
> (such as a lifted Combine), or for runners which use the beam representation
> as their internal representation (such as the directrunner)
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)