Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix all tour examples from part 1 #30478

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ package main

import (
"context"

"github.com/apache/beam/sdks/v2/go/pkg/beam"
"github.com/apache/beam/sdks/v2/go/pkg/beam/log"
"github.com/apache/beam/sdks/v2/go/pkg/beam/transforms/stats"
Expand All @@ -37,6 +38,7 @@ import (

func main() {
ctx := context.Background()
beam.Init()

p, s := beam.NewPipelineWithRoot()

Expand All @@ -51,7 +53,7 @@ func main() {
err := beamx.Run(ctx, p)

if err != nil {
log.Exitf(context.Background(), "Failed to execute job: %v", err)
log.Exitf(ctx, "Failed to execute job: %v", err)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,37 @@
package main

import (
"context"
"github.com/apache/beam/sdks/v2/go/pkg/beam"
"github.com/apache/beam/sdks/v2/go/pkg/beam/log"
"github.com/apache/beam/sdks/v2/go/pkg/beam/x/beamx"
"github.com/apache/beam/sdks/v2/go/pkg/beam/x/debug"
"github.com/apache/beam/sdks/v2/go/pkg/beam/transforms/stats"
"context"

"github.com/apache/beam/sdks/v2/go/pkg/beam"
"github.com/apache/beam/sdks/v2/go/pkg/beam/log"
"github.com/apache/beam/sdks/v2/go/pkg/beam/transforms/stats"
"github.com/apache/beam/sdks/v2/go/pkg/beam/x/beamx"
"github.com/apache/beam/sdks/v2/go/pkg/beam/x/debug"
)

func main() {
ctx := context.Background()
ctx := context.Background()
beam.Init()

p, s := beam.NewPipelineWithRoot()
p, s := beam.NewPipelineWithRoot()

// List of elements
input := beam.Create(s, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
// List of elements
input := beam.Create(s, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

// The applyTransform() converts [input] to [output]
output := applyTransform(s,input)
// The applyTransform() converts [input] to [output]
output := applyTransform(s, input)

debug.Printf(s, "PCollection maximum value: %v", output)
debug.Printf(s, "PCollection maximum value: %v", output)

err := beamx.Run(ctx, p)
err := beamx.Run(ctx, p)

if err != nil {
log.Exitf(context.Background(), "Failed to execute job: %v", err)
}
if err != nil {
log.Exitf(ctx, "Failed to execute job: %v", err)
}
}

// Return the maximum number from `PCollection`.
func applyTransform(s beam.Scope, input beam.PCollection) beam.PCollection {
return stats.Max(s, input)
}
return stats.Max(s, input)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,37 @@
package main

import (
"context"
"github.com/apache/beam/sdks/v2/go/pkg/beam"
"github.com/apache/beam/sdks/v2/go/pkg/beam/log"
"github.com/apache/beam/sdks/v2/go/pkg/beam/x/beamx"
"github.com/apache/beam/sdks/v2/go/pkg/beam/x/debug"
"github.com/apache/beam/sdks/v2/go/pkg/beam/transforms/stats"
"context"

"github.com/apache/beam/sdks/v2/go/pkg/beam"
"github.com/apache/beam/sdks/v2/go/pkg/beam/log"
"github.com/apache/beam/sdks/v2/go/pkg/beam/transforms/stats"
"github.com/apache/beam/sdks/v2/go/pkg/beam/x/beamx"
"github.com/apache/beam/sdks/v2/go/pkg/beam/x/debug"
)

func main() {
ctx := context.Background()
ctx := context.Background()
beam.Init()

p, s := beam.NewPipelineWithRoot()
p, s := beam.NewPipelineWithRoot()

// List of elements
input := beam.Create(s, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
// List of elements
input := beam.Create(s, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

// The applyTransform() converts [input] to [output]
output := applyTransform(s, input)
// The applyTransform() converts [input] to [output]
output := applyTransform(s, input)

debug.Printf(s, "PCollection mean value: %v", output)
debug.Printf(s, "PCollection mean value: %v", output)

err := beamx.Run(ctx, p)
err := beamx.Run(ctx, p)

if err != nil {
log.Exitf(context.Background(), "Failed to execute job: %v", err)
}
if err != nil {
log.Exitf(ctx, "Failed to execute job: %v", err)
}
}

// Return the mean of numbers from `PCollection`.
func applyTransform(s beam.Scope, input beam.PCollection) beam.PCollection {
return stats.Mean(s, input)
}
return stats.Mean(s, input)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,37 @@
package main

import (
"context"
"github.com/apache/beam/sdks/v2/go/pkg/beam"
"github.com/apache/beam/sdks/v2/go/pkg/beam/log"
"github.com/apache/beam/sdks/v2/go/pkg/beam/x/beamx"
"github.com/apache/beam/sdks/v2/go/pkg/beam/x/debug"
"github.com/apache/beam/sdks/v2/go/pkg/beam/transforms/stats"
"context"

"github.com/apache/beam/sdks/v2/go/pkg/beam"
"github.com/apache/beam/sdks/v2/go/pkg/beam/log"
"github.com/apache/beam/sdks/v2/go/pkg/beam/transforms/stats"
"github.com/apache/beam/sdks/v2/go/pkg/beam/x/beamx"
"github.com/apache/beam/sdks/v2/go/pkg/beam/x/debug"
)

func main() {
ctx := context.Background()
ctx := context.Background()
beam.Init()

p, s := beam.NewPipelineWithRoot()
p, s := beam.NewPipelineWithRoot()

// List of elements
input := beam.Create(s, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
// List of elements
input := beam.Create(s, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

// The applyTransform() converts [input] to [output]
output := applyTransform(s, input)
// The applyTransform() converts [input] to [output]
output := applyTransform(s, input)

debug.Printf(s, "PCollection minimum value: %v", output)
debug.Printf(s, "PCollection minimum value: %v", output)

err := beamx.Run(ctx, p)
err := beamx.Run(ctx, p)

if err != nil {
log.Exitf(context.Background(), "Failed to execute job: %v", err)
}
if err != nil {
log.Exitf(ctx, "Failed to execute job: %v", err)
}
}

// Return the minimum of numbers from `PCollection`.
func applyTransform(s beam.Scope, input beam.PCollection) beam.PCollection {
return stats.Min(s, input)
}
return stats.Min(s, input)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ package main

import (
"context"

"github.com/apache/beam/sdks/v2/go/pkg/beam"
"github.com/apache/beam/sdks/v2/go/pkg/beam/log"
"github.com/apache/beam/sdks/v2/go/pkg/beam/transforms/stats"
Expand All @@ -37,6 +38,7 @@ import (

func main() {
ctx := context.Background()
beam.Init()

p, s := beam.NewPipelineWithRoot()

Expand All @@ -51,7 +53,7 @@ func main() {
err := beamx.Run(ctx, p)

if err != nil {
log.Exitf(context.Background(), "Failed to execute job: %v", err)
log.Exitf(ctx, "Failed to execute job: %v", err)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,39 @@
package main

import (
"context"
"github.com/apache/beam/sdks/v2/go/pkg/beam"
"github.com/apache/beam/sdks/v2/go/pkg/beam/log"
"github.com/apache/beam/sdks/v2/go/pkg/beam/x/beamx"
"github.com/apache/beam/sdks/v2/go/pkg/beam/x/debug"
"github.com/apache/beam/sdks/v2/go/pkg/beam/transforms/filter"
"context"

"github.com/apache/beam/sdks/v2/go/pkg/beam"
"github.com/apache/beam/sdks/v2/go/pkg/beam/log"
"github.com/apache/beam/sdks/v2/go/pkg/beam/transforms/filter"
"github.com/apache/beam/sdks/v2/go/pkg/beam/x/beamx"
"github.com/apache/beam/sdks/v2/go/pkg/beam/x/debug"
)

func main() {
ctx := context.Background()
ctx := context.Background()
beam.Init()

p, s := beam.NewPipelineWithRoot()
p, s := beam.NewPipelineWithRoot()

// List of elements
input := beam.Create(s, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
// List of elements
input := beam.Create(s, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

// The [input] filtered with the applyTransform()
output := applyTransform(s, input)
// The [input] filtered with the applyTransform()
output := applyTransform(s, input)

debug.Printf(s, "PCollection filtered value: %v", output)
debug.Printf(s, "PCollection filtered value: %v", output)

err := beamx.Run(ctx, p)
err := beamx.Run(ctx, p)

if err != nil {
log.Exitf(context.Background(), "Failed to execute job: %v", err)
}
if err != nil {
log.Exitf(ctx, "Failed to execute job: %v", err)
}
}

// The method filters the collection so that the numbers are even
func applyTransform(s beam.Scope, input beam.PCollection) beam.PCollection {
return filter.Exclude(s, input, func(element int) bool {
return element % 2 == 1
})
return filter.Exclude(s, input, func(element int) bool {
return element%2 == 1
})
}


Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,21 @@ package main

import (
"context"
"strconv"
"strings"

"github.com/apache/beam/sdks/v2/go/pkg/beam"
"github.com/apache/beam/sdks/v2/go/pkg/beam/io/textio"
"github.com/apache/beam/sdks/v2/go/pkg/beam/log"
_ "github.com/apache/beam/sdks/v2/go/pkg/beam/transforms/filter"
_ "github.com/apache/beam/sdks/v2/go/pkg/beam/transforms/stats"
"github.com/apache/beam/sdks/v2/go/pkg/beam/x/beamx"
"github.com/apache/beam/sdks/v2/go/pkg/beam/x/debug"
"strconv"
"strings"
)

func main() {
ctx := context.Background()
beam.Init()

p, s := beam.NewPipelineWithRoot()

Expand Down Expand Up @@ -71,7 +73,7 @@ func main() {
err := beamx.Run(ctx, p)

if err != nil {
log.Exitf(context.Background(), "Failed to execute job: %v", err)
log.Exitf(ctx, "Failed to execute job: %v", err)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,21 @@ package main

import (
"context"
"strconv"
"strings"

"github.com/apache/beam/sdks/v2/go/pkg/beam"
"github.com/apache/beam/sdks/v2/go/pkg/beam/io/textio"
"github.com/apache/beam/sdks/v2/go/pkg/beam/log"
"github.com/apache/beam/sdks/v2/go/pkg/beam/transforms/filter"
"github.com/apache/beam/sdks/v2/go/pkg/beam/transforms/stats"
"github.com/apache/beam/sdks/v2/go/pkg/beam/x/beamx"
"github.com/apache/beam/sdks/v2/go/pkg/beam/x/debug"
"strconv"
"strings"
)

func main() {
ctx := context.Background()
beam.Init()

p, s := beam.NewPipelineWithRoot()

Expand Down Expand Up @@ -73,7 +75,7 @@ func main() {
err := beamx.Run(ctx, p)

if err != nil {
log.Exitf(context.Background(), "Failed to execute job: %v", err)
log.Exitf(ctx, "Failed to execute job: %v", err)
}
}

Expand Down
Loading
Loading