aggfuncs

package
v0.0.0-...-503c688 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2023 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefUint32Size is the size of uint32
	DefUint32Size = int64(unsafe.Sizeof(uint32(0)))
	// DefUint64Size is the size of uint64
	DefUint64Size = int64(unsafe.Sizeof(uint64(0)))
	// DefInt64Size is the size of int64
	DefInt64Size = int64(unsafe.Sizeof(int64(0)))
	// DefFloat64Size is the size of float64
	DefFloat64Size = int64(unsafe.Sizeof(float64(0)))
	// DefTimeSize is the size of time
	DefTimeSize = int64(unsafe.Sizeof(types.Time{}))
	// DefRowSize is the size of row
	DefRowSize = int64(unsafe.Sizeof(chunk.Row{}))
	// DefBoolSize is the size of bool
	DefBoolSize = int64(unsafe.Sizeof(false))
	// DefInterfaceSize is the size of interface
	DefInterfaceSize = int64(16)
	// DefMyDecimalSize is the size of MyDecimal
	DefMyDecimalSize = int64(unsafe.Sizeof(types.MyDecimal{}))
	// DefDurationSize is the size of duration
	DefDurationSize = int64(unsafe.Sizeof(types.Duration{}))
)
View Source
const (
	// DefPartialResult4AvgDecimalSize is the size of partialResult4AvgDecimal
	DefPartialResult4AvgDecimalSize = int64(unsafe.Sizeof(partialResult4AvgDecimal{}))
	// DefPartialResult4AvgDistinctDecimalSize is the size of partialResult4AvgDistinctDecimal
	DefPartialResult4AvgDistinctDecimalSize = int64(unsafe.Sizeof(partialResult4AvgDistinctDecimal{}))
	// DefPartialResult4AvgFloat64Size is the size of partialResult4AvgFloat64
	DefPartialResult4AvgFloat64Size = int64(unsafe.Sizeof(partialResult4AvgFloat64{}))
	// DefPartialResult4AvgDistinctFloat64Size is the size of partialResult4AvgDistinctFloat64
	DefPartialResult4AvgDistinctFloat64Size = int64(unsafe.Sizeof(partialResult4AvgDistinctFloat64{}))
)
View Source
const (
	// DefPartialResult4CountDistinctIntSize is the size of partialResult4CountDistinctInt
	DefPartialResult4CountDistinctIntSize = int64(unsafe.Sizeof(partialResult4CountDistinctInt{}))
	// DefPartialResult4CountDistinctRealSize is the size of partialResult4CountDistinctReal
	DefPartialResult4CountDistinctRealSize = int64(unsafe.Sizeof(partialResult4CountDistinctReal{}))
	// DefPartialResult4CountDistinctDecimalSize is the size of partialResult4CountDistinctDecimal
	DefPartialResult4CountDistinctDecimalSize = int64(unsafe.Sizeof(partialResult4CountDistinctDecimal{}))
	// DefPartialResult4CountDistinctDurationSize is the size of partialResult4CountDistinctDuration
	DefPartialResult4CountDistinctDurationSize = int64(unsafe.Sizeof(partialResult4CountDistinctDuration{}))
	// DefPartialResult4CountDistinctStringSize is the size of partialResult4CountDistinctString
	DefPartialResult4CountDistinctStringSize = int64(unsafe.Sizeof(partialResult4CountDistinctString{}))
	// DefPartialResult4CountWithDistinctSize is the size of partialResult4CountWithDistinct
	DefPartialResult4CountWithDistinctSize = int64(unsafe.Sizeof(partialResult4CountWithDistinct{}))
	// DefPartialResult4ApproxCountDistinctSize is the size of partialResult4ApproxCountDistinct
	DefPartialResult4ApproxCountDistinctSize = int64(unsafe.Sizeof(partialResult4ApproxCountDistinct{}))
)
View Source
const (
	// DefPartialResult4FirstRowIntSize is the size of partialResult4FirstRowInt
	DefPartialResult4FirstRowIntSize = int64(unsafe.Sizeof(partialResult4FirstRowInt{}))
	// DefPartialResult4FirstRowFloat32Size is the size of partialResult4FirstRowFloat32
	DefPartialResult4FirstRowFloat32Size = int64(unsafe.Sizeof(partialResult4FirstRowFloat32{}))
	// DefPartialResult4FirstRowFloat64Size is the size of partialResult4FirstRowFloat64
	DefPartialResult4FirstRowFloat64Size = int64(unsafe.Sizeof(partialResult4FirstRowFloat64{}))
	// DefPartialResult4FirstRowStringSize is the size of partialResult4FirstRowString
	DefPartialResult4FirstRowStringSize = int64(unsafe.Sizeof(partialResult4FirstRowString{}))
	// DefPartialResult4FirstRowTimeSize is the size of partialResult4FirstRowTime
	DefPartialResult4FirstRowTimeSize = int64(unsafe.Sizeof(partialResult4FirstRowTime{}))
	// DefPartialResult4FirstRowDurationSize is the size of partialResult4FirstRowDuration
	DefPartialResult4FirstRowDurationSize = int64(unsafe.Sizeof(partialResult4FirstRowDuration{}))
	// DefPartialResult4FirstRowJSONSize is the size of partialResult4FirstRowJSON
	DefPartialResult4FirstRowJSONSize = int64(unsafe.Sizeof(partialResult4FirstRowJSON{}))
	// DefPartialResult4FirstRowDecimalSize is the size of partialResult4FirstRowDecimal
	DefPartialResult4FirstRowDecimalSize = int64(unsafe.Sizeof(partialResult4FirstRowDecimal{}))
	// DefPartialResult4FirstRowEnumSize is the size of partialResult4FirstRowEnum
	DefPartialResult4FirstRowEnumSize = int64(unsafe.Sizeof(partialResult4FirstRowEnum{}))
	// DefPartialResult4FirstRowSetSize is the size of partialResult4FirstRowSet
	DefPartialResult4FirstRowSetSize = int64(unsafe.Sizeof(partialResult4FirstRowSet{}))
)
View Source
const (
	// DefPartialResult4GroupConcatSize is the size of partialResult4GroupConcat
	DefPartialResult4GroupConcatSize = int64(unsafe.Sizeof(partialResult4GroupConcat{}))
	// DefPartialResult4GroupConcatDistinctSize is the size of partialResult4GroupConcatDistinct
	DefPartialResult4GroupConcatDistinctSize = int64(unsafe.Sizeof(partialResult4GroupConcatDistinct{}))
	// DefPartialResult4GroupConcatOrderSize is the size of partialResult4GroupConcatOrder
	DefPartialResult4GroupConcatOrderSize = int64(unsafe.Sizeof(partialResult4GroupConcatOrder{}))
	// DefPartialResult4GroupConcatOrderDistinctSize is the size of partialResult4GroupConcatOrderDistinct
	DefPartialResult4GroupConcatOrderDistinctSize = int64(unsafe.Sizeof(partialResult4GroupConcatOrderDistinct{}))

	// DefBytesBufferSize is the size of bytes.Buffer.
	DefBytesBufferSize = int64(unsafe.Sizeof(bytes.Buffer{}))
	// DefTopNRowsSize is the size of topNRows.
	DefTopNRowsSize = int64(unsafe.Sizeof(topNRows{}))
)
View Source
const (
	// DefPartialResult4MaxMinIntSize is the size of partialResult4MaxMinInt
	DefPartialResult4MaxMinIntSize = int64(unsafe.Sizeof(partialResult4MaxMinInt{}))
	// DefPartialResult4MaxMinUintSize is the size of partialResult4MaxMinUint
	DefPartialResult4MaxMinUintSize = int64(unsafe.Sizeof(partialResult4MaxMinUint{}))
	// DefPartialResult4MaxMinDecimalSize is the size of partialResult4MaxMinDecimal
	DefPartialResult4MaxMinDecimalSize = int64(unsafe.Sizeof(partialResult4MaxMinDecimal{}))
	// DefPartialResult4MaxMinFloat32Size is the size of partialResult4MaxMinFloat32
	DefPartialResult4MaxMinFloat32Size = int64(unsafe.Sizeof(partialResult4MaxMinFloat32{}))
	// DefPartialResult4MaxMinFloat64Size is the size of partialResult4MaxMinFloat64
	DefPartialResult4MaxMinFloat64Size = int64(unsafe.Sizeof(partialResult4MaxMinFloat64{}))
	// DefPartialResult4MaxMinTimeSize is the size of partialResult4MaxMinTime
	DefPartialResult4MaxMinTimeSize = int64(unsafe.Sizeof(partialResult4MaxMinTime{}))
	// DefPartialResult4MaxMinDurationSize is the size of partialResult4MaxMinDuration
	DefPartialResult4MaxMinDurationSize = int64(unsafe.Sizeof(partialResult4MaxMinDuration{}))
	// DefPartialResult4MaxMinStringSize is the size of partialResult4MaxMinString
	DefPartialResult4MaxMinStringSize = int64(unsafe.Sizeof(partialResult4MaxMinString{}))
	// DefPartialResult4MaxMinJSONSize is the size of partialResult4MaxMinJSON
	DefPartialResult4MaxMinJSONSize = int64(unsafe.Sizeof(partialResult4MaxMinJSON{}))
	// DefPartialResult4MaxMinEnumSize is the size of partialResult4MaxMinEnum
	DefPartialResult4MaxMinEnumSize = int64(unsafe.Sizeof(partialResult4MaxMinEnum{}))
	// DefPartialResult4MaxMinSetSize is the size of partialResult4MaxMinSet
	DefPartialResult4MaxMinSetSize = int64(unsafe.Sizeof(partialResult4MaxMinSet{}))
	// DefMaxMinDequeSize is the size of maxMinHeap
	DefMaxMinDequeSize = int64(unsafe.Sizeof(MinMaxDeque{}))
)
View Source
const (
	// DefPartialResult4SumFloat64Size is the size of partialResult4SumFloat64
	DefPartialResult4SumFloat64Size = int64(unsafe.Sizeof(partialResult4SumFloat64{}))
	// DefPartialResult4SumDecimalSize is the size of partialResult4SumDecimal
	DefPartialResult4SumDecimalSize = int64(unsafe.Sizeof(partialResult4SumDecimal{}))
	// DefPartialResult4SumDistinctFloat64Size is the size of partialResult4SumDistinctFloat64
	DefPartialResult4SumDistinctFloat64Size = int64(unsafe.Sizeof(partialResult4SumDistinctFloat64{}))
	// DefPartialResult4SumDistinctDecimalSize is the size of partialResult4SumDistinctDecimal
	DefPartialResult4SumDistinctDecimalSize = int64(unsafe.Sizeof(partialResult4SumDistinctDecimal{}))
)
View Source
const (
	// DefPartialResult4FirstValueSize is the size of partialResult4FirstValue
	DefPartialResult4FirstValueSize = int64(unsafe.Sizeof(partialResult4FirstValue{}))
	// DefPartialResult4LastValueSize is the size of partialResult4LastValue
	DefPartialResult4LastValueSize = int64(unsafe.Sizeof(partialResult4LastValue{}))
	// DefPartialResult4NthValueSize is the size of partialResult4NthValue
	DefPartialResult4NthValueSize = int64(unsafe.Sizeof(partialResult4NthValue{}))

	// DefValue4IntSize is the size of value4Int
	DefValue4IntSize = int64(unsafe.Sizeof(value4Int{}))
	// DefValue4Float32Size is the size of value4Float32
	DefValue4Float32Size = int64(unsafe.Sizeof(value4Float32{}))
	// DefValue4Float64Size is the size of value4Float64
	DefValue4Float64Size = int64(unsafe.Sizeof(value4Float64{}))
	// DefValue4DecimalSize is the size of value4Decimal
	DefValue4DecimalSize = int64(unsafe.Sizeof(value4Decimal{}))
	// DefValue4TimeSize is the size of value4Time
	DefValue4TimeSize = int64(unsafe.Sizeof(value4Time{}))
	// DefValue4DurationSize is the size of value4Duration
	DefValue4DurationSize = int64(unsafe.Sizeof(value4Duration{}))
	// DefValue4StringSize is the size of value4String
	DefValue4StringSize = int64(unsafe.Sizeof(value4String{}))
	// DefValue4JSONSize is the size of value4JSON
	DefValue4JSONSize = int64(unsafe.Sizeof(value4JSON{}))
)
View Source
const (
	// DefPartialResult4VarPopFloat64Size is the size of partialResult4VarPopFloat64
	DefPartialResult4VarPopFloat64Size = int64(unsafe.Sizeof(partialResult4VarPopFloat64{}))
	// DefPartialResult4VarPopDistinctFloat64Size is the size of partialResult4VarPopDistinctFloat64
	DefPartialResult4VarPopDistinctFloat64Size = int64(unsafe.Sizeof(partialResult4VarPopDistinctFloat64{}))
)
View Source
const (
	// DefPartialResult4BitFuncSize the size of partialResult4BitFunc
	DefPartialResult4BitFuncSize = int64(unsafe.Sizeof(partialResult4BitFunc(0)))
)
View Source
const (
	// DefPartialResult4CountSize is the size of partialResult4Count
	DefPartialResult4CountSize = int64(unsafe.Sizeof(partialResult4Count(0)))
)
View Source
const (
	// DefPartialResult4CumeDistSize is the size of partialResult4CumeDist
	DefPartialResult4CumeDistSize = int64(unsafe.Sizeof(partialResult4CumeDist{}))
)
View Source
const (
	// DefPartialResult4JsonArrayagg is the size of partialResult4JsonArrayagg
	DefPartialResult4JsonArrayagg = int64(unsafe.Sizeof(partialResult4JsonArrayagg{}))
)
View Source
const (
	// DefPartialResult4JsonObjectAgg is the size of partialResult4JsonObject
	DefPartialResult4JsonObjectAgg = int64(unsafe.Sizeof(partialResult4JsonObjectAgg{}))
)
View Source
const (
	// DefPartialResult4LeadLagSize is the size of partialResult4LeadLag
	DefPartialResult4LeadLagSize = int64(unsafe.Sizeof(partialResult4LeadLag{}))
)
View Source
const (
	// DefPartialResult4Ntile is the size of partialResult4Ntile
	DefPartialResult4Ntile = int64(unsafe.Sizeof(partialResult4Ntile{}))
)
View Source
const (
	// DefPartialResult4RankSize is the size of partialResult4Rank
	DefPartialResult4RankSize = int64(unsafe.Sizeof(partialResult4Rank{}))
)
View Source
const (
	// DefPartialResult4RowNumberSize is the size of partialResult4RowNumberSize
	DefPartialResult4RowNumberSize = int64(unsafe.Sizeof(partialResult4RowNumber{}))
)
View Source
const (
	// DefSliceSize represents size of an empty Slice
	DefSliceSize = int64(unsafe.Sizeof([]interface{}{}))
)

