octosql: github.com/cube2222/octosql/execution/aggregates Index | Files

package aggregates

import "github.com/cube2222/octosql/execution/aggregates"

Index

Package Files

avg.go count.go distinct.go first.go key.go last.go max.go min.go sum.go table.go

Variables

var AggregateTable = map[string]execution.AggregatePrototype{
    "count":          func() execution.Aggregate { return NewCountAggregate() },
    "sum":            func() execution.Aggregate { return NewSumAggregate() },
    "avg":            func() execution.Aggregate { return NewAverageAggregate() },
    "min":            func() execution.Aggregate { return NewMinAggregate() },
    "max":            func() execution.Aggregate { return NewMaxAggregate() },
    "sum_distinct":   func() execution.Aggregate { return NewDistinctAggregate(NewSumAggregate()) },
    "count_distinct": func() execution.Aggregate { return NewDistinctAggregate(NewCountAggregate()) },
    "avg_distinct":   func() execution.Aggregate { return NewDistinctAggregate(NewAverageAggregate()) },
    "first":          func() execution.Aggregate { return NewFirstAggregate() },
    "last":           func() execution.Aggregate { return NewLastAggregate() },
    "key":            func() execution.Aggregate { return NewKeyAggregate() },
}

type Average Uses

type Average struct {
    // contains filtered or unexported fields
}

func NewAverageAggregate Uses

func NewAverageAggregate() *Average

func (*Average) AddValue Uses

func (agg *Average) AddValue(ctx context.Context, tx storage.StateTransaction, value octosql.Value) error

func (*Average) GetValue Uses

func (agg *Average) GetValue(ctx context.Context, tx storage.StateTransaction) (octosql.Value, error)

func (*Average) RetractValue Uses

func (agg *Average) RetractValue(ctx context.Context, tx storage.StateTransaction, value octosql.Value) error

func (*Average) String Uses

func (agg *Average) String() string

type Count Uses

type Count struct {
}

func NewCountAggregate Uses

func NewCountAggregate() *Count

func (*Count) AddValue Uses

func (agg *Count) AddValue(ctx context.Context, tx storage.StateTransaction, value octosql.Value) error

func (*Count) GetValue Uses

func (agg *Count) GetValue(ctx context.Context, tx storage.StateTransaction) (octosql.Value, error)

func (*Count) RetractValue Uses

func (agg *Count) RetractValue(ctx context.Context, tx storage.StateTransaction, value octosql.Value) error

func (*Count) String Uses

func (agg *Count) String() string

type Distinct Uses

type Distinct struct {
    // contains filtered or unexported fields
}

func NewDistinctAggregate Uses

func NewDistinctAggregate(aggr execution.Aggregate) *Distinct

func (*Distinct) AddValue Uses

func (agg *Distinct) AddValue(ctx context.Context, tx storage.StateTransaction, value octosql.Value) error

func (*Distinct) GetValue Uses

func (agg *Distinct) GetValue(ctx context.Context, tx storage.StateTransaction) (octosql.Value, error)

func (*Distinct) RetractValue Uses

func (agg *Distinct) RetractValue(ctx context.Context, tx storage.StateTransaction, value octosql.Value) error

func (*Distinct) String Uses

func (agg *Distinct) String() string

type First Uses

type First struct {
}

func NewFirstAggregate Uses

func NewFirstAggregate() *First

func (*First) AddValue Uses

func (agg *First) AddValue(ctx context.Context, tx storage.StateTransaction, value octosql.Value) error

First storage contains Deque for actual order of elements added and Map for storing counts of every element. Once the element is added, we PushBack it into the Deque (because it is the last one to pick as 'first' in order). Above that, we increment its count in Map.

func (*First) GetValue Uses

func (agg *First) GetValue(ctx context.Context, tx storage.StateTransaction) (octosql.Value, error)

Now the only think we need to do is PopFront ('front' because together with PushBack it creates a queue structure) first element which has positive count value (which means it wasn't fully retracted). If the front element doesn't have positive count, we need to 'forget' about its existence (as is described above RetractValue method), so we just Pop it.

func (*First) RetractValue Uses

func (agg *First) RetractValue(ctx context.Context, tx storage.StateTransaction, value octosql.Value) error

Now, once the element is retracted we don't know its current position in Deque, so the only thing we can do is decrement its count value in Map (if it reaches 0, we will Pop it from deque during GetValue and don't bother)

