field

package
v0.0.0-...-ad801e6 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// OrderableTypes is a list of value types eligible for ordering.
	OrderableTypes = ValueTypeSet{
		NullType:   struct{}{},
		BoolType:   struct{}{},
		IntType:    struct{}{},
		DoubleType: struct{}{},
		BytesType:  struct{}{},
		TimeType:   struct{}{},
	}

	// GroupableTypes is a list of value types eligible for grouping.
	GroupableTypes = ValueTypeSet{
		NullType:   struct{}{},
		BoolType:   struct{}{},
		IntType:    struct{}{},
		DoubleType: struct{}{},
		BytesType:  struct{}{},
		TimeType:   struct{}{},
	}
)
View Source
var (
	// NullUnion is a null value union.
	NullUnion = ValueUnion{Type: NullType}
)
View Source
var (
	// NumValidFieldTypes returns the number of valid field types.
	NumValidFieldTypes = len(validTypes)
)

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.

func ReturnArrayToPool

func ReturnArrayToPool(fields []Field, p *BucketizedFieldArrayPool)

ReturnArrayToPool returns an field array to pool.

Types

type BoolAsUnionFn

type BoolAsUnionFn func(v bool) ValueUnion

BoolAsUnionFn converts a bool to a value union.

type BucketizedFieldArrayPool

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

BucketizedFieldArrayPool is a bucketized value pool.

func NewBucketizedFieldArrayPool

func NewBucketizedFieldArrayPool(sizes []FieldArrayBucket, opts *FieldArrayPoolOptions) *BucketizedFieldArrayPool

NewBucketizedFieldArrayPool creates a bucketized object pool.

func (*BucketizedFieldArrayPool) Get

func (p *BucketizedFieldArrayPool) Get(capacity int) []Field

Get gets a value from the pool.

func (*BucketizedFieldArrayPool) Init

func (p *BucketizedFieldArrayPool) Init(alloc func(capacity int) []Field)

Init initializes the bucketized pool.

func (*BucketizedFieldArrayPool) Put

func (p *BucketizedFieldArrayPool) Put(v []Field, capacity int)

Put puts a value to the pool.

type BucketizedFieldArrayPoolConfiguration

type BucketizedFieldArrayPoolConfiguration struct {
	// The pool bucket configuration.
	Buckets []FieldArrayBucketConfiguration `yaml:"buckets"`

	// The watermark configuration.
	Watermark FieldArrayPoolWatermarkConfiguration `yaml:"watermark"`
}

BucketizedFieldArrayPoolConfiguration contains configuration for bucketized pools.

func (*BucketizedFieldArrayPoolConfiguration) NewBuckets

NewBuckets create a new list of buckets.

func (*BucketizedFieldArrayPoolConfiguration) NewPoolOptions

func (c *BucketizedFieldArrayPoolConfiguration) NewPoolOptions(
	instrumentOptions instrument.Options,
) *FieldArrayPoolOptions

NewPoolOptions creates a new set of pool options.

type BytesAsUnionFn

type BytesAsUnionFn func(v xbytes.Bytes) ValueUnion

BytesAsUnionFn converts a string to a value union.

type DoubleAsUnionFn

type DoubleAsUnionFn func(v float64) ValueUnion

DoubleAsUnionFn converts a double to a value union.

type Field

type Field struct {
	Path  []string
	Value ValueUnion
}

Field is an event field.

func NewFieldFromProto

func NewFieldFromProto(pbField servicepb.Field) (Field, error)

NewFieldFromProto creates a new field from a field protobuf message.

func (*Field) Clone

func (f *Field) Clone() Field

Clone clones a field.

func (*Field) Reset

func (f *Field) Reset()

Reset resets a field.

func (*Field) ToProto

func (f *Field) ToProto() (servicepb.Field, error)

ToProto converts a field to a field protobuf message.

type FieldArrayBucket

type FieldArrayBucket struct {
	// Capacity is the size of each element in the bucket.
	Capacity int

	// Count is the number of fixed elements in the bucket.
	Count int

	// Options is an optional override to specify options to use for a bucket,
	// specify nil to use the options specified to the bucketized pool
	// constructor for this bucket.
	Options *FieldArrayPoolOptions
}

FieldArrayBucket specifies a bucket.

type FieldArrayBucketConfiguration

type FieldArrayBucketConfiguration struct {
	// The count of the items in the bucket.
	Count int `yaml:"count"`

	// The capacity of each item in the bucket.
	Capacity int `yaml:"capacity"`
}

FieldArrayBucketConfiguration contains configuration for a pool bucket.

func (*FieldArrayBucketConfiguration) NewBucket

NewBucket creates a new bucket.

type FieldArrayPool

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

FieldArrayPool is a value pool.

func NewFieldArrayPool

func NewFieldArrayPool(opts *FieldArrayPoolOptions) *FieldArrayPool

NewFieldArrayPool creates a new pool.

func (*FieldArrayPool) Get

func (p *FieldArrayPool) Get() []Field

Get gets a value from the pool.

func (*FieldArrayPool) Init