Variables

This section is empty.

Functions

func GetDatumMemSize

func GetDatumMemSize(d *types.Datum) int64

GetDatumMemSize calculates the memory size of each types.Datum in sortRow.byItems. types.Datum memory size = variable type's memory size + variable value's memory size.

func NewPartialResult4ApproxCountDistinct

func NewPartialResult4ApproxCountDistinct() *partialResult4ApproxCountDistinct

NewPartialResult4ApproxCountDistinct builds a partial result for agg function ApproxCountDistinct.

func WriteTime

func WriteTime(buf []byte, t types.Time)

WriteTime writes `t` into `buf`.

Types

type AggFunc

type AggFunc interface {
	// AllocPartialResult allocates a specific data structure to store the
	// partial result, initializes it, and converts it to PartialResult to
	// return back. The second returned value is the memDelta used to trace
	// memory usage. Aggregate operator implementation, no matter it's a hash
	// or stream, should hold this allocated PartialResult for the further
	// operations like: "ResetPartialResult", "UpdatePartialResult".
	AllocPartialResult() (pr PartialResult, memDelta int64)

	// ResetPartialResult resets the partial result to the original state for a
	// specific aggregate function. It converts the input PartialResult to the
	// specific data structure which stores the partial result and then reset
	// every field to the proper original state.
	ResetPartialResult(pr PartialResult)

	// UpdatePartialResult updates the specific partial result for an aggregate
	// function using the input rows which all belonging to the same data group.
	// It converts the PartialResult to the specific data structure which stores
	// the partial result and then iterates on the input rows and update that
	// partial result according to the functionality and the state of the
	// aggregate function. The returned value is the memDelta used to trace memory
	// usage.
	UpdatePartialResult(sctx sessionctx.Context, rowsInGroup []chunk.Row, pr PartialResult) (memDelta int64, err error)

	// MergePartialResult will be called in the final phase when parallelly
	// executing. It converts the PartialResult `src`, `dst` to the same specific
	// data structure which stores the partial results, and then evaluate the
	// final result using the partial results as input values. The returned value
	// is the memDelta used to trace memory usage.
	MergePartialResult(sctx sessionctx.Context, src, dst PartialResult) (memDelta int64, err error)

	// AppendFinalResult2Chunk finalizes the partial result and append the
	// final result to the input chunk. Like other operations, it converts the
	// input PartialResult to the specific data structure which stores the
	// partial result and then calculates the final result and append that
	// final result to the chunk provided.
	AppendFinalResult2Chunk(sctx sessionctx.Context, pr PartialResult, chk *chunk.Chunk) error
}