func (*First) String Uses

func (agg *First) String() string

type Key Uses

type Key struct {
}

func NewKeyAggregate Uses

func NewKeyAggregate() *Key

func (*Key) AddValue Uses

func (agg *Key) AddValue(ctx context.Context, tx storage.StateTransaction, value octosql.Value) error

func (*Key) GetValue Uses

func (agg *Key) GetValue(ctx context.Context, tx storage.StateTransaction) (octosql.Value, error)

func (*Key) RetractValue Uses

func (agg *Key) RetractValue(ctx context.Context, tx storage.StateTransaction, value octosql.Value) error

func (*Key) String Uses

func (agg *Key) String() string

type Last Uses

type Last struct {
}

func NewLastAggregate Uses

func NewLastAggregate() *Last

func (*Last) AddValue Uses

func (agg *Last) AddValue(ctx context.Context, tx storage.StateTransaction, value octosql.Value) error

Last storage contains Deque for actual order of elements added and Map for storing counts of every element. Once the element is added, we PushFront it into the Deque (because it is the first one to pick as 'last' in order). Above that, we increment its count in Map.

func (*Last) GetValue Uses

func (agg *Last) GetValue(ctx context.Context, tx storage.StateTransaction) (octosql.Value, error)

Now the only think we need to do is PopFront ('front' because together with PushFront it creates a stack structure) first element which has positive count value (which means it wasn't fully retracted). If the front element doesn't have positive count, we need to 'forget' about its existence (as is described above RetractValue method), so we just Pop it.

func (*Last) RetractValue Uses

func (agg *Last) RetractValue(ctx context.Context, tx storage.StateTransaction, value octosql.Value) error

Now, once the element is retracted we don't know its current position in Deque, so the only thing we can do is decrement its count value in Map (if it reaches 0, we will Pop it from deque during GetValue and don't bother)

func (*Last) String Uses

func (agg *Last) String() string

type Max Uses

type Max struct {
}

func NewMaxAggregate Uses

func NewMaxAggregate() *Max

func (*Max) AddValue Uses

func (agg *Max) AddValue(ctx context.Context, tx storage.StateTransaction, value octosql.Value) error

func (*Max) GetValue Uses

func (agg *Max) GetValue(ctx context.Context, tx storage.StateTransaction) (octosql.Value, error)

func (*Max) RetractValue Uses

func (agg *Max) RetractValue(ctx context.Context, tx storage.StateTransaction, value octosql.Value) error

func (*Max) String Uses

func (agg *Max) String() string

type Min Uses

type Min struct {
}

func NewMinAggregate Uses

func NewMinAggregate() *Min

func (*Min) AddValue Uses

func (agg *Min) AddValue(ctx context.Context, tx storage.StateTransaction, value octosql.Value) error

func (*Min) GetValue Uses

func (agg *Min) GetValue(ctx context.Context, tx storage.StateTransaction) (octosql.Value, error)

func (*Min) RetractValue Uses

func (agg *Min) RetractValue(ctx context.Context, tx storage.StateTransaction, value octosql.Value) error

func (*Min) String Uses

func (agg *Min) String() string

type Sum Uses

type Sum struct {
}

func NewSumAggregate Uses

func NewSumAggregate() *Sum

func (*Sum) AddValue Uses

func (agg *Sum) AddValue(ctx context.Context, tx storage.StateTransaction, value octosql.Value) error

func (*Sum) GetValue Uses

func (agg *Sum) GetValue(ctx context.Context, tx storage.StateTransaction) (octosql.Value, error)

func (*Sum) RetractValue Uses

func (agg *Sum) RetractValue(ctx context.Context, tx storage.StateTransaction, value octosql.Value) error

func (*Sum) String Uses

func (agg *Sum) String() string

Package aggregates imports 7 packages (graph) and is imported by 1 packages. Updated 2020-07-13. Refresh now. Tools for package owners.