Documentation ¶
Overview ¶
Package expr provides a framework for Expressions that evaluate to floating point values and allow various functions that can aggregate data, perform calculations on that data, evaluate boolean expressions against that data and serialize the data to/from bytes for durable storage in the database.
Index ¶
- func AssertFloatEquals(t *testing.T, a, b float64) bool
- func AssertFloatWithin(t *testing.T, e, expected float64, actual float64, msg string) bool
- func FuzzyEquals(e, a, b float64) bool
- func IsField(e Expr) (string, bool)
- func IsPercentile(e Expr) bool
- type Expr
- func ADD(left interface{}, right interface{}) Expr
- func AND(left interface{}, right interface{}) Expr
- func AVG(val interface{}) Expr
- func BOUNDED(expr interface{}, min float64, max float64) Expr
- func CONST(value float64) Expr
- func COUNT(expr interface{}) Expr
- func DIV(left interface{}, right interface{}) Expr
- func EQ(left interface{}, right interface{}) Expr
- func FIELD(name string) Expr
- func GT(left interface{}, right interface{}) Expr
- func GTE(left interface{}, right interface{}) Expr
- func IF(cond goexpr.Expr, wrapped interface{}) Expr
- func LT(left interface{}, right interface{}) Expr
- func LTE(left interface{}, right interface{}) Expr
- func MAX(expr interface{}) Expr
- func MIN(expr interface{}) Expr
- func MULT(left interface{}, right interface{}) Expr
- func NEQ(left interface{}, right interface{}) Expr
- func OR(left interface{}, right interface{}) Expr
- func PERCENTILE(value interface{}, percentile interface{}, min float64, max float64, ...) Expr
- func PERCENTILEOPT(wrapped interface{}, percentile interface{}) Expr
- func SHIFT(wrapped interface{}, offset time.Duration) Expr
- func SUB(left interface{}, right interface{}) Expr
- func SUM(expr interface{}) Expr
- func UnaryMath(name string, wrapped interface{}) (Expr, error)
- func WAVG(val interface{}, weight interface{}) Expr
- type FloatParams
- type Map
- type Params
- type SubMerge
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertFloatEquals ¶
AssertFloatEquals does a fuzzy comparison of floats.
func AssertFloatWithin ¶
AssertFloatWithin checks whether a given float is within e error (decimal) of another float
func FuzzyEquals ¶
courtesy of https://gist.github.com/cevaris/bc331cbe970b03816c6b
func IsField ¶
IsField checks whether the given expression is a field expression and if so, returns the name of the field.
func IsPercentile ¶
IsPercentile indicates whether the given expression is a percentile expression.
Types ¶
type Expr ¶
type Expr interface { // Validate makes sure that this expression is valid and returns an error if // it is not. Validate() error // EncodedWidth returns the number of bytes needed to represent the internal // state of this Expr. EncodedWidth() int // Shift returns the total cumulative shift in time, including // subexpressions. Shift() time.Duration // Update updates the value in buf by applying the given Params. Metadata // provides additional metadata that can be used in evaluating how to apply // the update. Update(b []byte, params Params, metadata goexpr.Params) (remain []byte, value float64, updated bool) // Merge merges x and y, writing the result to b. It returns the remaining // portions of x and y. Merge(b []byte, x []byte, y []byte) (remainB []byte, remainX []byte, remainY []byte) // SubMergers returns a list of functions that merge values of the given // subexpressions into this Expr. The list is the same length as the number of // sub expressions. For any subexpression that is not represented in our // Expression, the corresponding function in the list is nil. SubMergers(subs []Expr) []SubMerge // Get gets the value in buf, returning the value, a boolean indicating // whether or not the value was actually set, and the remaining byte array // after consuming the underlying data. Get(b []byte) (value float64, ok bool, remain []byte) // IsConstant indicates whether or not this is a constant expression IsConstant() bool // DeAggregate strips aggregates from this expression and returns the result DeAggregate() Expr String() string }
An Expr is expression that stores its value in a byte array and that evaluates to a float64.
func ADD ¶
func ADD(left interface{}, right interface{}) Expr
ADD creates an Expr that obtains its value by adding right and left.
func AND ¶
func AND(left interface{}, right interface{}) Expr
AND tests whether left and right is true
func AVG ¶
func AVG(val interface{}) Expr
AVG creates an Expr that obtains its value as the arithmetic mean over the given value.
func BOUNDED ¶
BOUNDED bounds the given expression to min <= val <= max. Any values that fall outside of the bounds will appear as unset (i.e. they are discarded.)
func COUNT ¶
func COUNT(expr interface{}) Expr
COUNT creates an Expr that counts the number of values.
func DIV ¶
func DIV(left interface{}, right interface{}) Expr
DIV creates an Expr that obtains its value by dividing left by right. If right is 0, this returns 0.
func GT ¶
func GT(left interface{}, right interface{}) Expr
GT tests whether left is greater than right
func GTE ¶
func GTE(left interface{}, right interface{}) Expr
GTE tests whether left is greater than or equal to right
func LT ¶
func LT(left interface{}, right interface{}) Expr
LT tests whether left is less than right
func LTE ¶
func LTE(left interface{}, right interface{}) Expr
LTE tests whether left is less than or equal to the right
func MAX ¶
func MAX(expr interface{}) Expr
MAX creates an Expr that keeps track of the maximum value of the wrapped expression or field.
func MIN ¶
func MIN(expr interface{}) Expr
MIN creates an Expr that keeps track of the minimum value of the wrapped expression or field.
func MULT ¶
func MULT(left interface{}, right interface{}) Expr
MULT creates an Expr that obtains its value by multiplying right and left.
func NEQ ¶
func NEQ(left interface{}, right interface{}) Expr
NEQ tests whether left is different from right
func PERCENTILE ¶
func PERCENTILE(value interface{}, percentile interface{}, min float64, max float64, precision int) Expr
PERCENTILE tracks estimated percentile values for the given expression assuming the given min and max possible values, to the given precision (where precision is the number of decimal points).
Inputs are automatically bounded to the min/max using BOUNDED, such that values falling outside the range are discarded. Percentile is input in percent (e.g. 0-100). See https://godoc.org/github.com/codahale/hdrhistogram.
It is possible to wrap an existing PERCENTILE with a new PERCENTILE to reuse the original PERCENTILE's storage but look at a different percentile. In this case, the min, max and precision parameters are ignored.
WARNING - when PERCENTILEs that wrap existing PERCENTILEs are not stored and as such are only suitable for use in querying but not in tables or views unless those explicitly include the original PERCENTILE as well.
WARNING - relative to other types of expressions, PERCENTILE types can be very large (e.g. on the order of Kilobytes vs 8 or 16 bytes for most other expressions) so it is best to keep these relatively low cardinality.
func PERCENTILEOPT ¶
func PERCENTILEOPT(wrapped interface{}, percentile interface{}) Expr
PERCENTILEOPT returns an optimized PERCENTILE that wraps an existing PERCENTILE.
func SUB ¶
func SUB(left interface{}, right interface{}) Expr
SUB creates an Expr that obtains its value by subtracting right from left.
type FloatParams ¶
type FloatParams float64
FloatParams is an implementation of Params that always returns the same float64 value.
type Params ¶
type Params interface { // Get returns the named value. Found should be false if nothing was found for // the given name. Get(name string) (val float64, found bool) }
Params is an interface for data structures that can contain named values.