lostluck commented on a change in pull request #15239:
URL: https://github.com/apache/beam/pull/15239#discussion_r681196854
##########
File path: sdks/go/pkg/beam/windowing.go
##########
@@ -21,21 +21,47 @@ import (
"github.com/apache/beam/sdks/go/pkg/beam/internal/errors"
)
+type WindowIntoOption interface {
+ windowIntoOption()
+}
+
+type WindowTrigger struct {
+ Name window.TriggerType
+}
+
+func (t WindowTrigger) windowIntoOption() {}
+
+func (t WindowTrigger) GetName() window.TriggerType {
+ return t.Name
+}
+
// WindowInto applies the windowing strategy to each element.
-func WindowInto(s Scope, ws *window.Fn, col PCollection) PCollection {
- return Must(TryWindowInto(s, ws, col))
+func WindowInto(s Scope, ws *window.Fn, col PCollection, opts
...WindowIntoOption) PCollection {
+ return Must(TryWindowInto(s, ws, col, opts...))
}
// TryWindowInto attempts to insert a WindowInto transform.
-func TryWindowInto(s Scope, ws *window.Fn, col PCollection) (PCollection,
error) {
+func TryWindowInto(s Scope, ws *window.Fn, col PCollection, opts
...WindowIntoOption) (PCollection, error) {
if !s.IsValid() {
return PCollection{}, errors.New("invalid scope")
}
if !col.IsValid() {
return PCollection{}, errors.New("invalid input pcollection")
}
+ var edge *graph.MultiEdge
+ for _, opt := range opts {
Review comment:
Consider just creating a windowing strategy before iterating over the
ops with all the reasonable defaults set, and then update that strategy with
the whatever is in options. Then we don't end up with a combinatorial explosion
when other options are added or with the awkward "if there are no options, do
this" length check written below.
##########
File path: sdks/go/pkg/beam/windowing.go
##########
@@ -21,21 +21,47 @@ import (
"github.com/apache/beam/sdks/go/pkg/beam/internal/errors"
)
+type WindowIntoOption interface {
+ windowIntoOption()
+}
+
+type WindowTrigger struct {
+ Name window.TriggerType
+}
+
+func (t WindowTrigger) windowIntoOption() {}
+
+func (t WindowTrigger) GetName() window.TriggerType {
Review comment:
There's no need for a GetName function. As a rule, don't add "Get" to a
method that just returns a field.
See https://golang.org/doc/effective_go#Getters
##########
File path: sdks/go/pkg/beam/windowing.go
##########
@@ -21,21 +21,47 @@ import (
"github.com/apache/beam/sdks/go/pkg/beam/internal/errors"
)
+type WindowIntoOption interface {
+ windowIntoOption()
+}
+
+type WindowTrigger struct {
+ Name window.TriggerType
+}
+
+func (t WindowTrigger) windowIntoOption() {}
+
+func (t WindowTrigger) GetName() window.TriggerType {
+ return t.Name
+}
+
// WindowInto applies the windowing strategy to each element.
-func WindowInto(s Scope, ws *window.Fn, col PCollection) PCollection {
- return Must(TryWindowInto(s, ws, col))
+func WindowInto(s Scope, ws *window.Fn, col PCollection, opts
...WindowIntoOption) PCollection {
+ return Must(TryWindowInto(s, ws, col, opts...))
}
// TryWindowInto attempts to insert a WindowInto transform.
-func TryWindowInto(s Scope, ws *window.Fn, col PCollection) (PCollection,
error) {
+func TryWindowInto(s Scope, ws *window.Fn, col PCollection, opts
...WindowIntoOption) (PCollection, error) {
if !s.IsValid() {
return PCollection{}, errors.New("invalid scope")
}
if !col.IsValid() {
return PCollection{}, errors.New("invalid input pcollection")
}
+ var edge *graph.MultiEdge
+ for _, opt := range opts {
+ switch opt.(type) {
+ case WindowTrigger:
+ edge = graph.NewWindowInto(s.real, s.scope,
&window.WindowingStrategy{Fn: ws, Trigger: opt.(WindowTrigger).GetName()},
col.n)
Review comment:
Consider accessing the trigger kind directly with `.Name` without a
method instead, and remove the method.
--
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]