github.com/apache/beam/sdks/v2@v2.48.2/go/examples/xlang/multi_input_output/multi.go (about) 1 // Licensed to the Apache Software Foundation (ASF) under one or more 2 // contributor license agreements. See the NOTICE file distributed with 3 // this work for additional information regarding copyright ownership. 4 // The ASF licenses this file to You under the Apache License, Version 2.0 5 // (the "License"); you may not use this file except in compliance with 6 // the License. You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 // multi exemplifies using a cross-language transform with multiple inputs and 17 // outputs from a test expansion service. 18 // 19 // Prerequisites to run wordcount: 20 // –> [Required] Job needs to be submitted to a portable runner (--runner=universal) 21 // –> [Required] Endpoint of job service needs to be passed (--endpoint=<ip:port>) 22 // –> [Required] Endpoint of expansion service needs to be passed (--expansion_addr=<ip:port>) 23 // –> [Optional] Environment type can be LOOPBACK. Defaults to DOCKER. (--environment_type=LOOPBACK|DOCKER) 24 package main 25 26 import ( 27 "context" 28 "flag" 29 "log" 30 31 "github.com/apache/beam/sdks/v2/go/examples/xlang" 32 "github.com/apache/beam/sdks/v2/go/pkg/beam" 33 "github.com/apache/beam/sdks/v2/go/pkg/beam/testing/passert" 34 "github.com/apache/beam/sdks/v2/go/pkg/beam/x/beamx" 35 36 // Imports to enable correct filesystem access and runner setup in LOOPBACK mode 37 _ "github.com/apache/beam/sdks/v2/go/pkg/beam/io/filesystem/gcs" 38 _ "github.com/apache/beam/sdks/v2/go/pkg/beam/io/filesystem/local" 39 _ "github.com/apache/beam/sdks/v2/go/pkg/beam/runners/universal" 40 ) 41 42 var ( 43 expansionAddr = flag.String("expansion_addr", "", "Address of Expansion Service") 44 ) 45 46 func main() { 47 flag.Parse() 48 beam.Init() 49 50 if *expansionAddr == "" { 51 log.Fatal("No expansion address provided") 52 } 53 54 p := beam.NewPipeline() 55 s := p.Root() 56 57 main1 := beam.CreateList(s, []string{"a", "bb"}) 58 main2 := beam.CreateList(s, []string{"x", "yy", "zzz"}) 59 side := beam.CreateList(s, []string{"s"}) 60 61 // Using the cross-language transform 62 mainOut, sideOut := xlang.Multi(s, *expansionAddr, main1, main2, side) 63 64 passert.Equals(s, mainOut, "as", "bbs", "xs", "yys", "zzzs") 65 passert.Equals(s, sideOut, "ss") 66 67 if err := beamx.Run(context.Background(), p); err != nil { 68 log.Fatalf("Failed to execute job: %v", err) 69 } 70 }