youngoli commented on a change in pull request #16490:
URL: https://github.com/apache/beam/pull/16490#discussion_r792285861



##########
File path: sdks/go/pkg/beam/core/runtime/xlangx/resolve_test.go
##########
@@ -0,0 +1,76 @@
+// 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 xlangx
+
+import (
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/core/graph"
+       pipepb "github.com/apache/beam/sdks/v2/go/pkg/beam/model/pipeline_v1"
+       "github.com/golang/protobuf/proto"
+       "testing"
+)
+
+func createExternalEdge(typeUrn string, typePayload []byte) *graph.MultiEdge {
+       env := map[string]*pipepb.Environment{
+               "env_java": {
+                       Dependencies: []*pipepb.ArtifactInformation{
+                               {
+                                       TypeUrn:     typeUrn,
+                                       TypePayload: typePayload,
+                               },
+                       },
+               },
+       }
+       return &graph.MultiEdge{
+               Op: graph.External,
+               External: &graph.ExternalTransform{
+                       Expanded: &graph.ExpandedTransform{
+                               Components: &pipepb.Components{
+                                       Environments: env,
+                               },
+                       },
+               },
+       }
+}
+
+func TestUpdateArtifactTypeFromFileToUrl(t *testing.T) {
+       payload, _ := proto.Marshal(&pipepb.ArtifactFilePayload{
+               Path: "gs://dummy"})
+       e := createExternalEdge("beam:artifact:type:file:v1", payload)
+       UpdateArtifactTypeFromFileToUrl([]*graph.MultiEdge{e})
+       expected := createExternalEdge("beam:artifact:type:url:v1", payload)
+
+       if !proto.Equal(
+               e.External.Expanded.Components.(*pipepb.Components),
+               expected.External.Expanded.Components.(*pipepb.Components)) {
+               t.Errorf("Mismatched output %v != %v",
+                       e.External.Expanded.Components.(*pipepb.Components),
+                       
expected.External.Expanded.Components.(*pipepb.Components))
+       }
+
+       payload, _ = proto.Marshal(&pipepb.ArtifactFilePayload{

Review comment:
       Nit: I'd separate this case into its own unit test.

##########
File path: sdks/go/pkg/beam/core/runtime/xlangx/resolve.go
##########
@@ -127,3 +127,46 @@ func ResolveArtifactsWithConfig(ctx context.Context, edges 
[]*graph.MultiEdge, c
        }
        return paths, nil
 }
+

Review comment:
       Can you add a comment? All exported functions should be documented in Go.

##########
File path: sdks/go/pkg/beam/core/runtime/xlangx/resolve.go
##########
@@ -127,3 +127,46 @@ func ResolveArtifactsWithConfig(ctx context.Context, edges 
[]*graph.MultiEdge, c
        }
        return paths, nil
 }
+
+func UpdateArtifactTypeFromFileToUrl(edges []*graph.MultiEdge) {
+       for _, e := range edges {
+               if e.Op == graph.External && e.External != nil {
+                       components, err := 
graphx.ExpandedComponents(e.External.Expanded)
+                       if err != nil {
+                               panic(errors.WithContextf(err,
+                                       "updating URL artifacts type for edge 
%v", e.Name()))
+                       }
+                       envs := components.Environments
+                       for _, env := range envs {
+                               deps := env.GetDependencies()
+                               var resolvedDeps []*pipepb.ArtifactInformation
+                               for _, a := range deps {
+                                       path, sha256 := 
artifact.MustExtractFilePayload(a)
+                                       var typeUrn string
+                                       var typePayload []byte
+                                       if strings.Contains(path, "://") {

Review comment:
       Nit: Maybe here you could use the 
[Clone](https://pkg.go.dev/google.golang.org/protobuf/proto#Clone) method to 
create a copy of the `ArtifactInformation`, and then just change the fields 
that need to be modified? Might be slightly inefficient to copy fields that 
immediately get replaced, but means this code is more flexible if 
`ArtifactInformation` changes in the future.




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