Documentation ¶
Index ¶
- func CompareValue(v1, v2 ValueUnion) (int, error)
- func MustCompareValue(v1, v2 ValueUnion) int
- func MustReverseCompareValue(v1, v2 ValueUnion) int
- type FieldValueToValueFn
- type NewResultArrayFn
- type NewResultArrayFromValueTypesFn
- type Op
- func (f Op) AllowedTypes() (field.ValueTypeSet, error)
- func (f Op) IsValid() bool
- func (f Op) MustNewResult(t field.ValueType) Result
- func (f Op) NewResult(t field.ValueType) (Result, error)
- func (f Op) RequiresField() bool
- func (f Op) String() string
- func (f *Op) ToOptionalProto() (servicepb.OptionalCalculationOp, error)
- func (f Op) ToProto() (servicepb.Calculation_Op, error)
- func (f *Op) UnmarshalJSON(data []byte) error
- type Result
- type ResultArray
- type ValueCompareFn
- type ValueType
- type ValueUnion
- type Values
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareValue ¶
func CompareValue(v1, v2 ValueUnion) (int, error)
CompareValue is a convience method that compares two value unions. If the two values have different field types, the result is undefined and the method always returns -1. Otherwise, the corresponding values are compared, and the method returns * -1 if v1 < v2 * 0 if v1 == v2 * 1 if v1 > v2
func MustCompareValue ¶
func MustCompareValue(v1, v2 ValueUnion) int
MustCompareValue compares two value unions, and panics if it encounters an error.
func MustReverseCompareValue ¶
func MustReverseCompareValue(v1, v2 ValueUnion) int
MustReverseCompareValue reverse compares two value unions, and panics if it encounters an error.
Types ¶
type FieldValueToValueFn ¶
type FieldValueToValueFn func(v *field.ValueUnion) ValueUnion
FieldValueToValueFn converts a field value to a calculation value union.
func AsValueFn ¶
func AsValueFn(t field.OptionalType) (FieldValueToValueFn, error)
AsValueFn returns a function that converts a field value union with the given field type to a calculation value union.
func AsValueFns ¶
func AsValueFns(fieldTypes field.OptionalTypeArray) ([]FieldValueToValueFn, error)
AsValueFns returns a list of value conversion functions for the given list of field types.
type NewResultArrayFn ¶
type NewResultArrayFn func() (ResultArray, error)
NewResultArrayFn creates a new result array.
type NewResultArrayFromValueTypesFn ¶
type NewResultArrayFromValueTypesFn func(valueTypes field.OptionalTypeArray) (ResultArray, error)
NewResultArrayFromValueTypesFn creates a new result array based on the field value types.
type Op ¶
type Op int
Op represents a calculation operator.
func (Op) AllowedTypes ¶
func (f Op) AllowedTypes() (field.ValueTypeSet, error)
AllowedTypes returns a list of value types that are allowed for the given calculation operator.
func (Op) MustNewResult ¶
MustNewResult creates a new result based on the operator and possibly the given field value type, and panics if an error is encountered.
func (Op) NewResult ¶
NewResult creates a new result based on the operator and possibly the given field value type.
func (Op) RequiresField ¶
RequiresField returns true if the calculation may be performed against a field that differs from the set of grouping fields.
func (*Op) ToOptionalProto ¶
func (f *Op) ToOptionalProto() (servicepb.OptionalCalculationOp, error)
ToOptionalProto converts the calculation op to an optional calculation op protobuf message.
func (Op) ToProto ¶
func (f Op) ToProto() (servicepb.Calculation_Op, error)
ToProto converts the calculation op to a calculation op protobuf message.
func (*Op) UnmarshalJSON ¶
UnmarshalJSON unmarshals a JSON object as a calculation operator.
type Result ¶
type Result interface { // New creates a new result with the same result type. New() Result // Add adds a value to the result. // TODO(xichen): Perhaps make this API take a `*ValueUnion` instead to save copy time. Add(v ValueUnion) // MergeInPlace merges the current result with the other result in place. MergeInPlace(other Result) error // Value returns the result value. Value() ValueUnion // MarshalJSON marshals the result as a JSON object. MarshalJSON() ([]byte, error) }
Result represents a merge-able calculation result. In simple cases this can be simply a single numeric value or a bytes value. However, there are also cases where calculation of a result requires calculations of other intermediate values, which eventually get transformed into the final result (e.g., the average value of a field).
func NewMaxBytesResult ¶
func NewMaxBytesResult() Result
NewMaxBytesResult creates a new maximum bytes result.
func NewMaxNumberResult ¶
func NewMaxNumberResult() Result
NewMaxNumberResult creates a new maximum number result.
func NewMinBytesResult ¶
func NewMinBytesResult() Result
NewMinBytesResult creates a new minimum bytes result.
func NewMinNumberResult ¶
func NewMinNumberResult() Result
NewMinNumberResult creates a new minimum number result.
type ResultArray ¶
type ResultArray []Result
ResultArray is an array of calculation result.
func (ResultArray) MergeInPlace ¶
func (arr ResultArray) MergeInPlace(other ResultArray)
MergeInPlace merges the other result array into the current array in place. Precondition: len(arr) == len(other).
func (ResultArray) New ¶
func (arr ResultArray) New() ResultArray
New creates a new result array where each result is created anew from the existing result in the corresponding slot.
func (ResultArray) ToProto ¶
func (arr ResultArray) ToProto() []servicepb.CalculationValue
ToProto converts a result array to a value array protobuf message.
type ValueCompareFn ¶
type ValueCompareFn func(v1, v2 ValueUnion) int
ValueCompareFn compares two value unions.
type ValueUnion ¶
ValueUnion is a value union.
func NewBytesUnion ¶
func NewBytesUnion(v xbytes.Bytes) ValueUnion
NewBytesUnion creates a new string union.
func NewNumberUnion ¶
func NewNumberUnion(v float64) ValueUnion
NewNumberUnion creates a new number union.
func NewValueFromProto ¶
func NewValueFromProto(pbValue servicepb.CalculationValue) (ValueUnion, error)
NewValueFromProto creates a value from protobuf message.
func (ValueUnion) MarshalJSON ¶
func (u ValueUnion) MarshalJSON() ([]byte, error)
MarshalJSON marshals value as a JSON object.
func (ValueUnion) ToProto ¶
func (u ValueUnion) ToProto() servicepb.CalculationValue
ToProto converts a value to a calculation value protobuf message.
type Values ¶
type Values []ValueUnion
Values is a list of calculation values.
func NewValuesFromProto ¶
func NewValuesFromProto(pbValues []servicepb.CalculationValue) (Values, error)
NewValuesFromProto creates a list of calculation values from protobuf message.