Documentation
¶
Index ¶
- Constants
- type Aggeregator
- type And
- type Average
- type Count
- type Distinct
- type Equal
- type Event
- type From
- type LargerThan
- type Length
- type LengthBatch
- type LessThan
- type Limit
- type Limiter
- type Max
- type Min
- type NoLimit
- type NoOrder
- type NotEqual
- type OrderBy
- type Select
- type SelectAll
- type Selector
- type Sorter
- type Stream
- func (s *Stream) Average(name string) *Stream
- func (s *Stream) Close() error
- func (s *Stream) Count(name string) *Stream
- func (s *Stream) Distinct(name string) *Stream
- func (s *Stream) Equals(name string, value any) *Stream
- func (s *Stream) From(typ any) *Stream
- func (s *Stream) Input() chan any
- func (s *Stream) IsClosed() bool
- func (s *Stream) LargerThan(name string, value any) *Stream
- func (s *Stream) Length(length int) *Stream
- func (s *Stream) LengthBatch(length int) *Stream
- func (s *Stream) LessThan(name string, value any) *Stream
- func (s *Stream) Limit(limit, offset int) *Stream
- func (s *Stream) Listen(input any)
- func (s *Stream) Max(name string) *Stream
- func (s *Stream) Min(name string) *Stream
- func (s *Stream) OrderBy(name string, desc bool) *Stream
- func (s *Stream) Output() chan []Event
- func (s *Stream) Run()
- func (s *Stream) Select(name string) *Stream
- func (s *Stream) SelectAll() *Stream
- func (s *Stream) String() string
- func (s *Stream) Sum(name string) *Stream
- func (s *Stream) Time(expire time.Duration, unit lexer.Token) *Stream
- func (s *Stream) TimeBatch(expire time.Duration, unit lexer.Token) *Stream
- func (s *Stream) Update(input any)
- type Sum
- type Time
- type TimeBatch
- type Where
- type Window
Examples ¶
Constants ¶
View Source
const ( DESC = true ASC = false )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Aggeregator ¶ added in v0.0.2
type Average ¶
type Average struct {
Name string
}
Example ¶
package main
import (
"fmt"
"github.com/itsubaki/gostream/stream"
)
func main() {
type LogEvent struct {
Level int
}
e := make([]stream.Event, 0)
for i := 0; i < 10; i++ {
e = append(e, stream.NewEvent(LogEvent{
Level: i,
}))
}
avg := &stream.Average{Name: "Level"}
out := avg.Apply(e)
fmt.Println(out[len(out)-1].ResultSet)
}
Output: [4.5]
type Count ¶
type Count struct {
Name string
}
Example ¶
package main
import (
"fmt"
"github.com/itsubaki/gostream/stream"
)
func main() {
type LogEvent struct {
Level int
}
e := make([]stream.Event, 0)
for i := 0; i < 10; i++ {
e = append(e, stream.NewEvent(LogEvent{
Level: i,
}))
}
c := &stream.Count{Name: "Level"}
out := c.Apply(e)
fmt.Println(out[len(out)-1].ResultSet)
}
Output: [10]
type Distinct ¶
type Distinct struct {
Name string
}
Example ¶
package main
import (
"fmt"
"github.com/itsubaki/gostream/stream"
)
func main() {
type LogEvent struct {
Level int
}
e := make([]stream.Event, 0)
e = append(e, stream.NewEvent(LogEvent{Level: 0}))
e = append(e, stream.NewEvent(LogEvent{Level: 0}))
e = append(e, stream.NewEvent(LogEvent{Level: 1}))
e = append(e, stream.NewEvent(LogEvent{Level: 1}))
e = append(e, stream.NewEvent(LogEvent{Level: 2}))
e = append(e, stream.NewEvent(LogEvent{Level: 2}))
e = append(e, stream.NewEvent(LogEvent{Level: 2}))
e = append(e, stream.NewEvent(LogEvent{Level: 2}))
d := &stream.Distinct{Name: "Level"}
out := d.Apply(e)
fmt.Println(len(out))
}
Output: 3
type Event ¶
type LargerThan ¶
func (LargerThan) Apply ¶
func (w LargerThan) Apply(input any) bool
func (LargerThan) String ¶
func (w LargerThan) String() string
type LengthBatch ¶
func (*LengthBatch) Apply ¶
func (w *LengthBatch) Apply(e []Event) []Event
func (*LengthBatch) String ¶
func (w *LengthBatch) String() string
type Max ¶
type Max struct {
Name string
}
Example ¶
package main
import (
"fmt"
"github.com/itsubaki/gostream/stream"
)
func main() {
type LogEvent struct {
Level int
}
e := make([]stream.Event, 0)
for i := 0; i < 10; i++ {
e = append(e, stream.NewEvent(LogEvent{
Level: i,
}))
}
m := &stream.Max{Name: "Level"}
out := m.Apply(e)
fmt.Println(out[len(out)-1].ResultSet)
}
Output: [9]
type Min ¶
type Min struct {
Name string
}
Example ¶
package main
import (
"fmt"
"github.com/itsubaki/gostream/stream"
)
func main() {
type LogEvent struct {
Level int
}
e := make([]stream.Event, 0)
for i := 0; i < 10; i++ {
e = append(e, stream.NewEvent(LogEvent{
Level: i,
}))
}
m := &stream.Min{Name: "Level"}
out := m.Apply(e)
fmt.Println(out[len(out)-1].ResultSet)
}
Output: [0]
type OrderBy ¶
Example ¶
package main
import (
"fmt"
"github.com/itsubaki/gostream/stream"
)
func main() {
type LogEvent struct {
Level int
}
e := make([]stream.Event, 0)
for i := 0; i < 10; i++ {
e = append(e, stream.NewEvent(LogEvent{
Level: i,
}))
}
o := &stream.OrderBy{
Name: "Level",
Index: 0,
Desc: false,
}
out := o.Apply(e)
for _, ev := range out {
fmt.Print(ev.Underlying)
}
}
Output: {0}{1}{2}{3}{4}{5}{6}{7}{8}{9}
Example (Desc) ¶
package main
import (
"fmt"
"github.com/itsubaki/gostream/stream"
)
func main() {
type LogEvent struct {
Level int
}
o := &stream.OrderBy{
Name: "Level",
Index: 0,
Desc: true,
}
e := make([]stream.Event, 0)
for i := 0; i < 10; i++ {
e = append(e, stream.NewEvent(LogEvent{
Level: i,
}))
}
out := o.Apply(e)
for _, ev := range out {
fmt.Print(ev.Underlying)
}
}
Output: {9}{8}{7}{6}{5}{4}{3}{2}{1}{0}
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Example ¶
package main
import (
"fmt"
"time"
"github.com/itsubaki/gostream/stream"
)
func main() {
type LogEvent struct {
Time time.Time
Level int
Message string
}
s := stream.New().
SelectAll().
From(LogEvent{}).
Length(10).
OrderBy("Level", true).
Limit(10, 5)
fmt.Println(s)
}
Output: SELECT * FROM LogEvent.LENGTH(10) ORDER BY Level DESC LIMIT 10 OFFSET 5
func (*Stream) LengthBatch ¶
type Sum ¶
type Sum struct {
Name string
}
Example ¶
package main
import (
"fmt"
"github.com/itsubaki/gostream/stream"
)
func main() {
type LogEvent struct {
Level int
}
e := make([]stream.Event, 0)
for i := 0; i < 10; i++ {
e = append(e, stream.NewEvent(LogEvent{
Level: i,
}))
}
s := &stream.Sum{Name: "Level"}
out := s.Apply(e)
fmt.Println(out[len(out)-1].ResultSet)
}
Output: [45]
Click to show internal directories.
Click to hide internal directories.