func (p *FieldArrayPool) Init(alloc func() []Field)

Init initializes the pool.

func (*FieldArrayPool) Put

func (p *FieldArrayPool) Put(v []Field)

Put returns a value to pool.

type FieldArrayPoolConfiguration

type FieldArrayPoolConfiguration struct {
	// The size of the pool.
	Size *int `yaml:"size"`

	// The watermark configuration.
	Watermark FieldArrayPoolWatermarkConfiguration `yaml:"watermark"`
}

FieldArrayPoolConfiguration contains pool configuration.

func (*FieldArrayPoolConfiguration) NewPoolOptions

func (c *FieldArrayPoolConfiguration) NewPoolOptions(
	instrumentOpts instrument.Options,
) *FieldArrayPoolOptions

NewPoolOptions creates a new set of pool options.

type FieldArrayPoolOptions

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

FieldArrayPoolOptions provide a set of options for the value pool.

func NewFieldArrayPoolOptions

func NewFieldArrayPoolOptions() *FieldArrayPoolOptions

NewFieldArrayPoolOptions create a new set of value pool options.

func (*FieldArrayPoolOptions) InstrumentOptions

func (o *FieldArrayPoolOptions) InstrumentOptions() instrument.Options

InstrumentOptions returns the instrument options.

func (*FieldArrayPoolOptions) RefillHighWatermark

func (o *FieldArrayPoolOptions) RefillHighWatermark() float64

RefillHighWatermark returns the high watermark for stop refilling the pool.

func (*FieldArrayPoolOptions) RefillLowWatermark

func (o *FieldArrayPoolOptions) RefillLowWatermark() float64

RefillLowWatermark returns the low watermark for refilling the pool.

func (*FieldArrayPoolOptions) SetInstrumentOptions

func (o *FieldArrayPoolOptions) SetInstrumentOptions(v instrument.Options) *FieldArrayPoolOptions

SetInstrumentOptions sets the instrument options.

func (*FieldArrayPoolOptions) SetRefillHighWatermark

func (o *FieldArrayPoolOptions) SetRefillHighWatermark(v float64) *FieldArrayPoolOptions

SetRefillHighWatermark sets the high watermark for refilling the pool.

func (*FieldArrayPoolOptions) SetRefillLowWatermark

func (o *FieldArrayPoolOptions) SetRefillLowWatermark(v float64) *FieldArrayPoolOptions

SetRefillLowWatermark sets the low watermark for refilling the pool.

func (*FieldArrayPoolOptions) SetSize

SetSize sets the pool size.

func (*FieldArrayPoolOptions) Size

func (o *FieldArrayPoolOptions) Size() int

Size returns pool size.

type FieldArrayPoolWatermarkConfiguration

type FieldArrayPoolWatermarkConfiguration struct {
	// The low watermark to start refilling the pool, if zero none.
	RefillLowWatermark float64 `yaml:"low" validate:"min=0.0,max=1.0"`

	// The high watermark to stop refilling the pool, if zero none.
	RefillHighWatermark float64 `yaml:"high" validate:"min=0.0,max=1.0"`
}

FieldArrayPoolWatermarkConfiguration contains watermark configuration for pools.

type Fields

type Fields []Field

Fields is a list of fields.

func (Fields) ToProto

func (f Fields) ToProto() ([]servicepb.Field, error)

ToProto converts a list of fields to a list of fields in protobuf message.

type IntAsUnionFn

type IntAsUnionFn func(v int) ValueUnion

IntAsUnionFn converts an int to a value union.

type Iterator

type Iterator interface {
	// Next returns true if there are more fields to be iterated over,
	// and false otherwise.
	Next() bool

	// Current returns the current field. The field remains valid
	// until the next Next() call.
	Current() Field

	// Close closes the iterator.
	Close()
}

Iterator iterate over a set of fields.

func NewArrayBasedIterator

func NewArrayBasedIterator(arr []Field, p *BucketizedFieldArrayPool) Iterator

NewArrayBasedIterator creates an array based iterator. If the array pool is nil, the field array should be returned to pool on close.

type OptionalType

type OptionalType struct {
	HasType bool
	Type    ValueType
}

OptionalType is a type "option" which is either "null" or has a valid type. It is similar to a `*ValueType` from a functionality perspective but has lower GC overhead.

func (*OptionalType) MergeInPlace

func (t *OptionalType) MergeInPlace(other OptionalType) error

MergeInPlace merges the other optional type into the current optional type. The merging is valid if: - Neither optional types has a type. - Only one of `t` and `other` has a valid type. - Both optional types have the same valid type.

type OptionalTypeArray

type OptionalTypeArray []OptionalType

OptionalTypeArray is an array of optional types.

func (*OptionalTypeArray) MergeInPlace

func (v *OptionalTypeArray) MergeInPlace(other OptionalTypeArray) error

MergeInPlace merges the other type array into the current type array in place. The other type array becomes invalid after the merge. Precondition: One of the following conditions is true: - One of or both `v` and `other` are nil. - Both type arrays have the same size.

