ahmedabu98 commented on code in PR #30910:
URL: https://github.com/apache/beam/pull/30910#discussion_r1571019914


##########
sdks/java/managed/src/main/java/org/apache/beam/sdk/managed/ManagedSchemaTransformTranslation.java:
##########
@@ -0,0 +1,143 @@
+/*
+ * 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.managed;
+
+import static org.apache.beam.model.pipeline.v1.RunnerApi.FunctionSpec;
+import static 
org.apache.beam.sdk.managed.ManagedSchemaTransformProvider.ManagedConfig;
+import static 
org.apache.beam.sdk.managed.ManagedSchemaTransformProvider.ManagedSchemaTransform;
+import static 
org.apache.beam.sdk.util.construction.PTransformTranslation.TransformPayloadTranslator;
+
+import com.google.auto.service.AutoService;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.beam.model.pipeline.v1.SchemaApi;
+import 
org.apache.beam.model.pipeline.v1.SchemaAwareTransforms.ManagedTransformPayload;
+import org.apache.beam.sdk.coders.RowCoder;
+import org.apache.beam.sdk.options.PipelineOptions;
+import org.apache.beam.sdk.runners.AppliedPTransform;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.schemas.SchemaTranslation;
+import org.apache.beam.sdk.transforms.PTransform;
+import org.apache.beam.sdk.util.construction.SdkComponents;
+import 
org.apache.beam.sdk.util.construction.TransformPayloadTranslatorRegistrar;
+import org.apache.beam.sdk.values.Row;
+import org.apache.beam.vendor.grpc.v1p60p1.com.google.protobuf.ByteString;
+import 
org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap;
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+public class ManagedSchemaTransformTranslation {
+  static class ManagedSchemaTransformTranslator
+      implements TransformPayloadTranslator<ManagedSchemaTransform> {
+    private final ManagedSchemaTransformProvider provider;
+    static final Schema SCHEMA =
+        Schema.builder()
+            .addStringField("transform_identifier")
+            .addNullableStringField("config")
+            .addNullableStringField("config_url")
+            .build();
+
+    public ManagedSchemaTransformTranslator() {
+      provider = new ManagedSchemaTransformProvider(null);
+    }
+
+    @Override
+    public String getUrn() {
+      return provider.identifier();
+    }
+
+    @Override
+    @SuppressWarnings("argument")
+    public @Nullable FunctionSpec translate(
+        AppliedPTransform<?, ?, ManagedSchemaTransform> application, 
SdkComponents components)
+        throws IOException {
+      SchemaApi.Schema expansionSchema = 
SchemaTranslation.schemaToProto(SCHEMA, true);
+      ManagedConfig managedConfig = 
application.getTransform().getManagedConfig();
+      Row configRow = toConfigRow(application.getTransform());
+      ByteArrayOutputStream os = new ByteArrayOutputStream();
+      RowCoder.of(SCHEMA).encode(configRow, os);
+
+      return FunctionSpec.newBuilder()
+          .setUrn(getUrn())
+          .setPayload(
+              ManagedTransformPayload.newBuilder()
+                  
.setUnderlyingTransformUrn(managedConfig.getTransformIdentifier())

Review Comment:
   As discussed offline, the underlying transform is the SchemaTransform.
   Making name changes to the proto to reflect this (underlying_transform_urn 
--> underlying_transform_identifier)



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to