Documentation
¶
Index ¶
- Constants
- Variables
- func ExecuteFunction(name string, v any) (any, error)
- func IsRegisteredFunction(name string) bool
- func NewStringFunctionWith(name string, t StringFunc, opts ...ExecutorOption) *stringFunction
- func NewTimeFunctionWith(name string, t TimeFunc, opts ...ExecutorOption) *timeFunction
- func RegisteredFunctionNames() []string
- func WithColumns(columns []string) resultSetOption
- func WithRows(rows []Row) resultSetOption
- type AggrAggregateFunc
- type AggrFinalizeFunc
- type AggrResetFunc
- type Aggregator
- type AggregatorOption
- type AggregatorSet
- type Argument
- type Arguments
- type ArithFunc
- type Avg
- func (aggr Avg) Aggregate(v any) error
- func (aggr Avg) AggregateMap(m map[string]any) error
- func (aggr Avg) AggregateRow(row []any) error
- func (aggr Avg) Arguments() []string
- func (aggr Avg) Finalize() (ResultSet, error)
- func (aggr Avg) GroupBy() (string, bool)
- func (aggr Avg) Name() string
- func (aggr Avg) Reset(opts ...any) error
- func (aggrImpl Avg) Type() FunctionType
- type AvgOption
- type CastFunc
- type Count
- func (aggr Count) Aggregate(v any) error
- func (aggr Count) AggregateMap(m map[string]any) error
- func (aggr Count) AggregateRow(row []any) error
- func (aggr Count) Arguments() []string
- func (aggr Count) Finalize() (ResultSet, error)
- func (aggr Count) GroupBy() (string, bool)
- func (aggr Count) Name() string
- func (aggr Count) Reset(opts ...any) error
- func (aggrImpl Count) Type() FunctionType
- type CountOption
- type Executor
- func NewAbs(opts ...ExecutorOption) Executor
- func NewAddOperator(opts ...ExecutorOption) Executor
- func NewArithFunctionWith(name string, arithFn ArithFunc, opts ...ExecutorOption) Executor
- func NewArithOperatorFor(ope string, opts ...ExecutorOption) (Executor, error)
- func NewCastFunctionWith(name string, castFn CastFunc) Executor
- func NewCeil(opts ...ExecutorOption) Executor
- func NewCos(opts ...ExecutorOption) Executor
- func NewCurrentTimestamp(opts ...ExecutorOption) Executor
- func NewDivOperator(opts ...ExecutorOption) Executor
- func NewExecutorForName(name string, opts ...ExecutorOption) (Executor, error)
- func NewExp(opts ...ExecutorOption) Executor
- func NewFloor(opts ...ExecutorOption) Executor
- func NewLog(opts ...ExecutorOption) Executor
- func NewLog10(opts ...ExecutorOption) Executor
- func NewLower(opts ...ExecutorOption) Executor
- func NewMathFunctionWith(name string, mathFn MathFunc, opts ...ExecutorOption) Executor
- func NewMod(opts ...ExecutorOption) Executor
- func NewModOperator(opts ...ExecutorOption) Executor
- func NewMulOperator(opts ...ExecutorOption) Executor
- func NewNow(opts ...ExecutorOption) Executor
- func NewPI(opts ...ExecutorOption) Executor
- func NewPower(opts ...ExecutorOption) Executor
- func NewRand(opts ...ExecutorOption) Executor
- func NewRound(opts ...ExecutorOption) Executor
- func NewSin(opts ...ExecutorOption) Executor
- func NewSqrt(opts ...ExecutorOption) Executor
- func NewSubOperator(opts ...ExecutorOption) Executor
- func NewTan(opts ...ExecutorOption) Executor
- func NewTrim(opts ...ExecutorOption) Executor
- func NewUpper(opts ...ExecutorOption) Executor
- type ExecutorOption
- type Function
- type FunctionOption
- type FunctionType
- type GroupBy
- type Map
- type MathFunc
- type MathResultSet
- type Max
- func (aggr Max) Aggregate(v any) error
- func (aggr Max) AggregateMap(m map[string]any) error
- func (aggr Max) AggregateRow(row []any) error
- func (aggr Max) Arguments() []string
- func (aggr Max) Finalize() (ResultSet, error)
- func (aggr Max) GroupBy() (string, bool)
- func (aggr Max) Name() string
- func (aggr Max) Reset(opts ...any) error
- func (aggrImpl Max) Type() FunctionType
- type MaxOption
- type Min
- func (aggr Min) Aggregate(v any) error
- func (aggr Min) AggregateMap(m map[string]any) error
- func (aggr Min) AggregateRow(row []any) error
- func (aggr Min) Arguments() []string
- func (aggr Min) Finalize() (ResultSet, error)
- func (aggr Min) GroupBy() (string, bool)
- func (aggr Min) Name() string
- func (aggr Min) Reset(opts ...any) error
- func (aggrImpl Min) Type() FunctionType
- type MinOption
- type ResultSet
- type Row
- type SelectorHelper
- type StringFunc
- type Sum
- func (aggr Sum) Aggregate(v any) error
- func (aggr Sum) AggregateMap(m map[string]any) error
- func (aggr Sum) AggregateRow(row []any) error
- func (aggr Sum) Arguments() []string
- func (aggr Sum) Finalize() (ResultSet, error)
- func (aggr Sum) GroupBy() (string, bool)
- func (aggr Sum) Name() string
- func (aggr Sum) Reset(opts ...any) error
- func (aggrImpl Sum) Type() FunctionType
- type SumOption
- type TimeFunc
Constants ¶
const ( // Math. AbsFunctionName = "ABS" CeilFunctionName = "CEIL" FloorFunctionName = "FLOOR" RoundFunctionName = "ROUND" SqrtFunctionName = "SQRT" LogFunctionName = "LOG" Log10FunctionName = "LOG10" ExpFunctionName = "EXP" PowerFunctionName = "POWER" ModFunctionName = "MOD" SinFunctionName = "SIN" CosFunctionName = "COS" TanFunctionName = "TAN" RandFunctionName = "RAND" PiFunctionName = "PI" // String. UpperFunctionName = "UPPER" LowerFunctionName = "LOWER" TrimFunctionName = "TRIM" // Time. CurrentTimestampFunctionName = "CURRENT_TIMESTAMP" NowFunctionName = "NOW" // Aggregate. MaxFunctionName = "MAX" MinFunctionName = "MIN" SumFunctionName = "SUM" AvgFunctionName = "AVG" CountFunctionName = "COUNT" // Airthmetic. AddOperatorID = "+" SubOperatorID = "-" MulOperatorID = "*" DivOperatorID = "/" ModOperatorID = "%" )
const (
// Asterisk is a asterisk string.
Asterisk = "*"
)
Variables ¶
var ErrInvalid = errors.New("invalid")
ErrInvalid is returned when the value is invalid.
var ErrNegativeValue = errors.New("negative value")
ErrNegativeValue is returned when the value is negative.
var ErrNoData = errors.New("no data")
ErrNoData is returned when there is no data.
var ErrNotFound = errors.New("not found")
ErrNotFound is returned when the data type is invalid.
var ErrNotImplemented = errors.New("not implemented")
ErrNotImplemented is returned when the function is not implemented.
var ErrNotSupported = errors.New("not supported")
ErrNotSupported is returned when the function is not supported.
Functions ¶
func ExecuteFunction ¶
ExecuteFunction returns the executed value with the specified arguments.
func IsRegisteredFunction ¶
IsRegisteredFunctionNamePattern checks if the given name matches any registered function name pattern.
func NewStringFunctionWith ¶
func NewStringFunctionWith(name string, t StringFunc, opts ...ExecutorOption) *stringFunction
NewStringFunctionWith returns a new string function with the specified name and executor.
func NewTimeFunctionWith ¶
func NewTimeFunctionWith(name string, t TimeFunc, opts ...ExecutorOption) *timeFunction
NewTimeFunctionWith returns a new time function with the specified name and executor.
func RegisteredFunctionNames ¶
func RegisteredFunctionNames() []string
RegisteredFunctionNames returns a list of all registered function names.
func WithColumns ¶
func WithColumns(columns []string) resultSetOption
WithColumns sets the columns of the result set.
Types ¶
type AggrAggregateFunc ¶
type AggrAggregateFunc func(aggr *aggrImpl, accumulatedValue float64, inputValue float64) (float64, error)
AggrAggregateFunc is a function that performs aggregation on the given values.
type AggrFinalizeFunc ¶
type AggrFinalizeFunc func(aggr *aggrImpl, accumulatedValue float64, accumulatedCount int) (any, error)
AggrFinalizeFunc is a function that finalizes the aggregation and returns the result.
type AggrResetFunc ¶
AggrResetFunc is a function that resets the aggregation state.
type Aggregator ¶
type Aggregator interface {
// Name returns the name of the aggregator.
Name() string
// Type returns the type of the aggregator.
Type() FunctionType
// Argmuents returns the arguments of the aggregator.
Arguments() []string
// GroupBy returns the group by column name and whether it is a group by column.
GroupBy() (string, bool)
// Reset resets the aggregator to its initial state.
Reset(opts ...any) error
// Aggregate aggregates a map or an array. The map represents a row of data, and the array is a
// list of rows. If grouping is enabled, the array row must have a group value as the first element.
Aggregate(v any) error
// Finalize finalizes the aggregation and returns the result.
Finalize() (ResultSet, error)
}
Aggregator is an interface for aggregating data.
func NewAggregatorForName ¶
func NewAggregatorForName(name string, opts ...AggregatorOption) (Aggregator, error)
NewAggregator creates a new Aggregator with the given options.
type AggregatorOption ¶
type AggregatorOption = aggrOption
AggregatorOption is a function that configures the Aggregator.
func WithAggregatorArguments ¶
func WithAggregatorArguments(args []string) AggregatorOption
WithaggregatorArguments is an option to set the arguments for the aggregator.
func WithAggregatorGroupBy ¶
func WithAggregatorGroupBy(group string) AggregatorOption
WithAggregatorGroupBy is an option to set the group by clause for the aggregator.
func WithAggregatorName ¶
func WithAggregatorName(name string) AggregatorOption
WithAggregatorName is an option to set the name of the aggregator.
type AggregatorSet ¶
type AggregatorSet []Aggregator
AggregatorSet is a collection of Aggregators. It provides methods to manage and operate on multiple aggregators.
func NewAggregatorSetForNames ¶
func NewAggregatorSetForNames(names []string, opts ...aggrOption) (AggregatorSet, error)
NewAggregatorSetForNames creates a new AggregatorSet for the given names.
func NewAggregatorSetWith ¶
func NewAggregatorSetWith(aggrs []Aggregator) AggregatorSet
NewAggregatorSet creates a new AggregatorSet with the given aggregators.
func (*AggregatorSet) Aggregate ¶
func (aggrSet *AggregatorSet) Aggregate(v any) error
Aggregate aggregates a row of data using all aggregators in the set.
func (*AggregatorSet) Finalize ¶
func (aggrSet *AggregatorSet) Finalize() (ResultSet, error)
Finalize finalizes the aggregation and returns the result set.
func (*AggregatorSet) Reset ¶
func (aggrSet *AggregatorSet) Reset(opts ...any) error
Reset resets all aggregators in the set.
type Argument ¶
type Argument string
Argument represents am argument in a function.
func NewArgumentWith ¶
NewArgument returns a new argument instance from the specified string.
func (Argument) IsAsterisk ¶
IsAsterisk returns true whether the argument name is the asterisk.
type Arguments ¶
type Arguments []Argument
Arguments represens an argument array in a function.
func NewArgumentStrings ¶
NewArgumentStrings returns an argument array instance with the specified string arguments.
func NewArguments ¶
func NewArguments() Arguments
NewArguments returns an empty argument array instance.
func NewArgumentsWith ¶
NewArgumentsWith returns an argument array instance with the specified arguments.
func (Arguments) IsAsterisk ¶
IsAsterisk returns true if the argument list is an asterisk.
type Avg ¶
type Avg struct {
// contains filtered or unexported fields
}
Avg is an aggregator that calculates the average of values.
func (Avg) Aggregate ¶
Aggregate aggregates a map or an array. The map represents a row of data, and the array is a list of rows. If grouping is enabled, the array row must have a group value as the first element.
func (Avg) AggregateMap ¶
AggregateMap aggregates a map of data using the aggregator.
func (Avg) AggregateRow ¶
AggregateRow aggregates a row of data using the aggregator. The row is expected to be an array where the first element is the group value (if grouping is enabled),
func (Avg) Arguments ¶
func (aggr Avg) Arguments() []string
Arguments returns the arguments of the aggregator.
func (Avg) GroupBy ¶
GroupBy returns the group by column name and a boolean indicating if it is set.
type AvgOption ¶
type AvgOption = aggrOption
AvgOption is a function that configures the Avg aggregator.
func WithAvgArguments ¶
WithAvgArguments sets the arguments for the Avg aggregator.
func WithAvgGroupBy ¶
WithAvgGroupBy sets the group by column for the Avg aggregator.
type Count ¶
type Count struct {
// contains filtered or unexported fields
}
Count is an aggregator that calculates the sum of values.
func NewCount ¶
func NewCount(opts ...CountOption) (*Count, error)
NewCount creates a new Count aggregator with the given options.
func (Count) Aggregate ¶
Aggregate aggregates a map or an array. The map represents a row of data, and the array is a list of rows. If grouping is enabled, the array row must have a group value as the first element.
func (Count) AggregateMap ¶
AggregateMap aggregates a map of data using the aggregator.
func (Count) AggregateRow ¶
AggregateRow aggregates a row of data using the aggregator. The row is expected to be an array where the first element is the group value (if grouping is enabled),
func (Count) Arguments ¶
func (aggr Count) Arguments() []string
Arguments returns the arguments of the aggregator.
func (Count) GroupBy ¶
GroupBy returns the group by column name and a boolean indicating if it is set.
func (Count) Type ¶
func (aggrImpl Count) Type() FunctionType
Type returns the type of the aggregator.
type CountOption ¶
type CountOption = aggrOption
CountOption is a function that configures the Count aggregator.
func WithCountArguments ¶
func WithCountArguments(args []string) CountOption
WithCountArguments sets the arguments for the Count aggregator.
func WithCountGroupBy ¶
func WithCountGroupBy(group string) CountOption
WithCountGroupBy sets the group by column for the Count aggregator.
type Executor ¶
type Executor interface {
// Name returns the name of the function.
Name() string
// Type returns the type of the function.
Type() FunctionType
// Arguments returns the arguments of the executor.
Arguments() []string
// Execute returns the executed value with the specified arguments.
Execute(any) (any, error)
}
Executor represents a function executor interface.
func NewAddOperator ¶
func NewAddOperator(opts ...ExecutorOption) Executor
NewAddOperator returns a new add function.
func NewArithFunctionWith ¶
func NewArithFunctionWith(name string, arithFn ArithFunc, opts ...ExecutorOption) Executor
NewArithFunctionWith returns a new base arithmetic function with the specified name and arithmetic.
func NewArithOperatorFor ¶
func NewArithOperatorFor(ope string, opts ...ExecutorOption) (Executor, error)
NewArithOperatorFor returns a new arithmetic function with the given operator and implementation.
func NewCastFunctionWith ¶
NewCastFunctionWith returns a new base cast function with the specified name and cast.
func NewCurrentTimestamp ¶
func NewCurrentTimestamp(opts ...ExecutorOption) Executor
NewCurrentTimestamp returns a new current timestamp function.
func NewDivOperator ¶
func NewDivOperator(opts ...ExecutorOption) Executor
NewDivOperator returns a new division function.
func NewExecutorForName ¶
func NewExecutorForName(name string, opts ...ExecutorOption) (Executor, error)
NewExecutorForName returns a function executor with the specified name.
func NewFloor ¶
func NewFloor(opts ...ExecutorOption) Executor
NewFloor returns a new floor function.
func NewLog10 ¶
func NewLog10(opts ...ExecutorOption) Executor
NewLog10 returns a new log10 function.
func NewLower ¶
func NewLower(opts ...ExecutorOption) Executor
NewLowerFunctionWith returns a new string function with the specified name and executor.
func NewMathFunctionWith ¶
func NewMathFunctionWith(name string, mathFn MathFunc, opts ...ExecutorOption) Executor
NewMathFunctionWith returns a new base math function with the specified name and math.
func NewModOperator ¶
func NewModOperator(opts ...ExecutorOption) Executor
NewModOperator returns a new mod function.
func NewMulOperator ¶
func NewMulOperator(opts ...ExecutorOption) Executor
NewMulOperator returns a new multiple function.
func NewNow ¶
func NewNow(opts ...ExecutorOption) Executor
NewTimeFunctionWith returns a new time function with the specified name and executor.
func NewPI ¶
func NewPI(opts ...ExecutorOption) Executor
NewPI returns a new pi function that returns the value of π (pi).
func NewPower ¶
func NewPower(opts ...ExecutorOption) Executor
NewPower returns a new power function.
func NewRand ¶
func NewRand(opts ...ExecutorOption) Executor
NewRand returns a new rand function that generates a random float64 in [0.0, 1.0).
func NewRound ¶
func NewRound(opts ...ExecutorOption) Executor
NewRound returns a new round function.
func NewSubOperator ¶
func NewSubOperator(opts ...ExecutorOption) Executor
NewSubOperator returns a new sub function.
func NewTrim ¶
func NewTrim(opts ...ExecutorOption) Executor
NewTrimFunctionWith returns a new string function with the specified name and executor.
func NewUpper ¶
func NewUpper(opts ...ExecutorOption) Executor
NewUpperFunctionWith returns a new string function with the specified name and executor.
type ExecutorOption ¶
type ExecutorOption = execOption
ExecutorOption is an option for the function executor.
func WithExecutorArguments ¶
func WithExecutorArguments(args []string) ExecutorOption
WithExecutorArguments returns an option to set the arguments for the executor.
func WithExecutorName ¶
func WithExecutorName(name string) ExecutorOption
WithExecutorName returns an option to set the name of the executor.
type Function ¶
type Function interface {
// Name returns the function name.
Name() string
// IsName returns true whether the function name is the specified one.
IsName(string) bool
// Type returns the function type.
Type() FunctionType
// IsType returns true whether the function type is the specified one.
IsType(FunctionType) bool
// IsFunction returns true whether the function is a function.
IsFunction() bool
// Function returns the function if the function is a function.
Function() (Function, bool)
// Arguments returns the argument list.
Arguments() Arguments
// Executor returns the executor of the function.
Executor(opts ...ExecutorOption) (Executor, error)
// IsAggregator returns true if the function is an aggregator function.
IsAggregator() bool
// Aggregator returns the aggregator of the function.
Aggregator(opts ...AggregatorOption) (Aggregator, error)
// String returns a string representation of the function.
String() string
// SelectorHelper provides additional methods for selectors.
SelectorHelper
}
Function represents a .
func NewFunctionWith ¶
func NewFunctionWith(opts ...FunctionOption) Function
NewFunctionWith returns a function instance.
type FunctionOption ¶
type FunctionOption = func(*function)
FunctionOption represents a function option function.
func WithFunctionAggregator ¶
func WithFunctionAggregator(aggregator Aggregator) FunctionOption
WithFunctionAggregator sets the function aggregator.
func WithFunctionArguments ¶
func WithFunctionArguments(args ...Argument) FunctionOption
WithFunctionArguments sets the function arguments.
func WithFunctionExecutor ¶
func WithFunctionExecutor(executor Executor) FunctionOption
WithFunctionExecutor sets the function executor.
func WithFunctionName ¶
func WithFunctionName(name string) FunctionOption
WithFunctionName sets the function name.
func WithFunctionType ¶
func WithFunctionType(t FunctionType) FunctionOption
WithFunctionType sets the function type.
type FunctionType ¶
type FunctionType int
FunctionType represents a function type.
const ( UnknownFunctionType FunctionType = iota MathFunction AggregateFunction CastFunction ArithOperator TimeFunction StringFunction )
func NewFunctionTypeForName ¶
func NewFunctionTypeForName(name string) (FunctionType, error)
NewFunctionTypeForName returns a FunctionType based on the function name.
type Map ¶
Map represents a map with string keys and values of any type.
func NewMapWithMap ¶
NewMapWithMap creates a new Map from an existing map.
func NewMapWithRow ¶
NewMap creates a new Map with the given key-value pairs.
type MathResultSet ¶
MathResultSet represents a result set of an math function.
type Max ¶
type Max struct {
// contains filtered or unexported fields
}
Max is an aggregator that calculates the sum of values.
func (Max) Aggregate ¶
Aggregate aggregates a map or an array. The map represents a row of data, and the array is a list of rows. If grouping is enabled, the array row must have a group value as the first element.
func (Max) AggregateMap ¶
AggregateMap aggregates a map of data using the aggregator.
func (Max) AggregateRow ¶
AggregateRow aggregates a row of data using the aggregator. The row is expected to be an array where the first element is the group value (if grouping is enabled),
func (Max) Arguments ¶
func (aggr Max) Arguments() []string
Arguments returns the arguments of the aggregator.
func (Max) GroupBy ¶
GroupBy returns the group by column name and a boolean indicating if it is set.
type MaxOption ¶
type MaxOption = aggrOption
MaxOption is a function that configures the Max aggregator.
func WithMaxArguments ¶
WithMaxArguments sets the arguments for the Max aggregator.
func WithMaxGroupBy ¶
WithMaxGroupBy sets the group by column for the Max aggregator.
type Min ¶
type Min struct {
// contains filtered or unexported fields
}
Min is an aggregator that calculates the minimum of values.
func (Min) Aggregate ¶
Aggregate aggregates a map or an array. The map represents a row of data, and the array is a list of rows. If grouping is enabled, the array row must have a group value as the first element.
func (Min) AggregateMap ¶
AggregateMap aggregates a map of data using the aggregator.
func (Min) AggregateRow ¶
AggregateRow aggregates a row of data using the aggregator. The row is expected to be an array where the first element is the group value (if grouping is enabled),
func (Min) Arguments ¶
func (aggr Min) Arguments() []string
Arguments returns the arguments of the aggregator.
func (Min) GroupBy ¶
GroupBy returns the group by column name and a boolean indicating if it is set.
type MinOption ¶
type MinOption = aggrOption
MinOption is a function that configures the Min aggregator.
func WithMinArguments ¶
WithMinArguments sets the arguments for the Min aggregator.
func WithMinGroupBy ¶
WithMinGroupBy sets the group by column for the Min aggregator.
type ResultSet ¶
type ResultSet interface {
// Columns returns the column names.
Columns() []string
// Next returns the next row.
Next() bool
// Row returns the current row.
Row() (Row, error)
// Map returns the current row as a Map.
Map() (Map, error)
}
ReseltSet is the result set of an aggregation.
func NewResultSet ¶
func NewResultSet(opts ...resultSetOption) ResultSet
NewResultSet creates a new result set with the given options.
type SelectorHelper ¶
type SelectorHelper interface {
// IsAsterisk returns true wheher the selector is an asterisk.
IsAsterisk() bool
// IsFunction returns true whether the selector is a function.
IsFunction() bool
}
SelectorHelper provides additional methods for selectors.
type StringFunc ¶
type Sum ¶
type Sum struct {
// contains filtered or unexported fields
}
Sum is an aggregator that calculates the sum of values.
func (Sum) Aggregate ¶
Aggregate aggregates a map or an array. The map represents a row of data, and the array is a list of rows. If grouping is enabled, the array row must have a group value as the first element.
func (Sum) AggregateMap ¶
AggregateMap aggregates a map of data using the aggregator.
func (Sum) AggregateRow ¶
AggregateRow aggregates a row of data using the aggregator. The row is expected to be an array where the first element is the group value (if grouping is enabled),
func (Sum) Arguments ¶
func (aggr Sum) Arguments() []string
Arguments returns the arguments of the aggregator.
func (Sum) GroupBy ¶
GroupBy returns the group by column name and a boolean indicating if it is set.
type SumOption ¶
type SumOption = aggrOption
SumOption is a function that configures the Sum aggregator.
func WithSumArguments ¶
WithSumArguments sets the arguments for the Sum aggregator.
func WithSumGroupBy ¶
WithSumGroupBy sets the group by column for the Sum aggregator.
Source Files
¶
- aggr.go
- aggr_func.go
- aggr_impl.go
- aggr_set.go
- arg.go
- args.go
- arith.go
- arith_func.go
- avg.go
- cast.go
- const.go
- count.go
- errors.go
- executor.go
- executor_func.go
- executor_impl.go
- func.go
- func_impl.go
- map.go
- math.go
- math_func.go
- max.go
- min.go
- names.go
- resultset.go
- resultset_impl.go
- row.go
- string.go
- string_func.go
- sum.go
- time.go
- time_func.go
- type.go