Skip to content

Commit b9f7274

Browse files
authored
Merge pull request #33 from reugn/develop
v0.5.2
2 parents 67e21cc + e1674a1 commit b9f7274

9 files changed

+197
-58
lines changed

flow/filter.go

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ type Filter struct {
2323
parallelism uint
2424
}
2525

26+
// Verify Filter satisfies the Flow interface.
27+
var _ streams.Flow = (*Filter)(nil)
28+
2629
// NewFilter returns a new Filter instance.
2730
// filterFunc is the filter predicate function.
2831
// parallelism is the flow parallelism factor. In case the events order matters, use parallelism = 1.

flow/flat_map.go

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ type FlatMap struct {
2121
parallelism uint
2222
}
2323

24+
// Verify FlatMap satisfies the Flow interface.
25+
var _ streams.Flow = (*FlatMap)(nil)
26+
2427
// NewFlatMap returns a new FlatMap instance.
2528
// flatMapFunc is the FlatMap transformation function.
2629
// parallelism is the flow parallelism factor. In case the events order matters, use parallelism = 1.

flow/map.go

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ type Map struct {
2121
parallelism uint
2222
}
2323

24+
// Verify Map satisfies the Flow interface.
25+
var _ streams.Flow = (*Map)(nil)
26+
2427
// NewMap returns a new Map instance.
2528
// mapFunc is the Map transformation function.
2629
// parallelism is the flow parallelism factor. In case the events order matters, use parallelism = 1.

flow/pass_through.go

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ type PassThrough struct {
1414
out chan interface{}
1515
}
1616

