functions

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Avg

type Avg struct {
	Expr expr.Expr
}

Avg is the AVG aggregator function.

func (*Avg) Aggregator

func (s *Avg) Aggregator() expr.Aggregator

Aggregator returns a Avg. It implements the AggregatorBuilder interface.

func (*Avg) Eval

func (s *Avg) Eval(env *environment.Environment) (types.Value, error)

Eval extracts the average value from the given object and returns it.

func (*Avg) IsEqual

func (s *Avg) IsEqual(other expr.Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

func (*Avg) Params

func (s *Avg) Params() []expr.Expr

func (*Avg) String

func (s *Avg) String() string

String returns the alias if non-zero, otherwise it returns a string representation of the average expression.

type AvgAggregator

type AvgAggregator struct {
	Fn      *Avg
	Avg     float64
	Counter int64
}

AvgAggregator is an aggregator that returns the average non-null value.

func (*AvgAggregator) Aggregate

func (s *AvgAggregator) Aggregate(env *environment.Environment) error

Aggregate stores the average value of all non-NULL numeric values in the group.

func (*AvgAggregator) Eval

Eval returns the aggregated average as a double.

func (*AvgAggregator) String

func (s *AvgAggregator) String() string

type Coalesce

type Coalesce struct {
	Exprs []expr.Expr
}

func (*Coalesce) Eval

func (*Coalesce) Params

func (c *Coalesce) Params() []expr.Expr

func (*Coalesce) String

func (c *Coalesce) String() string

type Count

type Count struct {
	Expr expr.Expr

	Count int64
	// contains filtered or unexported fields
}

Count is the COUNT aggregator function. It counts the number of objects in a stream.

func NewCount

func NewCount(e expr.Expr) *Count

func (*Count) Aggregator

func (c *Count) Aggregator() expr.Aggregator

Aggregator returns a CountAggregator. It implements the AggregatorBuilder interface.

func (*Count) Eval

func (c *Count) Eval(env *environment.Environment) (types.Value, error)

func (*Count) IsEqual

func (c *Count) IsEqual(other expr.Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

func (*Count) Params

func (c *Count) Params() []expr.Expr

func (*Count) String

func (c *Count) String() string

type CountAggregator

type CountAggregator struct {
	Fn    *Count
	Count int64
}

CountAggregator is an aggregator that counts non-null expressions.

func (*CountAggregator) Aggregate

func (c *CountAggregator) Aggregate(env *environment.Environment) error

Aggregate increments the counter if the count expression evaluates to a non-null value.

func (*CountAggregator) Eval

Eval returns the result of the aggregation as an integer.

func (*CountAggregator) String

func (c *CountAggregator) String() string

type Definition

type Definition interface {
	Name() string
	String() string
	Function(...expr.Expr) (expr.Function, error)
	Arity() int
}

A Definition transforms a list of expressions into a Function.

type Definitions

type Definitions map[string]Definition

Definitions table holds a map of definition, indexed by their names.

func BuiltinDefinitions

func BuiltinDefinitions() Definitions

BuiltinDefinitions returns a map of builtin functions.

func MathFunctions

func MathFunctions() Definitions

MathFunctions returns all math package functions.

func ObjectsDefinitions

func ObjectsDefinitions() Definitions

func StringsDefinitions

func StringsDefinitions() Definitions

type Len

type Len struct {
	Expr expr.Expr
}

Len represents the len() function. It returns the length of string, array or object. For other types len() returns NULL.

func (*Len) Eval

func (s *Len) Eval(env *environment.Environment) (types.Value, error)

Eval extracts the average value from the given object and returns it.

func (*Len) IsEqual

func (s *Len) IsEqual(other expr.Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

func (*Len) Params

func (s *Len) Params() []expr.Expr

func (*Len) String

func (s *Len) String() string

String returns the literal representation of len.

type Lower

type Lower struct {
	Expr expr.Expr
}

Lower is the LOWER function It returns the lower-case version of a string

func (*Lower) Eval

func (s *Lower) Eval(env *environment.Environment) (types.Value, error)

func (*Lower) IsEqual

func (s *Lower) IsEqual(other expr.Expr) bool

func (*Lower) Params

func (s *Lower) Params() []expr.Expr

func (*Lower) String

func (s *Lower) String() string

type Max

type Max struct {
	Expr expr.Expr
}

Max is the MAX aggregator function.

func (*Max) Aggregator

func (m *Max) Aggregator() expr.Aggregator

Aggregator returns a MaxAggregator. It implements the AggregatorBuilder interface.

func (*Max) Eval

func (m *Max) Eval(env *environment.Environment) (types.Value, error)

Eval extracts the max value from the given object and returns it.

func (*Max) IsEqual

func (m *Max) IsEqual(other expr.Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

func (*Max) Params

func (m *Max) Params() []expr.Expr

func (*Max) String

func (m *Max) String() string

String returns the alias if non-zero, otherwise it returns a string representation of the count expression.

type MaxAggregator

type MaxAggregator struct {
	Fn  *Max
	Max types.Value
}

MaxAggregator is an aggregator that returns the minimum non-null value.

func (*MaxAggregator) Aggregate

func (m *MaxAggregator) Aggregate(env *environment.Environment) error

Aggregate stores the maximum value. Values are compared based on their types, then if the type is equal their value is compared. Numbers are considered of the same type.

func (*MaxAggregator) Eval

Eval return the maximum value.

func (*MaxAggregator) String

func (m *MaxAggregator) String() string

type Min

type Min struct {
	Expr expr.Expr
}

Min is the MIN aggregator function.

func (*Min) Aggregator

func (m *Min) Aggregator() expr.Aggregator

Aggregator returns a MinAggregator. It implements the AggregatorBuilder interface.

func (*Min) Eval

func (m *Min) Eval(env *environment.Environment) (types.Value, error)

Eval extracts the min value from the given object and returns it.

func (*Min) IsEqual

func (m *Min) IsEqual(other expr.Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

func (*Min) Params

func (m *Min) Params() []expr.Expr

func (*Min) String

func (m *Min) String() string

String returns the alias if non-zero, otherwise it returns a string representation of the count expression.

type MinAggregator

type MinAggregator struct {
	Fn  *Min
	Min types.Value
}

MinAggregator is an aggregator that returns the minimum non-null value.

func (*MinAggregator) Aggregate

func (m *MinAggregator) Aggregate(env *environment.Environment) error

Aggregate stores the minimum value. Values are compared based on their types, then if the type is equal their value is compared. Numbers are considered of the same type.

func (*MinAggregator) Eval

Eval return the minimum value.

func (*MinAggregator) String

func (m *MinAggregator) String() string

type Now

type Now struct{}

func (*Now) Eval

func (n *Now) Eval(env *environment.Environment) (types.Value, error)

func (*Now) IsEqual

func (n *Now) IsEqual(other expr.Expr) bool

func (*Now) Params

func (n *Now) Params() []expr.Expr

func (*Now) String

func (n *Now) String() string

type ObjectFields

type ObjectFields struct {
	Expr expr.Expr
}

ObjectFields implements the objects.fields function which returns the list of top-level fields of an object. If the argument is not an object, it returns null.

func (*ObjectFields) Eval

func (*ObjectFields) IsEqual

func (s *ObjectFields) IsEqual(other expr.Expr) bool

func (*ObjectFields) Params

func (s *ObjectFields) Params() []expr.Expr

func (*ObjectFields) String

func (s *ObjectFields) String() string

type PK

type PK struct{}

PK represents the pk() function. It returns the primary key of the current object.

func (*PK) Eval

func (k *PK) Eval(env *environment.Environment) (types.Value, error)

Eval returns the primary key of the current object.

func (*PK) IsEqual

func (k *PK) IsEqual(other expr.Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

func (*PK) Params

func (*PK) Params() []expr.Expr

func (*PK) String

func (k *PK) String() string

type Packages

type Packages map[string]Definitions

Packages represent a table of SQL functions grouped by their packages

func DefaultPackages

func DefaultPackages() Packages

func (Packages) GetFunc

func (t Packages) GetFunc(pkg string, fname string) (Definition, error)

GetFunc return a function definition by its package and name.

type ScalarDefinition

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

A ScalarDefinition is the definition type for functions which operates on scalar values in contrast to other SQL functions such as the SUM aggregator which operates on expressions instead.

This difference allows to simply define them with a CallFn function that takes multiple object.Value and return another types.Value, rather than having to manually evaluate expressions (see Definition).

func NewScalarDefinition

func NewScalarDefinition(name string, arity int, callFn func(...types.Value) (types.Value, error)) *ScalarDefinition

func (*ScalarDefinition) Arity

func (fd *ScalarDefinition) Arity() int

Arity returns the arity of the defined function.

func (*ScalarDefinition) Function

func (fd *ScalarDefinition) Function(args ...expr.Expr) (expr.Function, error)

Function returns a Function expr node.

func (*ScalarDefinition) Name

func (fd *ScalarDefinition) Name() string

Name returns the defined function named (as an ident, so no parentheses).

func (*ScalarDefinition) String

func (fd *ScalarDefinition) String() string

String returns the defined function name and its arguments.

type ScalarFunction

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

A ScalarFunction is a function which operates on scalar values in contrast to other SQL functions such as the SUM aggregator wich operates on expressions instead.

func (*ScalarFunction) Eval

Eval returns a object.Value based on the given environment and the underlying function definition.

func (*ScalarFunction) Params

func (sf *ScalarFunction) Params() []expr.Expr

Params return the function arguments.

func (*ScalarFunction) String

func (sf *ScalarFunction) String() string

String returns a string represention of the function expression and its arguments.

type Sum

type Sum struct {
	Expr expr.Expr
}

Sum is the SUM aggregator function.

func (*Sum) Aggregator

func (s *Sum) Aggregator() expr.Aggregator

Aggregator returns a Sum. It implements the AggregatorBuilder interface.

func (*Sum) Eval

func (s *Sum) Eval(env *environment.Environment) (types.Value, error)

Eval extracts the sum value from the given object and returns it.

func (*Sum) IsEqual

func (s *Sum) IsEqual(other expr.Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

func (*Sum) Params

func (s *Sum) Params() []expr.Expr

func (*Sum) String

func (s *Sum) String() string

String returns the alias if non-zero, otherwise it returns a string representation of the count expression.

type SumAggregator

type SumAggregator struct {
	Fn   *Sum
	SumI *int64
	SumF *float64
}

SumAggregator is an aggregator that returns the minimum non-null value.

func (*SumAggregator) Aggregate

func (s *SumAggregator) Aggregate(env *environment.Environment) error

Aggregate stores the sum of all non-NULL numeric values in the group. The result is an integer value if all summed values are integers. If any of the value is a double, the returned result will be a double.

func (*SumAggregator) Eval

Eval return the aggregated sum.

func (*SumAggregator) String

func (s *SumAggregator) String() string

type Trim

type Trim struct {
	Expr     []expr.Expr
	TrimFunc TrimFunc
	Name     string
}

TRIM removes leading and trailing characters from a string based on the given input. LTRIM removes leading characters RTRIM removes trailing characters By default remove space " "

func (*Trim) Eval

func (s *Trim) Eval(env *environment.Environment) (types.Value, error)

func (*Trim) IsEqual

func (s *Trim) IsEqual(other expr.Expr) bool

func (*Trim) Params

func (s *Trim) Params() []expr.Expr

func (*Trim) String

func (s *Trim) String() string

type TrimFunc

type TrimFunc func(string, string) string

type TypeOf

type TypeOf struct {
	Expr expr.Expr
}

func (*TypeOf) Eval

func (t *TypeOf) Eval(env *environment.Environment) (types.Value, error)

func (*TypeOf) IsEqual

func (t *TypeOf) IsEqual(other expr.Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

func (*TypeOf) Params

func (t *TypeOf) Params() []expr.Expr

func (*TypeOf) String

func (t *TypeOf) String() string

type Upper

type Upper struct {
	Expr expr.Expr
}

Upper is the UPPER function It returns the upper-case version of a string

func (*Upper) Eval

func (s *Upper) Eval(env *environment.Environment) (types.Value, error)

func (*Upper) IsEqual

func (s *Upper) IsEqual(other expr.Expr) bool

func (*Upper) Params

func (s *Upper) Params() []expr.Expr

func (*Upper) String

func (s *Upper) String() string

Jump to

Keyboard shortcuts

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