snippets package - github.com/apache/beam/sdks/v2/go/examples/snippets - Go Packages

Package snippets contains code used in the Beam Programming Guide as examples for the Apache Beam Go SDK. These snippets are compiled and their tests run to ensure correctness. However, due to their piecemeal pedagogical use, they may not be the best example of production code.

The Beam Programming Guide can be found at https://beam.apache.org/documentation/programming-guide/.

Package snippets contains code used in the Beam Programming Guide as examples for the Apache Beam Go SDK. These snippets are compiled and their tests run to ensure correctness. However, due to their piecemeal pedagogical use, they may not be the best example of production code.

The Beam Programming Guide can be found at https://beam.apache.org/documentation/programming-guide/.

This section is empty.

This section is empty.

AddTimestampDoFn extracts an event time from a LogEntry.

[START countwords_composite] CountWords is a function that builds a composite PTransform to count the number of times each word appears.

Create demonstrates using beam.CreateList.

func LogicalTypeExample()
func PipelineConstruction()

PipelineConstruction contains snippets for the initial sections of the Beam Programming Guide, from initializing to submitting a pipeline.

PipelineOptions shows basic pipeline options using flags.

func PipelineOptionsCustom()

PipelineOptionsCustom shows slightly less basic pipeline options using flags.

type ComputeWordLengthFn struct{}

ComputeWordLengthFn is the DoFn to perform on each element in the input PCollection.

func (fn *ComputeWordLengthFn) ProcessElement(word string, emit func(int))

ProcessElement is the method to execute for each element.

type CustomWatermarkEstimator struct {
	
}

CustomWatermarkEstimator is a custom watermark estimator. You may use any type here, including some of Beam's built in watermark estimator types, e.g. sdf.WallTimeWatermarkEstimator, sdf.TimestampObservingWatermarkEstimator, and sdf.ManualWatermarkEstimator

CurrentWatermark returns the current watermark and is invoked on DoFn splits and self-checkpoints. Watermark estimators must implement CurrentWatermark() time.Time

ObserveTimestamp is called on the output timestamps of all emitted elements to update the watermark. It is optional

type JoinedEvent struct {
	View, Click *Event
}

LogEntry is a dummy type for documentation purposes.

type MyCustomType struct{}
type MyMetricsDoFn struct {
	
}
func (fn *MyMetricsDoFn) Setup()
type Purchase struct {
	
	UserID string `beam:"userId"`
	
	ItemID int64 `beam:"itemId"`
	
	ShippingAddress ShippingAddress `beam:"shippingAddress"`
	
	Cost int64 `beam:"cost"`
	
	
	
	Transactions []Transaction `beam:"transactions"`
}
type ShippingAddress struct {
	StreetAddress string  `beam:"streetAddress"`
	City          string  `beam:"city"`
	State         *string `beam:"state"`
	Country       string  `beam:"country"`
	PostCode      string  `beam:"postCode"`
}
type SomeService struct {
	ThrottlingErr error
}
type Student struct {
	Percentile int
}

TimestampNanos is a logical type using time.Time, but encodes as a schema type.

type TimestampNanosProvider struct{}

TimestampNanosProvider implements the beam.SchemaProvider interface.

BuildDecoder builds a Beam schema decoder for the TimestampNanos type.

BuildEncoder builds a Beam schema encoder for the TimestampNanos type.

FromLogicalType converts checks if the given type is TimestampNanos, and if so returns the storage type.

type Transaction struct {
	Bank           string  `beam:"bank"`
	PurchaseAmount float64 `beam:"purchaseAmount"`
}
type WatermarkState struct {
	Watermark time.Time
}

WatermarkState is a custom type.`

It is optional to write your own state type when making a custom estimator.