|
27 | 27 | package main
|
28 | 28 |
|
29 | 29 | import (
|
30 |
| - "context" |
31 |
| - "github.com/apache/beam/sdks/v2/go/pkg/beam" |
32 |
| - "github.com/apache/beam/sdks/v2/go/pkg/beam/log" |
33 |
| - "github.com/apache/beam/sdks/v2/go/pkg/beam/x/beamx" |
34 |
| - "github.com/apache/beam/sdks/v2/go/pkg/beam/x/debug" |
35 |
| - "github.com/apache/beam/sdks/v2/go/pkg/beam/transforms/filter" |
| 30 | + "context" |
| 31 | + |
| 32 | + "github.com/apache/beam/sdks/v2/go/pkg/beam" |
| 33 | + "github.com/apache/beam/sdks/v2/go/pkg/beam/log" |
| 34 | + "github.com/apache/beam/sdks/v2/go/pkg/beam/transforms/filter" |
| 35 | + "github.com/apache/beam/sdks/v2/go/pkg/beam/x/beamx" |
| 36 | + "github.com/apache/beam/sdks/v2/go/pkg/beam/x/debug" |
36 | 37 | )
|
37 | 38 |
|
38 | 39 | func main() {
|
39 |
| - ctx := context.Background() |
| 40 | + ctx := context.Background() |
| 41 | + beam.Init() |
40 | 42 |
|
41 |
| - p, s := beam.NewPipelineWithRoot() |
| 43 | + p, s := beam.NewPipelineWithRoot() |
42 | 44 |
|
43 |
| - // List of elements |
44 |
| - input := beam.Create(s, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) |
| 45 | + // List of elements |
| 46 | + input := beam.Create(s, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) |
45 | 47 |
|
46 |
| - // The [input] filtered with the applyTransform() |
47 |
| - output := applyTransform(s, input) |
| 48 | + // The [input] filtered with the applyTransform() |
| 49 | + output := applyTransform(s, input) |
48 | 50 |
|
49 |
| - debug.Printf(s, "PCollection filtered value: %v", output) |
| 51 | + debug.Printf(s, "PCollection filtered value: %v", output) |
50 | 52 |
|
51 |
| - err := beamx.Run(ctx, p) |
| 53 | + err := beamx.Run(ctx, p) |
52 | 54 |
|
53 |
| - if err != nil { |
54 |
| - log.Exitf(context.Background(), "Failed to execute job: %v", err) |
55 |
| - } |
| 55 | + if err != nil { |
| 56 | + log.Exitf(ctx, "Failed to execute job: %v", err) |
| 57 | + } |
56 | 58 | }
|
57 | 59 |
|
58 | 60 | // The method filters the collection so that the numbers are even
|
59 | 61 | func applyTransform(s beam.Scope, input beam.PCollection) beam.PCollection {
|
60 |
| - return filter.Exclude(s, input, func(element int) bool { |
61 |
| - return element % 2 == 1 |
62 |
| - }) |
| 62 | + return filter.Exclude(s, input, func(element int) bool { |
| 63 | + return element%2 == 1 |
| 64 | + }) |
63 | 65 | }
|
64 |
| - |
65 |
| - |
0 commit comments