type TimeAsUnionFn

type TimeAsUnionFn func(v int64) ValueUnion

TimeAsUnionFn converts a time to a value union.

type ValueCloneOptions

type ValueCloneOptions struct {
	DeepCloneBytes bool
}

ValueCloneOptions controls how a value should be cloned.

type ValueCompareFn

type ValueCompareFn func(v1, v2 ValueUnion) int

ValueCompareFn compares two value unions.

type ValueType

type ValueType int

ValueType is the type of a field value.

const (
	UnknownType ValueType = iota
	NullType
	BoolType
	IntType
	DoubleType
	BytesType
	TimeType
)

List of supported field value types.

func (ValueType) IsValid

func (t ValueType) IsValid() bool

IsValid returns true if this is a valid value type.

func (ValueType) String

func (t ValueType) String() string

type ValueTypeArray

type ValueTypeArray []ValueType

ValueTypeArray is an array of value types.

func MergeTypes

func MergeTypes(a, b ValueTypeArray) ValueTypeArray

MergeTypes merges two value type arrays into a merged value type array.

func (ValueTypeArray) Equal

func (arr ValueTypeArray) Equal(other ValueTypeArray) bool

Equal returns true if the two value type arrays are considered equal, and false otherwise.

type ValueTypeSet

type ValueTypeSet map[ValueType]struct{}

ValueTypeSet is a set of value types.

func (ValueTypeSet) Clone

func (m ValueTypeSet) Clone() ValueTypeSet

Clone clones a value type set.

func (ValueTypeSet) MergeInPlace

func (m ValueTypeSet) MergeInPlace(other ValueTypeSet)

MergeInPlace merges another value type set into the current set in place.

type ValueUnion

type ValueUnion struct {
	Type         ValueType
	BoolVal      bool
	IntVal       int
	DoubleVal    float64
	BytesVal     xbytes.Bytes
	TimeNanosVal int64
}

ValueUnion is a value union.

func NewBoolUnion

func NewBoolUnion(v bool) ValueUnion

NewBoolUnion creates a new bool union.

func NewBytesUnion

func NewBytesUnion(v xbytes.Bytes) ValueUnion

NewBytesUnion creates a new bytes union.

func NewDoubleUnion

func NewDoubleUnion(v float64) ValueUnion

NewDoubleUnion creates a new double union.

func NewIntUnion

func NewIntUnion(v int) ValueUnion

NewIntUnion creates a new int union.

func NewTimeUnion

func NewTimeUnion(v int64) ValueUnion

NewTimeUnion creates a new time union.

func NewValueFromProto

func NewValueFromProto(pbValue servicepb.FieldValue) (ValueUnion, error)

NewValueFromProto creates a value from protobuf message.

func (*ValueUnion) Clone

func (v *ValueUnion) Clone(opts ValueCloneOptions) ValueUnion

Clone clones a value union.

func (*ValueUnion) Equal

func (v *ValueUnion) Equal(other *ValueUnion) bool

Equal returns true if two value unions are considered equal.

func (*ValueUnion) Hash

func (v *ValueUnion) Hash() uint64

Hash returns the hash of a value union.

func (ValueUnion) MarshalJSON

func (v ValueUnion) MarshalJSON() ([]byte, error)

MarshalJSON marshals value as a JSON object.

func (*ValueUnion) ToProto

func (v *ValueUnion) ToProto() (servicepb.FieldValue, error)

ToProto converts a value to a value proto message.

type Values

type Values []ValueUnion

Values is an array of values.

func FilterValues

func FilterValues(values Values, toExcludeIndices []int) Values

FilterValues return a value array excluding the given value indices. Precondition: Elements in `toExcludeIndices` are unique, monotonically increasing, and within range [0, len(values)). Postcondition: `values` is unmodified.

func NewValuesFromProto

func NewValuesFromProto(pbValues []servicepb.FieldValue) (Values, error)

NewValuesFromProto creates a list of field values from protobuf message.

func (Values) Clone

func (v Values) Clone(opts ValueCloneOptions) Values

Clone clones the values.

func (Values) Equal

func (v Values) Equal(other Values) bool

Equal returns true if two value arrays are considered equal.

func (Values) Hash

func (v Values) Hash() uint64

Hash returns the hash of a value array.

func (Values) ToProto

func (v Values) ToProto() ([]servicepb.FieldValue, error)

ToProto converts a value array to a value array protobuf message.

type ValuesLessThanFn

type ValuesLessThanFn func(v1, v2 Values) bool

ValuesLessThanFn compares two value unions and returns true if `v1` is less than `v2`.

func NewValuesLessThanFn

func NewValuesLessThanFn(compareFns []ValueCompareFn) ValuesLessThanFn

NewValuesLessThanFn creates a less than fn from a set of field value comparison functions. The logic is such that the function returned perform a prioritized ordering of results, where values at smaller indices of the array have higher priority and values at higher indices are only consulted if those at smaller indices are equal. Precondition: len(v1) == len(compareFns) && len(v2) == len(compareFns).

Jump to

Keyboard shortcuts

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