AggFunc is the interface to evaluate the aggregate functions.

func Build

func Build(ctx sessionctx.Context, aggFuncDesc *aggregation.AggFuncDesc, ordinal int) AggFunc

Build is used to build a specific AggFunc implementation according to the input aggFuncDesc.

func BuildWindowFunctions

func BuildWindowFunctions(ctx sessionctx.Context, windowFuncDesc *aggregation.AggFuncDesc, ordinal int, orderByCols []*expression.Column) AggFunc

BuildWindowFunctions builds specific window function according to function description and order by columns.

type MaxMinSlidingWindowAggFunc

type MaxMinSlidingWindowAggFunc interface {
	// SetWindowStart sets the start position of window
	SetWindowStart(start uint64)
}

MaxMinSlidingWindowAggFunc is the interface to evaluate the max/min agg function using sliding window

type MinMaxDeque

type MinMaxDeque struct {
	Items []Pair
	IsMax bool
	// contains filtered or unexported fields
}

MinMaxDeque is an array based double end queue

func NewDeque

func NewDeque(isMax bool, cmpFunc func(i, j interface{}) int) *MinMaxDeque

NewDeque inits a new MinMaxDeque

func (*MinMaxDeque) Back

func (d *MinMaxDeque) Back() (Pair, bool)