17+
// Verify PassThrough satisfies the Flow interface.
18+
var _ streams.Flow = (*PassThrough)(nil)
19+
1720
// NewPassThrough returns a new PassThrough instance.
1821
func NewPassThrough() *PassThrough {
1922
passThrough := &PassThrough{

flow/sliding_window.go

+24-18
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import (
88
"github.com/reugn/go-streams"
99
)
1010

11-
// SlidingWindow flow
12-
// Generates windows of a specified fixed size
13-
// Slides by a slide interval with records overlap
11+
// SlidingWindow assigns elements to windows of fixed length configured by the window size parameter.
12+
// An additional window slide parameter controls how frequently a sliding window is started.
13+
// Hence, sliding windows can be overlapping if the slide is smaller than the window size.
14+
// In this case elements are assigned to multiple windows.
1415
type SlidingWindow struct {
1516
sync.Mutex
1617
size time.Duration
@@ -22,26 +23,31 @@ type SlidingWindow struct {
2223
timestampExtractor func(interface{}) int64
2324
}
2425

25-
// NewSlidingWindow returns a new Processing time sliding window
26-
// size - The size of the generated windows
27-
// slide - The slide interval of the generated windows
26+
// Verify SlidingWindow satisfies the Flow interface.
27+
var _ streams.Flow = (*SlidingWindow)(nil)
28+
29+
// NewSlidingWindow returns a new processing time based SlidingWindow.
30+
// Processing time refers to the system time of the machine that is executing the respective operation.
31+
// size is the size of the generated windows.
32+
// slide is the sliding interval of the generated windows.
2833
func NewSlidingWindow(size time.Duration, slide time.Duration) *SlidingWindow {
2934
return NewSlidingWindowWithTsExtractor(size, slide, nil)
3035
}
3136

32-
// NewSlidingWindowWithTsExtractor returns a new Event time sliding window
33-
// Gives correct results on out-of-order events, late events, or on replays of data
34-
// size - The size of the generated windows
35-
// slide - The slide interval of the generated windows
36-
// timestampExtractor - The record timestamp (in nanoseconds) extractor
37+
// NewSlidingWindowWithTsExtractor returns a new event time based SlidingWindow.
38+
// Event time is the time that each individual event occurred on its producing device.
39+
// Gives correct results on out-of-order events, late events, or on replays of data.
40+
// size is the size of the generated windows.
41+
// slide is the sliding interval of the generated windows.
42+
// timestampExtractor is the record timestamp (in nanoseconds) extractor.
3743
func NewSlidingWindowWithTsExtractor(size time.Duration, slide time.Duration,
3844
timestampExtractor func(interface{}) int64) *SlidingWindow {
3945
window := &SlidingWindow{
4046
size: size,
4147
slide: slide,
4248
queue: &PriorityQueue{},
4349
in: make(chan interface{}),
44-
out: make(chan interface{}), //windows channel
50+
out: make(chan interface{}), // windows channel
4551
done: make(chan struct{}),
4652
timestampExtractor: timestampExtractor,
4753
}
@@ -50,13 +56,13 @@ func NewSlidingWindowWithTsExtractor(size time.Duration, slide time.Duration,
5056
return window
5157
}
5258

53-
// Via streams a data through the given flow
59+
// Via streams data through the given flow
5460
func (sw *SlidingWindow) Via(flow streams.Flow) streams.Flow {
5561
go sw.transmit(flow)
5662
return flow
5763
}
5864

59-
// To streams a data to the given sink
65+
// To streams data to the given sink
6066
func (sw *SlidingWindow) To(sink streams.Sink) {
6167
sw.transmit(sink)
6268
}
@@ -71,15 +77,15 @@ func (sw *SlidingWindow) In() chan<- interface{} {
7177
return sw.in
7278
}
7379

74-
// retransmit an emitted window to the next Inlet
80+
// submit emitted windows to the next Inlet
7581
func (sw *SlidingWindow) transmit(inlet streams.Inlet) {
7682
for elem := range sw.Out() {
7783
inlet.In() <- elem
7884
}
7985
close(inlet.In())
8086
}
8187

82-
// extract a timestamp from the record if timestampExtractor is set
88+
// extract timestamp from the record if the timestampExtractor is set
8389
// return the system clock time otherwise
8490
func (sw *SlidingWindow) timestamp(elem interface{}) int64 {
8591
if sw.timestampExtractor == nil {
@@ -99,7 +105,7 @@ func (sw *SlidingWindow) receive() {
99105
close(sw.out)
100106
}
101107

102-
// triggered by the slide interval
108+
// emit is triggered by the sliding interval
103109
func (sw *SlidingWindow) emit() {
104110
for {
105111
select {
@@ -130,7 +136,7 @@ func (sw *SlidingWindow) emit() {
130136
}
131137
sw.Unlock()
132138

133-
// send to the out chan
139+
// send window slice to the out chan
134140
if len(windowSlice) > 0 {
135141
sw.out <- windowSlice
136142
}

flow/throttler.go

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ type Throttler struct {
2929
counter uint
3030
}
3131

32+
// Verify Throttler satisfies the Flow interface.
33+
var _ streams.Flow = (*Throttler)(nil)
34+
3235
// NewThrottler returns a new Throttler instance.
3336
// elements is the maximum number of elements to be produced per the given period of time.
3437
// bufferSize defines the incoming elements buffer size.

flow/tumbling_window.go

+12-10
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ import (
77
"github.com/reugn/go-streams"
88
)
99

10-
// TumblingWindow flow
11-
// Generates windows of a specified window size
12-
// Tumbling windows have a fixed size and do not overlap
10+
// TumblingWindow assigns each element to a window of a specified window size.
11+
// Tumbling windows have a fixed size and do not overlap.
1312
type TumblingWindow struct {
1413
sync.Mutex
1514
size time.Duration
@@ -19,27 +18,30 @@ type TumblingWindow struct {
1918
buffer []interface{}
2019
}
2120

22-
// NewTumblingWindow returns a new TumblingWindow instance
23-
// size - The size of the generated windows
21+
// Verify TumblingWindow satisfies the Flow interface.
22+
var _ streams.Flow = (*TumblingWindow)(nil)
23+
24+
// NewTumblingWindow returns a new TumblingWindow instance.
25+
// size is the size of the generated windows.
2426
func NewTumblingWindow(size time.Duration) *TumblingWindow {
2527
window := &TumblingWindow{
2628
size: size,
2729
in: make(chan interface{}),
28-
out: make(chan interface{}), //windows channel
30+
out: make(chan interface{}), // windows channel
2931
done: make(chan struct{}),
3032
}
3133
go window.receive()
3234
go window.emit()
3335
return window
3436
}
3537

36-
// Via streams a data through the given flow
38+
// Via streams data through the given flow
3739
func (tw *TumblingWindow) Via(flow streams.Flow) streams.Flow {
3840
go tw.transmit(flow)
3941
return flow
4042
}
4143

42-
// To streams a data to the given sink
44+
// To streams data to the given sink
4345
func (tw *TumblingWindow) To(sink streams.Sink) {
4446
tw.transmit(sink)
4547
}
@@ -54,7 +56,7 @@ func (tw *TumblingWindow) In() chan<- interface{} {
5456
return tw.in
5557
}
5658

57-
// retransmit the emitted window to the next Inlet
59+
// submit emitted windows to the next Inlet
5860
func (tw *TumblingWindow) transmit(inlet streams.Inlet) {
5961
for elem := range tw.Out() {
6062
inlet.In() <- elem
@@ -81,7 +83,7 @@ func (tw *TumblingWindow) emit() {
8183
windowSlice := append(tw.buffer[:0:0], tw.buffer...)
8284
tw.buffer = nil
8385
tw.Unlock()
84-
// send to the out chan
86+
// send window slice to the out chan
8587
if len(windowSlice) > 0 {
8688
tw.out <- windowSlice
8789
}

go.mod

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ module github.com/reugn/go-streams
33
go 1.14
44

55
require (
6-
github.com/Shopify/sarama v1.27.0
7-
github.com/aerospike/aerospike-client-go v3.0.5+incompatible
8-
github.com/apache/pulsar-client-go v0.1.1
6+
github.com/Shopify/sarama v1.27.1
7+
github.com/aerospike/aerospike-client-go v3.1.0+incompatible
8+
github.com/apache/pulsar-client-go v0.2.0
99
github.com/go-redis/redis v6.15.9+incompatible
10-
github.com/onsi/gomega v1.10.1 // indirect
10+
github.com/onsi/gomega v1.10.3 // indirect
1111
github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da // indirect
1212
)

0 commit comments

Comments
 (0)