Skip to content

Commit

Permalink
[BEAM-11106] documentation for SDF truncation in Go (#17781)
Browse files Browse the repository at this point in the history
* documentation for sdf truncation

* update import

* update snippet
  • Loading branch information
riteshghorse authored Jun 2, 2022
1 parent d63c42b commit 937e22f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
17 changes: 17 additions & 0 deletions sdks/go/examples/snippets/04transforms.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,23 @@ func (fn *weDoFn) ProcessElement(e *CustomWatermarkEstimator, element string) {

// [END watermarkestimation_customestimator]

// [START sdf_truncate]

// TruncateRestriction is a transform that is triggered when pipeline starts to drain. It helps to finish a
// pipeline quicker by truncating the restriction.
func (fn *splittableDoFn) TruncateRestriction(rt *sdf.LockRTracker, element string) offsetrange.Restriction {
start := rt.GetRestriction().(offsetrange.Restriction).Start
prevEnd := rt.GetRestriction().(offsetrange.Restriction).End
// truncate the restriction by half.
newEnd := prevEnd / 2
return offsetrange.Restriction{
Start: start,
End: newEnd,
}
}

// [END sdf_truncate]

// [START cogroupbykey_output_helpers]

func formatCoGBKResults(key string, emailIter, phoneIter func(*string) bool) string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6524,6 +6524,11 @@ unbounded restrictions finish processing at the next SDF-initiated checkpoint or
You are able to override this default behavior by defining the appropriate method on the restriction
provider.

{{< paragraph class="language-go" >}}
Note: Once the pipeline drain starts and truncate restriction transform is triggered, the `sdf.ProcessContinuation`
will not be rescheduled.
{{< /paragraph >}}

{{< highlight java >}}
{{< code_sample "examples/java/src/main/java/org/apache/beam/examples/snippets/Snippets.java" SDF_Truncate >}}
{{< /highlight >}}
Expand All @@ -6533,7 +6538,7 @@ provider.
{{< /highlight >}}

{{< highlight go >}}
This is not supported yet, see BEAM-11106.
{{< code_sample "sdks/go/examples/snippets/04transforms.go" sdf_truncate >}}
{{< /highlight >}}

### 12.7. Bundle finalization {#bundle-finalization}
Expand Down

0 comments on commit 937e22f

Please sign in to comment.