Back returns the element at the end of MinMaxDeque, and whether reached end of deque

func (*MinMaxDeque) Dequeue

func (d *MinMaxDeque) Dequeue(boundary uint64) error

Dequeue pops out element from the front, if element's index is out of boundary, i.e. the leftmost element index

func (*MinMaxDeque) Enqueue

func (d *MinMaxDeque) Enqueue(idx uint64, item interface{}) error

Enqueue put Item at the back of queue, while popping any element that is lesser element in queue

func (*MinMaxDeque) Front

func (d *MinMaxDeque) Front() (Pair, bool)

Front returns the element at the front of MinMaxDeque, and whether reached end of deque

func (*MinMaxDeque) IsEmpty

func (d *MinMaxDeque) IsEmpty() bool

IsEmpty returns if MinMaxDeque is empty

func (*MinMaxDeque) PopBack

func (d *MinMaxDeque) PopBack() error

PopBack pops an Item from the end of MinMaxDeque

func (*MinMaxDeque) PopFront

func (d *MinMaxDeque) PopFront() error

PopFront pops an Item from the front of MinMaxDeque

func (*MinMaxDeque) PushBack

func (d *MinMaxDeque) PushBack(idx uint64, item interface{})

PushBack pushes Idx and Item(wrapped in Pair) to the end of MinMaxDeque

func (*MinMaxDeque) Reset

func (d *MinMaxDeque) Reset()

Reset resets the deque for a MaxMinSlidingWindowAggFunc

type Pair

type Pair struct {
	Item interface{}
	Idx  uint64
}

Pair pairs items and their indices in MinMaxDeque

type PartialResult

type PartialResult unsafe.Pointer

PartialResult represents data structure to store the partial result for the aggregate functions. Here we use unsafe.Pointer to allow the partial result to be any type.

type SlidingWindowAggFunc

type SlidingWindowAggFunc interface {
	// Slide evaluates the aggregate functions using a sliding window. The input
	// lastStart and lastEnd are the interval of the former sliding window,
	// shiftStart, shiftEnd mean the sliding window offset. Note that the input
	// PartialResult stores the intermediate result which will be used in the next
	// sliding window, ensure call ResetPartialResult after a frame are evaluated
	// completely.
	Slide(sctx sessionctx.Context, getRow func(uint64) chunk.Row, lastStart, lastEnd uint64, shiftStart, shiftEnd uint64, pr PartialResult) error
}

SlidingWindowAggFunc is the interface to evaluate the aggregate functions using sliding window.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL