[ 
https://issues.apache.org/jira/browse/BEAM-3304?focusedWorklogId=680918&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-680918
 ]
ASF GitHub Bot logged work on BEAM-3304:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 12/Nov/21 17:25
            Start Date: 12/Nov/21 17:25
    Worklog Time Spent: 10m 
      Work Description: lostluck commented on a change in pull request #15952:
URL: https://github.com/apache/beam/pull/15952#discussion_r748453793



##########
File path: sdks/go/pkg/beam/core/graph/window/trigger/trigger.go
##########
@@ -138,49 +143,116 @@ func (tr Trigger) AlignedTo(period time.Duration, offset 
time.Time) Trigger {
                // TODO: Change to call UnixMilli() once we move to only 
supporting a go version > 1.17.
                offsetMillis = offset.Unix()*1e3 + 
int64(offset.Nanosecond())/1e6
        }
-       tr.TimestampTransforms = append(tr.TimestampTransforms, 
AlignToTransform{
+       tr.timestampTransforms = append(tr.timestampTransforms, 
AlignToTransform{
                Period: int64(period / time.Millisecond),
                Offset: offsetMillis,
        })
        return tr
 }
 
+// RepeatTrigger fires a sub-trigger repeatedly.
+type RepeatTrigger struct {
+       subTrigger Trigger
+}
+
+func (t RepeatTrigger) trigger() {}
+
+// SubTrigger returns the trigger to be repeated.
+func (t *RepeatTrigger) SubTrigger() Trigger {
+       return t.subTrigger
+}
+
 // Repeat constructs a trigger that fires a trigger repeatedly
 // once the condition has been met.
 //
 // Ex: trigger.Repeat(trigger.AfterCount(1)) is same as trigger.Always().
-func Repeat(tr Trigger) Trigger {
-       return Trigger{Kind: RepeatTrigger, SubTriggers: []Trigger{tr}}
+func Repeat(tr Trigger) *RepeatTrigger {
+       return &RepeatTrigger{subTrigger: tr}
+}
+
+// AfterEndOfWindowTrigger provides option to set triggers for early and late 
firing.
+type AfterEndOfWindowTrigger struct {
+       earlyFiring Trigger
+       lateFiring  Trigger
+}
+
+func (t AfterEndOfWindowTrigger) trigger() {}
+
+// EarlyTrigger returns the Early Firing trigger for AfterEndOfWindowTrigger.
+func (t *AfterEndOfWindowTrigger) EarlyTrigger() Trigger {
+       return t.earlyFiring
+}
+
+// LateTrigger returns the Late Firing trigger for AfterEndOfWindowTrigger.
+func (t *AfterEndOfWindowTrigger) LateTrigger() Trigger {
+       return t.lateFiring
 }
 
 // AfterEndOfWindow constructs a trigger that is configurable for early firing
 // (before the end of window) and late firing (after the end of window).
 //
-// Default Options are: Default Trigger for EarlyFiring and No LateFiring.
-// Override it with EarlyFiring and LateFiring methods on this trigger.
-func AfterEndOfWindow() Trigger {
+// Must call EarlyFiring or LateFiring method on this trigger at the time of 
setting.
+func AfterEndOfWindow() *AfterEndOfWindowTrigger {
        defaultEarly := Default()
-       return Trigger{Kind: AfterEndOfWindowTrigger, EarlyTrigger: 
&defaultEarly, LateTrigger: nil}
+       return &AfterEndOfWindowTrigger{earlyFiring: defaultEarly, lateFiring: 
nil}
 }
 
 // EarlyFiring configures an AfterEndOfWindow trigger with an implicitly
 // repeated trigger that applies before the end of the window.
-func (tr Trigger) EarlyFiring(early Trigger) Trigger {
-       if tr.Kind != AfterEndOfWindowTrigger {
-               panic(fmt.Errorf("can't apply early firing to %s, want: 
AfterEndOfWindowTrigger", tr.Kind))
-       }
-       tr.EarlyTrigger = &early
+func (tr *AfterEndOfWindowTrigger) EarlyFiring(early Trigger) 
*AfterEndOfWindowTrigger {
+       tr.earlyFiring = early
        return tr
 }
 
 // LateFiring configures an AfterEndOfWindow trigger with an implicitly
 // repeated trigger that applies after the end of the window.
 //
 // Not setting a late firing trigger means elements are discarded.
-func (tr Trigger) LateFiring(late Trigger) Trigger {
-       if tr.Kind != AfterEndOfWindowTrigger {
-               panic(fmt.Errorf("can't apply late firing to %s, want: 
AfterEndOfWindowTrigger", tr.Kind))
-       }
-       tr.LateTrigger = &late
+func (tr *AfterEndOfWindowTrigger) LateFiring(late Trigger) 
*AfterEndOfWindowTrigger {
+       tr.lateFiring = late
        return tr
 }
+
+// NYI(BEAM-3304). Intended for framework use only.
+// AfterAnyTrigger fires after any of sub-trigger fires.

Review comment:
       Go doc comments on exported types and functions *must* start with the 
identifier, so these lines are reversed.
   
   ```suggestion
   // AfterAnyTrigger fires after any of sub-trigger fires.
   // NYI(BEAM-3304). Intended for framework use only.
   ```
   
   Here and below.

##########
File path: sdks/go/pkg/beam/core/graph/window/trigger/trigger.go
##########
@@ -138,49 +143,116 @@ func (tr Trigger) AlignedTo(period time.Duration, offset 
time.Time) Trigger {
                // TODO: Change to call UnixMilli() once we move to only 
supporting a go version > 1.17.
                offsetMillis = offset.Unix()*1e3 + 
int64(offset.Nanosecond())/1e6
        }
-       tr.TimestampTransforms = append(tr.TimestampTransforms, 
AlignToTransform{
+       tr.timestampTransforms = append(tr.timestampTransforms, 
AlignToTransform{
                Period: int64(period / time.Millisecond),
                Offset: offsetMillis,
        })
        return tr
 }
 
+// RepeatTrigger fires a sub-trigger repeatedly.
+type RepeatTrigger struct {
+       subTrigger Trigger
+}
+
+func (t RepeatTrigger) trigger() {}
+
+// SubTrigger returns the trigger to be repeated.
+func (t *RepeatTrigger) SubTrigger() Trigger {
+       return t.subTrigger
+}
+
 // Repeat constructs a trigger that fires a trigger repeatedly
 // once the condition has been met.
 //
 // Ex: trigger.Repeat(trigger.AfterCount(1)) is same as trigger.Always().
-func Repeat(tr Trigger) Trigger {
-       return Trigger{Kind: RepeatTrigger, SubTriggers: []Trigger{tr}}
+func Repeat(tr Trigger) *RepeatTrigger {
+       return &RepeatTrigger{subTrigger: tr}
+}
+
+// AfterEndOfWindowTrigger provides option to set triggers for early and late 
firing.
+type AfterEndOfWindowTrigger struct {
+       earlyFiring Trigger
+       lateFiring  Trigger
+}
+
+func (t AfterEndOfWindowTrigger) trigger() {}
+
+// EarlyTrigger returns the Early Firing trigger for AfterEndOfWindowTrigger.
+func (t *AfterEndOfWindowTrigger) EarlyTrigger() Trigger {
+       return t.earlyFiring
+}
+
+// LateTrigger returns the Late Firing trigger for AfterEndOfWindowTrigger.
+func (t *AfterEndOfWindowTrigger) LateTrigger() Trigger {
+       return t.lateFiring
 }
 
 // AfterEndOfWindow constructs a trigger that is configurable for early firing
 // (before the end of window) and late firing (after the end of window).
 //
-// Default Options are: Default Trigger for EarlyFiring and No LateFiring.
-// Override it with EarlyFiring and LateFiring methods on this trigger.
-func AfterEndOfWindow() Trigger {
+// Must call EarlyFiring or LateFiring method on this trigger at the time of 
setting.
+func AfterEndOfWindow() *AfterEndOfWindowTrigger {
        defaultEarly := Default()
-       return Trigger{Kind: AfterEndOfWindowTrigger, EarlyTrigger: 
&defaultEarly, LateTrigger: nil}
+       return &AfterEndOfWindowTrigger{earlyFiring: defaultEarly, lateFiring: 
nil}
 }
 
 // EarlyFiring configures an AfterEndOfWindow trigger with an implicitly
 // repeated trigger that applies before the end of the window.
-func (tr Trigger) EarlyFiring(early Trigger) Trigger {
-       if tr.Kind != AfterEndOfWindowTrigger {
-               panic(fmt.Errorf("can't apply early firing to %s, want: 
AfterEndOfWindowTrigger", tr.Kind))
-       }
-       tr.EarlyTrigger = &early
+func (tr *AfterEndOfWindowTrigger) EarlyFiring(early Trigger) 
*AfterEndOfWindowTrigger {
+       tr.earlyFiring = early
        return tr
 }
 
 // LateFiring configures an AfterEndOfWindow trigger with an implicitly
 // repeated trigger that applies after the end of the window.
 //
 // Not setting a late firing trigger means elements are discarded.
-func (tr Trigger) LateFiring(late Trigger) Trigger {
-       if tr.Kind != AfterEndOfWindowTrigger {
-               panic(fmt.Errorf("can't apply late firing to %s, want: 
AfterEndOfWindowTrigger", tr.Kind))
-       }
-       tr.LateTrigger = &late
+func (tr *AfterEndOfWindowTrigger) LateFiring(late Trigger) 
*AfterEndOfWindowTrigger {
+       tr.lateFiring = late
        return tr
 }
+
+// NYI(BEAM-3304). Intended for framework use only.
+// AfterAnyTrigger fires after any of sub-trigger fires.
+type AfterAnyTrigger struct {
+       subTriggers []Trigger
+}
+
+func (t AfterAnyTrigger) trigger() {}
+
+// SubTriggers returns the subTriggers.

Review comment:
       Please make your use/spelling of "subtriggers" to be consistent. The 
method name is fine, but we should change the comment to something like
   ```suggestion
   // SubTriggers returns the component triggers.
   ```
   
   This avoids having to figure out "subtriggers" or "sub-triggers" or "sub 
triggers", which isn't a term used by the programming guide.  
https://beam.apache.org/documentation/programming-guide/#composite-triggers

##########
File path: sdks/go/pkg/beam/core/graph/window/trigger/trigger.go
##########
@@ -138,49 +143,116 @@ func (tr Trigger) AlignedTo(period time.Duration, offset 
time.Time) Trigger {
                // TODO: Change to call UnixMilli() once we move to only 
supporting a go version > 1.17.
                offsetMillis = offset.Unix()*1e3 + 
int64(offset.Nanosecond())/1e6
        }
-       tr.TimestampTransforms = append(tr.TimestampTransforms, 
AlignToTransform{
+       tr.timestampTransforms = append(tr.timestampTransforms, 
AlignToTransform{
                Period: int64(period / time.Millisecond),
                Offset: offsetMillis,
        })
        return tr
 }
 
+// RepeatTrigger fires a sub-trigger repeatedly.
+type RepeatTrigger struct {
+       subTrigger Trigger
+}
+
+func (t RepeatTrigger) trigger() {}
+
+// SubTrigger returns the trigger to be repeated.
+func (t *RepeatTrigger) SubTrigger() Trigger {
+       return t.subTrigger
+}
+
 // Repeat constructs a trigger that fires a trigger repeatedly
 // once the condition has been met.
 //
 // Ex: trigger.Repeat(trigger.AfterCount(1)) is same as trigger.Always().
-func Repeat(tr Trigger) Trigger {
-       return Trigger{Kind: RepeatTrigger, SubTriggers: []Trigger{tr}}
+func Repeat(tr Trigger) *RepeatTrigger {
+       return &RepeatTrigger{subTrigger: tr}
+}
+
+// AfterEndOfWindowTrigger provides option to set triggers for early and late 
firing.
+type AfterEndOfWindowTrigger struct {
+       earlyFiring Trigger
+       lateFiring  Trigger
+}
+
+func (t AfterEndOfWindowTrigger) trigger() {}
+
+// EarlyTrigger returns the Early Firing trigger for AfterEndOfWindowTrigger.
+func (t *AfterEndOfWindowTrigger) EarlyTrigger() Trigger {
+       return t.earlyFiring
+}
+
+// LateTrigger returns the Late Firing trigger for AfterEndOfWindowTrigger.
+func (t *AfterEndOfWindowTrigger) LateTrigger() Trigger {

Review comment:
       WRT method names, we can drop the `Trigger` suffix here. `Early()` and 
`Late()` are fine.

##########
File path: sdks/go/pkg/beam/core/graph/window/trigger/trigger.go
##########
@@ -138,49 +143,116 @@ func (tr Trigger) AlignedTo(period time.Duration, offset 
time.Time) Trigger {
                // TODO: Change to call UnixMilli() once we move to only 
supporting a go version > 1.17.
                offsetMillis = offset.Unix()*1e3 + 
int64(offset.Nanosecond())/1e6
        }
-       tr.TimestampTransforms = append(tr.TimestampTransforms, 
AlignToTransform{
+       tr.timestampTransforms = append(tr.timestampTransforms, 
AlignToTransform{
                Period: int64(period / time.Millisecond),
                Offset: offsetMillis,
        })
        return tr
 }
 
+// RepeatTrigger fires a sub-trigger repeatedly.
+type RepeatTrigger struct {
+       subTrigger Trigger
+}
+
+func (t RepeatTrigger) trigger() {}
+
+// SubTrigger returns the trigger to be repeated.
+func (t *RepeatTrigger) SubTrigger() Trigger {
+       return t.subTrigger
+}
+
 // Repeat constructs a trigger that fires a trigger repeatedly
 // once the condition has been met.
 //
 // Ex: trigger.Repeat(trigger.AfterCount(1)) is same as trigger.Always().
-func Repeat(tr Trigger) Trigger {
-       return Trigger{Kind: RepeatTrigger, SubTriggers: []Trigger{tr}}
+func Repeat(tr Trigger) *RepeatTrigger {
+       return &RepeatTrigger{subTrigger: tr}
+}
+
+// AfterEndOfWindowTrigger provides option to set triggers for early and late 
firing.
+type AfterEndOfWindowTrigger struct {
+       earlyFiring Trigger
+       lateFiring  Trigger
+}
+
+func (t AfterEndOfWindowTrigger) trigger() {}
+
+// EarlyTrigger returns the Early Firing trigger for AfterEndOfWindowTrigger.
+func (t *AfterEndOfWindowTrigger) EarlyTrigger() Trigger {
+       return t.earlyFiring
+}
+
+// LateTrigger returns the Late Firing trigger for AfterEndOfWindowTrigger.
+func (t *AfterEndOfWindowTrigger) LateTrigger() Trigger {
+       return t.lateFiring
 }
 
 // AfterEndOfWindow constructs a trigger that is configurable for early firing
 // (before the end of window) and late firing (after the end of window).
 //
-// Default Options are: Default Trigger for EarlyFiring and No LateFiring.
-// Override it with EarlyFiring and LateFiring methods on this trigger.
-func AfterEndOfWindow() Trigger {
+// Must call EarlyFiring or LateFiring method on this trigger at the time of 
setting.
+func AfterEndOfWindow() *AfterEndOfWindowTrigger {
        defaultEarly := Default()
-       return Trigger{Kind: AfterEndOfWindowTrigger, EarlyTrigger: 
&defaultEarly, LateTrigger: nil}
+       return &AfterEndOfWindowTrigger{earlyFiring: defaultEarly, lateFiring: 
nil}
 }
 
 // EarlyFiring configures an AfterEndOfWindow trigger with an implicitly
 // repeated trigger that applies before the end of the window.
-func (tr Trigger) EarlyFiring(early Trigger) Trigger {
-       if tr.Kind != AfterEndOfWindowTrigger {
-               panic(fmt.Errorf("can't apply early firing to %s, want: 
AfterEndOfWindowTrigger", tr.Kind))
-       }
-       tr.EarlyTrigger = &early
+func (tr *AfterEndOfWindowTrigger) EarlyFiring(early Trigger) 
*AfterEndOfWindowTrigger {
+       tr.earlyFiring = early
        return tr
 }
 
 // LateFiring configures an AfterEndOfWindow trigger with an implicitly
 // repeated trigger that applies after the end of the window.
 //
 // Not setting a late firing trigger means elements are discarded.
-func (tr Trigger) LateFiring(late Trigger) Trigger {
-       if tr.Kind != AfterEndOfWindowTrigger {
-               panic(fmt.Errorf("can't apply late firing to %s, want: 
AfterEndOfWindowTrigger", tr.Kind))
-       }
-       tr.LateTrigger = &late
+func (tr *AfterEndOfWindowTrigger) LateFiring(late Trigger) 
*AfterEndOfWindowTrigger {
+       tr.lateFiring = late
        return tr
 }
+
+// NYI(BEAM-3304). Intended for framework use only.
+// AfterAnyTrigger fires after any of sub-trigger fires.
+type AfterAnyTrigger struct {
+       subTriggers []Trigger

Review comment:
       Don't camelcase the T here. just use subtriggers, which is what the 
proto uses anyway. Similarly for the other  
   subtrigger fields.




-- 
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: github-unsubscr...@beam.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 680918)
    Time Spent: 14h 40m  (was: 14.5h)

> Go triggering support
> ---------------------
>
>                 Key: BEAM-3304
>                 URL: https://issues.apache.org/jira/browse/BEAM-3304
>             Project: Beam
>          Issue Type: Improvement
>          Components: sdk-go
>            Reporter: Henning Rohde
>            Priority: P3
>          Time Spent: 14h 40m
>  Remaining Estimate: 0h
>
> `Add support for triggers.
> [https://beam.apache.org/documentation/programming-guide/#triggers] 
> Triggers are special runner side behavior indicating how to handle data WRT 
> the watermark and window. Commonly configuring the processing for “late data” 
> and similar.
> These are not currently implemented for user use in the Go SDK. Reshuffle 
> configures triggers, but it’s not accessible. A correct trigger 
> implementation can at least re-implement Reshuffle in a user pipeline, rather 
> than handled specially within the framework.
>  * Requires extending the window package to be able to configure the various 
> triggers.
>  * Specifically being able to compose triggers as also permitted by the proto.
>  ** 
> [https://github.com/apache/beam/blob/6e7b1c44bc7275ee047afc059fd610cd3f4e5bee/model/pipeline/src/main/proto/beam_runner_api.proto#L1111]
>  
>  * Requires updating the graphx package translate.go to marshal (and 
> unmarshal?) the triggers to and from Beam PipelineProto Windowing strategies.
>  * Requires supporting triggers with the beam.WindowInto transform for user 
> pipeline use as well as complete documentation on its use from the user side.
>  ** 
> [https://github.com/apache/beam/blob/6e7b1c44bc7275ee047afc059fd610cd3f4e5bee/sdks/go/pkg/beam/windowing.go]
>  
>  * Panes need to be decoded, otherwise triggering will cause runtime errors: 
> [https://lists.apache.org/thread.html/r94c42d2d116f6464cd6b689543e5e578edf8310bf7c6e48a0958a56c%40%3Cdev.beam.apache.org%3E]
>  
>  * Handle pane propagation and observation in the exec package, and in user 
> dofns. 
>  ** Panes indicate whether data was on time or not, and similar facets which 
> may be relevant for processing.
>  ** Might simply extend the existing window interface.
>  
> Similar to windowing,  many of the same places as 
> https://issues.apache.org/jira/browse/BEAM-11100 need to be modified.
> At simplest though, it's mostly a runner side construction, with less concern 
> on the exec side, and generally much simpler. 
> Appropriate integration tests against portable runners must be implemented:
> [https://github.com/apache/beam/tree/master/sdks/go/test/integration/primitives]
>  
> And optionally add support for the configurable triggers to the the Go Direct 
> Runner. However, the results must be compared and validated against a 
> semantically correct runner like the python portable runner first. At 
> minimum, the Go Direct Runner should be made aware of triggers and produce a 
> coherent error whenever there's a trigger it can't deal with.
>  



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to