[ 
https://issues.apache.org/jira/browse/BEAM-3304?focusedWorklogId=638495&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-638495
 ]

ASF GitHub Bot logged work on BEAM-3304:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 17/Aug/21 03:33
            Start Date: 17/Aug/21 03:33
    Worklog Time Spent: 10m 
      Work Description: lostluck commented on a change in pull request #15239:
URL: https://github.com/apache/beam/pull/15239#discussion_r690004841



##########
File path: sdks/go/pkg/beam/core/runtime/exec/datasource.go
##########
@@ -144,8 +144,8 @@ func (n *DataSource) Process(ctx context.Context) error {
                if n.incrementIndexAndCheckSplit() {
                        return nil
                }
-               // TODO(lostluck) 2020/02/22: Should we include window headers 
or just count the element sizes?
-               ws, t, err := DecodeWindowedValueHeader(wc, r)
+    // TODO(lostluck) 2020/02/22: Should we include window headers or just 
count the element sizes?

Review comment:
       Probably need to run gofmt again.

##########
File path: sdks/go/pkg/beam/windowing.go
##########
@@ -21,21 +21,48 @@ import (
        "github.com/apache/beam/sdks/go/pkg/beam/internal/errors"
 )
 
+type WindowIntoOption interface {
+       windowIntoOption()
+}
+
+type WindowTrigger struct {
+       Name window.Trigger
+}
+
+func (t WindowTrigger) windowIntoOption() {}
+
+type AccumulationMode struct {
+       Mode window.AccumulationMode
+}
+
+func (m AccumulationMode) windowIntoOption() {}
+
 // 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, wfn *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")
        }
+       ws := window.WindowingStrategy{Fn: wfn, Trigger: window.Trigger{}}
+       for _, opt := range opts {
+               switch opt := opt.(type) {
+               case WindowTrigger:
+                       ws.Trigger = opt.Name
+               case AccumulationMode:
+                       ws.AccumulationMode = opt.Mode
+               default:
+                       panic("Invalid option for Windowing Strategy")

Review comment:
       Since WindowIntoOptions are implementers of interfaces, we can improve 
this by actually communicating what's going wrong. That is something like 
`panic(fmt.Sprintf("Unknown WindowingInto option type: %T: %v", opt, opt))` 
which communicates the type, and if it's printable somehow so it's easier to 
find what needs working on.
   
   Since an error like this is likely an SDK dev error, a panic is fine, as 
there's nothing a user can do about it programmatically.

##########
File path: sdks/go/pkg/beam/core/runtime/graphx/translate.go
##########
@@ -981,22 +981,135 @@ func marshalWindowingStrategy(c *CoderMarshaller, w 
*window.WindowingStrategy) (
        } else {
                mergeStat = pipepb.MergeStatus_NON_MERGING
        }
+
        ws := &pipepb.WindowingStrategy{
                WindowFn:         windowFn,
                MergeStatus:      mergeStat,
-               AccumulationMode: pipepb.AccumulationMode_DISCARDING,
                WindowCoderId:    windowCoderId,
-               Trigger: &pipepb.Trigger{
+               Trigger:          makeTrigger(w.Trigger),
+               AccumulationMode: makeAccumulationMode(w.AccumulationMode),
+               OutputTime:       pipepb.OutputTime_END_OF_WINDOW,
+               ClosingBehavior:  pipepb.ClosingBehavior_EMIT_IF_NONEMPTY,
+               AllowedLateness:  0,
+               OnTimeBehavior:   pipepb.OnTimeBehavior_FIRE_IF_NONEMPTY,
+       }
+       return ws, nil
+}
+
+func makeAccumulationMode(m window.AccumulationMode) 
pipepb.AccumulationMode_Enum {
+       switch m {
+       case window.Accumulating:
+               return pipepb.AccumulationMode_ACCUMULATING
+       case window.Discarding:
+               return pipepb.AccumulationMode_DISCARDING
+       case window.Unspecified:
+               return pipepb.AccumulationMode_UNSPECIFIED
+       case window.Retracting:
+               return pipepb.AccumulationMode_RETRACTING
+       default:
+               return pipepb.AccumulationMode_DISCARDING
+       }
+}
+
+func makeTrigger(t window.Trigger) *pipepb.Trigger {
+       switch t.Kind {
+       case window.DefaultTrigger:
+               return &pipepb.Trigger{
                        Trigger: &pipepb.Trigger_Default_{
                                Default: &pipepb.Trigger_Default{},
                        },
-               },
-               OutputTime:      pipepb.OutputTime_END_OF_WINDOW,
-               ClosingBehavior: pipepb.ClosingBehavior_EMIT_IF_NONEMPTY,
-               AllowedLateness: 0,
-               OnTimeBehavior:  pipepb.OnTimeBehavior_FIRE_ALWAYS,
+               }
+       case window.AlwaysTrigger:
+               return &pipepb.Trigger{
+                       Trigger: &pipepb.Trigger_Always_{
+                               Always: &pipepb.Trigger_Always{},
+                       },
+               }
+       case window.AfterAnyTrigger:
+               return &pipepb.Trigger{
+                       Trigger: &pipepb.Trigger_AfterAny_{
+                               AfterAny: &pipepb.Trigger_AfterAny{
+                                       Subtriggers: 
extractSubtriggers(t.SubTriggers),
+                               },
+                       },
+               }
+       case window.AfterAllTrigger:
+               return &pipepb.Trigger{
+                       Trigger: &pipepb.Trigger_AfterAll_{
+                               AfterAll: &pipepb.Trigger_AfterAll{
+                                       Subtriggers: 
extractSubtriggers(t.SubTriggers),
+                               },
+                       },
+               }
+       case window.AfterProcessingTimeTrigger:
+               // TODO: Right now would work only for single delay value.

Review comment:
       Prefer not to leave unreferenced TODOs. Add the JIRA (BEAM-3304 ) for 
these or file a new one for these specific TODOs and list them as subtasks to 
BEAM-3304




-- 
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]


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

    Worklog Id:     (was: 638495)
    Time Spent: 4h 50m  (was: 4h 40m)

> 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
>            Assignee: Ritesh Ghorse
>            Priority: P3
>          Time Spent: 4h 50m
>  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.3.4#803005)

Reply via email to