Documentation ¶
Index ¶
- func ToCalculationOp(pbCalculationOp servicepb.Calculation_Op) (calculation.Op, error)
- func ToCalculationOpPtr(pbCalculationOp servicepb.OptionalCalculationOp) (*calculation.Op, error)
- func ToDurationPtr(pbTimeNanos servicepb.OptionalInt64) *xtime.Duration
- func ToFilterCombinatorPtr(pbFilterCombinator servicepb.OptionalFilterCombinator) (*filter.Combinator, error)
- func ToFilterOp(pbFilterOp servicepb.Filter_Op) (filter.Op, error)
- func ToFilterValue(pbFilterValue servicepb.OptionalFilterValue) (interface{}, error)
- func ToInt64Ptr(pbValue servicepb.OptionalInt64) *int64
- func ToIntPtr(pbValue servicepb.OptionalInt64) *int
- func ToStringPtr(pbString servicepb.OptionalString) *string
- func ToTimeUnit(pbTimeUnit servicepb.TimeUnit) (xtime.Unit, error)
- func ToTimeUnitPtr(pbTimeUnit servicepb.OptionalTimeUnit) (*xtime.Unit, error)
- type BytesCopyFunc
- type BytesEqualsFunc
- type BytesFinalizeFunc
- type BytesHashFunc
- type BytesResultArrayHashMap
- func (m *BytesResultArrayHashMap) Contains(k []byte) bool
- func (m *BytesResultArrayHashMap) Delete(k []byte)
- func (m *BytesResultArrayHashMap) Get(k []byte) (calculation.ResultArray, bool)
- func (m *BytesResultArrayHashMap) Iter() map[BytesResultArrayHashMapHash]BytesResultArrayHashMapEntry
- func (m *BytesResultArrayHashMap) Len() int
- func (m *BytesResultArrayHashMap) Reallocate()
- func (m *BytesResultArrayHashMap) Reset()
- func (m *BytesResultArrayHashMap) Set(k []byte, v calculation.ResultArray)
- func (m *BytesResultArrayHashMap) SetUnsafe(k []byte, v calculation.ResultArray, opts SetUnsafeBytesOptions)
- type BytesResultArrayHashMapEntry
- type BytesResultArrayHashMapHash
- type BytesResultArrayHashMapOptions
- type Calculation
- type FieldMeta
- type Filter
- type FilterList
- type ForEachSingleKeyResultGroupFn
- type GroupedQueryResults
- type GroupedResults
- func (r *GroupedResults) Clear()
- func (r *GroupedResults) HasSingleKey() bool
- func (r *GroupedResults) IsComplete() bool
- func (r *GroupedResults) IsEmpty() bool
- func (r *GroupedResults) IsOrdered() bool
- func (r *GroupedResults) Len() int
- func (r *GroupedResults) LimitReached() bool
- func (r *GroupedResults) MarshalJSON() ([]byte, error)
- func (r *GroupedResults) MergeInPlace(other *GroupedResults) error
- func (r *GroupedResults) NumGroupsLimit() int
- func (r *GroupedResults) ToProto() (*servicepb.GroupedQueryResults, error)
- func (r *GroupedResults) TrimIfNeeded()
- type InsertionStatus
- type MultiKeyGroupQueryResult
- type MultiKeyGroupQueryResults
- type MultiKeyResultGroups
- func (m *MultiKeyResultGroups) Clear()
- func (m *MultiKeyResultGroups) GetOrInsert(key []field.ValueUnion) (calculation.ResultArray, InsertionStatus)
- func (m *MultiKeyResultGroups) Len() int
- func (m *MultiKeyResultGroups) MarshalJSON(numGroups int, topNRequired bool) ([]byte, error)
- func (m *MultiKeyResultGroups) MergeInPlace(other *MultiKeyResultGroups)
- func (m *MultiKeyResultGroups) ToProto(numGroups int, topNRequired bool) (*servicepb.MultiKeyGroupQueryResults, error)
- type OrderBy
- type OrderByFieldType
- type ParseOptions
- type ParsedGroupedQuery
- type ParsedQuery
- type ParsedRawQuery
- type ParsedTimeBucketQuery
- type RawCalculation
- type RawCalculations
- type RawFilter
- type RawFilterList
- type RawFilterLists
- type RawFilters
- type RawOrderBy
- type RawOrderBys
- type RawQueryResults
- type RawResult
- type RawResultAddOptions
- type RawResultHeap
- func (h RawResultHeap) Cap() int
- func (h RawResultHeap) Len() int
- func (h RawResultHeap) Less(i, j int) bool
- func (h RawResultHeap) Min() RawResult
- func (h *RawResultHeap) Pop() RawResult
- func (h *RawResultHeap) Push(value RawResult)
- func (h RawResultHeap) RawData() []RawResult
- func (h *RawResultHeap) Reset()
- func (h *RawResultHeap) SortInPlace() []RawResult
- func (h RawResultHeap) Swap(i, j int)
- type RawResultLessThanFn
- type RawResults
- func (r *RawResults) AddOrdered(rr RawResult, opts RawResultAddOptions)
- func (r *RawResults) AddUnordered(rr RawResult)
- func (r *RawResults) Clear()
- func (r *RawResults) FieldValuesLessThanFn() field.ValuesLessThanFn
- func (r *RawResults) HasOrderedFilter() bool
- func (r *RawResults) IsComplete() bool
- func (r *RawResults) IsEmpty() bool
- func (r *RawResults) IsOrdered() bool
- func (r *RawResults) Len() int
- func (r *RawResults) LimitReached() bool
- func (r *RawResults) MarshalJSON() ([]byte, error)
- func (r *RawResults) MaxOrderByValues() field.Values
- func (r *RawResults) MergeInPlace(other *RawResults) error
- func (r *RawResults) MinOrderByValues() field.Values
- func (r *RawResults) ToProto() *servicepb.RawQueryResults
- type SetUnsafeBytesOptions
- type SetUnsafeOptions
- type SingleKeyGroupQueryResult
- type SingleKeyGroupQueryResults
- type SingleKeyResultGroups
- func (m *SingleKeyResultGroups) Clear()
- func (m *SingleKeyResultGroups) GetOrInsertNoCheck(key *field.ValueUnion) (calculation.ResultArray, InsertionStatus)
- func (m *SingleKeyResultGroups) Len() int
- func (m *SingleKeyResultGroups) MarshalJSON(numGroups int, topNRequired bool) ([]byte, error)
- func (m *SingleKeyResultGroups) MergeInPlace(other *SingleKeyResultGroups)
- func (m *SingleKeyResultGroups) ToProto(numGroups int, topNRequired bool) *servicepb.SingleKeyGroupQueryResults
- type SortOrder
- func (f SortOrder) CompareBoolFn() (compare.BoolCompareFn, error)
- func (f SortOrder) CompareBytesFn() (compare.BytesCompareFn, error)
- func (f SortOrder) CompareCalcValue(v1, v2 calculation.ValueUnion) (int, error)
- func (f SortOrder) CompareCalcValueFn() (calculation.ValueCompareFn, error)
- func (f SortOrder) CompareDoubleFn() (compare.DoubleCompareFn, error)
- func (f SortOrder) CompareFieldValue(v1, v2 field.ValueUnion) (int, error)
- func (f SortOrder) CompareFieldValueFn() (field.ValueCompareFn, error)
- func (f SortOrder) CompareIntFn() (compare.IntCompareFn, error)
- func (f SortOrder) CompareTimeFn() (compare.TimeCompareFn, error)
- func (f SortOrder) MustCompareCalcValue(v1, v2 calculation.ValueUnion) int
- func (f SortOrder) MustCompareFieldValue(v1, v2 field.ValueUnion) int
- func (f SortOrder) String() string
- func (f *SortOrder) ToProto() (servicepb.OptionalSortOrder, error)
- func (f *SortOrder) UnmarshalJSON(data []byte) error
- type TimeBucketQueryResult
- type TimeBucketQueryResults
- type TimeBucketResults
- func (r *TimeBucketResults) AddAt(timestampNanos int64)
- func (r *TimeBucketResults) Clear()
- func (r *TimeBucketResults) IsEmpty() bool
- func (r *TimeBucketResults) MarshalJSON() ([]byte, error)
- func (r *TimeBucketResults) MergeInPlace(other *TimeBucketResults) error
- func (r *TimeBucketResults) ToProto() *servicepb.TimeBucketQueryResults
- type TopNRawResults
- func (v *TopNRawResults) Add(val RawResult, opts RawResultAddOptions)
- func (v TopNRawResults) Cap() int
- func (v TopNRawResults) Len() int
- func (v TopNRawResults) RawData() []RawResult
- func (v *TopNRawResults) Reset()
- func (v *TopNRawResults) SortInPlace() []RawResult
- func (v TopNRawResults) Top() RawResult
- type Type
- type UnparsedGroupedQuery
- type UnparsedQuery
- type UnparsedRawQuery
- type UnparsedTimeBucketQuery
- type ValuesCopyFunc
- type ValuesEqualsFunc
- type ValuesFinalizeFunc
- type ValuesHashFunc
- type ValuesResultArrayHash
- func (m *ValuesResultArrayHash) Contains(k field.Values) bool
- func (m *ValuesResultArrayHash) Delete(k field.Values)
- func (m *ValuesResultArrayHash) Get(k field.Values) (calculation.ResultArray, bool)
- func (m *ValuesResultArrayHash) Iter() map[ValuesResultArrayHashHash]ValuesResultArrayHashEntry
- func (m *ValuesResultArrayHash) Len() int
- func (m *ValuesResultArrayHash) Reallocate()
- func (m *ValuesResultArrayHash) Reset()
- func (m *ValuesResultArrayHash) Set(k field.Values, v calculation.ResultArray)
- func (m *ValuesResultArrayHash) SetUnsafe(k field.Values, v calculation.ResultArray, opts SetUnsafeOptions)
- type ValuesResultArrayHashEntry
- type ValuesResultArrayHashHash
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ToCalculationOp ¶
func ToCalculationOp( pbCalculationOp servicepb.Calculation_Op, ) (calculation.Op, error)
ToCalculationOp converts a calculation op in protobuf to an internal calculation op.
func ToCalculationOpPtr ¶
func ToCalculationOpPtr( pbCalculationOp servicepb.OptionalCalculationOp, ) (*calculation.Op, error)
ToCalculationOpPtr converts an optional calculation op in protobuf to an internal calculation op pointer.
func ToDurationPtr ¶
func ToDurationPtr(pbTimeNanos servicepb.OptionalInt64) *xtime.Duration
ToDurationPtr converts an optional int64 in protobuf to a time duration pointer.
func ToFilterCombinatorPtr ¶
func ToFilterCombinatorPtr( pbFilterCombinator servicepb.OptionalFilterCombinator, ) (*filter.Combinator, error)
ToFilterCombinatorPtr converts an optional filter combinator in protobuf to a filter combinator pointer.
func ToFilterOp ¶
ToFilterOp converts a filter op in protobuf to an internal filter op.
func ToFilterValue ¶
func ToFilterValue(pbFilterValue servicepb.OptionalFilterValue) (interface{}, error)
ToFilterValue converts an optional filter value to an internal filter value.
func ToInt64Ptr ¶
func ToInt64Ptr(pbValue servicepb.OptionalInt64) *int64
ToInt64Ptr converts an optional int64 in protobuf to an *int64.
func ToIntPtr ¶
func ToIntPtr(pbValue servicepb.OptionalInt64) *int
ToIntPtr converts an optional int64 in protobuf to an *int.
func ToStringPtr ¶
func ToStringPtr(pbString servicepb.OptionalString) *string
ToStringPtr converts an optional string in protobuf to a string pointer.
func ToTimeUnit ¶
ToTimeUnit converts a time unit in protobuf to an internal time unit.
func ToTimeUnitPtr ¶
func ToTimeUnitPtr(pbTimeUnit servicepb.OptionalTimeUnit) (*xtime.Unit, error)
ToTimeUnitPtr converts an optional time unit in protobuf to an internal time unit pointer.
Types ¶
type BytesCopyFunc ¶
BytesCopyFunc is the copy key function to execute when copying the key.
type BytesEqualsFunc ¶
BytesEqualsFunc is the equals key function to execute when detecting equality of a key.
type BytesFinalizeFunc ¶
type BytesFinalizeFunc func([]byte)
BytesFinalizeFunc is the finalize key function to execute when finished with a key.
type BytesHashFunc ¶
type BytesHashFunc func([]byte) BytesResultArrayHashMapHash
BytesHashFunc is the hash function to execute when hashing a key.
type BytesResultArrayHashMap ¶
type BytesResultArrayHashMap struct {
// contains filtered or unexported fields
}
BytesResultArrayHashMap uses the genny package to provide a generic hash map that can be specialized by running the following command from this root of the repository: ``` make hashmap-gen pkg=outpkg key_type=Type value_type=Type out_dir=/tmp ``` Or if you would like to use bytes or ident.ID as keys you can use the partially specialized maps to generate your own maps as well: ``` make byteshashmap-gen pkg=outpkg value_type=Type out_dir=/tmp make idhashmap-gen pkg=outpkg value_type=Type out_dir=/tmp ``` This will output to stdout the generated source file to use for your map. It uses linear probing by incrementing the number of the hash created when hashing the identifier if there is a collision. BytesResultArrayHashMap is a value type and not an interface to allow for less painful upgrades when adding/removing methods, it is not likely to need mocking so an interface would not be super useful either.
func NewBytesResultArrayHashMap ¶
func NewBytesResultArrayHashMap(opts BytesResultArrayHashMapOptions) *BytesResultArrayHashMap
NewBytesResultArrayHashMap returns a new byte keyed map.
func (*BytesResultArrayHashMap) Contains ¶
func (m *BytesResultArrayHashMap) Contains(k []byte) bool
Contains returns true if value exists for key, false otherwise, it is shorthand for a call to Get that doesn't return the value.
func (*BytesResultArrayHashMap) Delete ¶
func (m *BytesResultArrayHashMap) Delete(k []byte)
Delete will remove a value set in the map for the specified key.
func (*BytesResultArrayHashMap) Get ¶
func (m *BytesResultArrayHashMap) Get(k []byte) (calculation.ResultArray, bool)
Get returns a value in the map for an identifier if found.
func (*BytesResultArrayHashMap) Iter ¶
func (m *BytesResultArrayHashMap) Iter() map[BytesResultArrayHashMapHash]BytesResultArrayHashMapEntry
Iter provides the underlying map to allow for using a native Go for loop to iterate the map, however callers should only ever read and not write the map.
func (*BytesResultArrayHashMap) Len ¶
func (m *BytesResultArrayHashMap) Len() int
Len returns the number of map entries in the map.
func (*BytesResultArrayHashMap) Reallocate ¶
func (m *BytesResultArrayHashMap) Reallocate()
Reallocate will avoid deleting all keys and reallocate a new map, this is useful if you believe you have a large map and will not need to grow back to a similar size.
func (*BytesResultArrayHashMap) Reset ¶
func (m *BytesResultArrayHashMap) Reset()
Reset will reset the map by simply deleting all keys to avoid allocating a new map.
func (*BytesResultArrayHashMap) Set ¶
func (m *BytesResultArrayHashMap) Set(k []byte, v calculation.ResultArray)
Set will set the value for an identifier.
func (*BytesResultArrayHashMap) SetUnsafe ¶
func (m *BytesResultArrayHashMap) SetUnsafe(k []byte, v calculation.ResultArray, opts SetUnsafeBytesOptions)
SetUnsafe will set the value for an identifier with unsafe options for how the map treats the key.
type BytesResultArrayHashMapEntry ¶
type BytesResultArrayHashMapEntry struct {
// contains filtered or unexported fields
}
BytesResultArrayHashMapEntry is an entry in the map, this is public to support iterating over the map using a native Go for loop.
func (BytesResultArrayHashMapEntry) Key ¶
func (e BytesResultArrayHashMapEntry) Key() []byte
Key returns the map entry key.
func (BytesResultArrayHashMapEntry) Value ¶
func (e BytesResultArrayHashMapEntry) Value() calculation.ResultArray
Value returns the map entry value.
type BytesResultArrayHashMapHash ¶
type BytesResultArrayHashMapHash uint64
BytesResultArrayHashMapHash is the hash for a given map entry, this is public to support iterating over the map using a native Go for loop.
type BytesResultArrayHashMapOptions ¶
BytesResultArrayHashMapOptions provides options used when created the map.
type Calculation ¶
type Calculation struct { FieldPath []string Op calculation.Op }
Calculation represents a calculation object.
type FieldMeta ¶
type FieldMeta struct { FieldPath []string // AllowedTypesBySourceIdx contains the set of field types allowed by the query, // keyed by the field index in the query clause. AllowedTypesBySourceIdx map[int]field.ValueTypeSet }
FieldMeta contains field metadata.
func (*FieldMeta) MergeInPlace ¶
MergeInPlace merges the other field meta into the current field meta. Precondition: m.fieldPath == other.fieldPath. Precondition: The set of source indices in the two metas don't overlap.
type Filter ¶
type Filter struct { FieldPath []string Op filter.Op Value *field.ValueUnion }
Filter is a parsed filter. TODO(xichen): Handle range query.
func (Filter) AllowedFieldTypes ¶
func (f Filter) AllowedFieldTypes() (field.ValueTypeSet, error)
AllowedFieldTypes returns a list of allowed field types given the filter operator and the RHS value if applicable.
type FilterList ¶
type FilterList struct { Filters []Filter FilterCombinator filter.Combinator }
FilterList is a list of parsed filters.
type ForEachSingleKeyResultGroupFn ¶
type ForEachSingleKeyResultGroupFn func(k field.ValueUnion, v calculation.ResultArray) bool
ForEachSingleKeyResultGroupFn is applied against each result group when iterating over result groups.
type GroupedQueryResults ¶
type GroupedQueryResults struct { SingleKey *SingleKeyGroupQueryResults `json:"singleKey"` MultiKey *MultiKeyGroupQueryResults `json:"multiKey"` }
GroupedQueryResults is a union that contains the results for a grouped query. Only one of the fields should be set. This is used to send results back to clients.
func NewGroupedQueryResultsFromProto ¶
func NewGroupedQueryResultsFromProto( pbRes *servicepb.GroupedQueryResults, ) (*GroupedQueryResults, error)
NewGroupedQueryResultsFromProto creates a new grouped query results from grouped query results protobuf message.
type GroupedResults ¶
type GroupedResults struct { // GroupBy contains a list of field paths to group results by. GroupBy [][]string Calculations []Calculation OrderBy []OrderBy // Limit is the limit defined in the raw groupBy query and limits the final number // of results in the response to the client sending the query. Limit int NewCalculationResultArrayFn calculation.NewResultArrayFromValueTypesFn // Field types for ensuring single-type fields. // These are derived from the first result group processed during query execution. GroupByFieldTypes field.ValueTypeArray CalcFieldTypes field.OptionalTypeArray SingleKeyGroups *SingleKeyResultGroups MultiKeyGroups *MultiKeyResultGroups }
GroupedResults is a collection of result groups.
func (*GroupedResults) HasSingleKey ¶
func (r *GroupedResults) HasSingleKey() bool
HasSingleKey returns true if the results are grouped by a single field as the group key.
func (*GroupedResults) IsComplete ¶
func (r *GroupedResults) IsComplete() bool
IsComplete returns true if the query result is complete and can be returned immediately without performing any further subqueries if any. This currently means the result should be unordered and the result collection size has reached the size limit. For ordered results, we should continue performing the subqueries if any since there may be future results that are ordered higher than the current results.
func (*GroupedResults) IsEmpty ¶
func (r *GroupedResults) IsEmpty() bool
IsEmpty returns true if the result collection is empty.
func (*GroupedResults) IsOrdered ¶
func (r *GroupedResults) IsOrdered() bool
IsOrdered returns true if the grouped results are kept in order.
func (*GroupedResults) Len ¶
func (r *GroupedResults) Len() int
Len returns the number of grouped results.
func (*GroupedResults) LimitReached ¶
func (r *GroupedResults) LimitReached() bool
LimitReached returns true if we have collected enough grouped results.
func (*GroupedResults) MarshalJSON ¶
func (r *GroupedResults) MarshalJSON() ([]byte, error)
MarshalJSON marshals the grouped results as a JSON object.
func (*GroupedResults) MergeInPlace ¶
func (r *GroupedResults) MergeInPlace(other *GroupedResults) error
MergeInPlace merges the other grouped results into the current grouped results in place. The other grouped results become invalid after the merge. Precondition: The current grouped results and the other grouped results are generated from the same query.
func (*GroupedResults) NumGroupsLimit ¶
func (r *GroupedResults) NumGroupsLimit() int
NumGroupsLimit is the limit on the maximum total number of unique groups we keep in each intermediate result. For unordered group by queries, this is the same as the result limit. For ordered groupBy queries, this limit is usually set very high so we can accurately keep track of all underlying groups for majority of use cases and achieve a good approximation for extremely high cardinality use cases while protecting the server from using too much resources to track all groups for extremely high cardinality use cases.
func (*GroupedResults) ToProto ¶
func (r *GroupedResults) ToProto() (*servicepb.GroupedQueryResults, error)
ToProto converts the grouped results to grouped results proto messages.
func (*GroupedResults) TrimIfNeeded ¶
func (r *GroupedResults) TrimIfNeeded()
TrimIfNeeded trims the grouped results when needed based on result limit specified in the query.
type InsertionStatus ¶
type InsertionStatus int
InsertionStatus represents an insertion status.
const ( Existent InsertionStatus = iota Inserted RejectedDueToLimit )
A list of supported insertion status.
type MultiKeyGroupQueryResult ¶
type MultiKeyGroupQueryResult struct { Key field.Values `json:"key"` Values calculation.Values `json:"values"` }
MultiKeyGroupQueryResult contains the result for a multi-key group.
func NewMultiKeyGroupedQueryResultFromProto ¶
func NewMultiKeyGroupedQueryResultFromProto( pbRes servicepb.MultiKeyGroupQueryResult, ) (MultiKeyGroupQueryResult, error)
NewMultiKeyGroupedQueryResultFromProto creates a new multi-key grouped query result from protobuf message.
type MultiKeyGroupQueryResults ¶
type MultiKeyGroupQueryResults struct {
Groups []MultiKeyGroupQueryResult `json:"groups"`
}
MultiKeyGroupQueryResults contains the result for a multi-groupBy-key grouped query.
func NewMultiKeyGroupedQueryResultsFromProto ¶
func NewMultiKeyGroupedQueryResultsFromProto( pbRes *servicepb.MultiKeyGroupQueryResults, ) (*MultiKeyGroupQueryResults, error)
NewMultiKeyGroupedQueryResultsFromProto creates a new multi-key grouped query results from protobuf message.
type MultiKeyResultGroups ¶
type MultiKeyResultGroups struct {
// contains filtered or unexported fields
}
MultiKeyResultGroups stores the result mappings keyed on an array of values from multiple fields.
func NewMultiKeyResultGroups ¶
func NewMultiKeyResultGroups( resultArrayProtoType calculation.ResultArray, orderBy []OrderBy, sizeLimit int, initCapacity int, ) (*MultiKeyResultGroups, error)
NewMultiKeyResultGroups creates a new multi key result groups object.
func (*MultiKeyResultGroups) Clear ¶
func (m *MultiKeyResultGroups) Clear()
Clear clears the result groups.
func (*MultiKeyResultGroups) GetOrInsert ¶
func (m *MultiKeyResultGroups) GetOrInsert( key []field.ValueUnion, ) (calculation.ResultArray, InsertionStatus)
GetOrInsert gets the calculation result array from the result for a given key.
- If the key exists, the existing result array is returned with `Existent`.
- If the key does not exist, and the size limit hasn't been reached yet, the key is inserted into the map along with a new calculation result array, and `Inserted`.
- If the key does not exist, and the size limit has already been reached, the key is not inserted, a nil result array is returned with `RejectedDueToLimit`.
NB(xichen): The key is cloned when being inserted into the map.
func (*MultiKeyResultGroups) Len ¶
func (m *MultiKeyResultGroups) Len() int
Len returns the number of keys in the group.
func (*MultiKeyResultGroups) MarshalJSON ¶
func (m *MultiKeyResultGroups) MarshalJSON( numGroups int, topNRequired bool, ) ([]byte, error)
MarshalJSON marshals the multi-key result groups into a JSON object.
func (*MultiKeyResultGroups) MergeInPlace ¶
func (m *MultiKeyResultGroups) MergeInPlace(other *MultiKeyResultGroups)
MergeInPlace merges the other result gruops into the current groups in place. The other result groups become invalid after the merge. Precondition: The two result groups collect results for the same query, and both result groups are under the same size limit.
func (*MultiKeyResultGroups) ToProto ¶
func (m *MultiKeyResultGroups) ToProto( numGroups int, topNRequired bool, ) (*servicepb.MultiKeyGroupQueryResults, error)
ToProto converts multi-key result groups into multi-key result groups proto message.
type OrderBy ¶
type OrderBy struct { FieldType OrderByFieldType FieldIndex int FieldPath []string SortOrder SortOrder }
OrderBy is a field used for ordering results.
type OrderByFieldType ¶
type OrderByFieldType int
OrderByFieldType is the field type used for ordering.
const ( UnknownOrderByFieldType OrderByFieldType = iota RawField GroupByField CalculationField )
A list of supported order-by field types.
type ParseOptions ¶
type ParseOptions struct { FieldPathSeparator byte FieldHashFn hash.StringArrayHashFn TimestampFieldPath []string RawDocSourceFieldPath []string }
ParseOptions provide a set of options for parsing a raw query.
type ParsedGroupedQuery ¶
type ParsedGroupedQuery struct { Namespace string StartNanosInclusive int64 EndNanosExclusive int64 Filters []FilterList GroupBy [][]string Calculations []Calculation OrderBy []OrderBy Limit int // Derived fields. NewCalculationResultArrayFn calculation.NewResultArrayFromValueTypesFn FieldConstraints map[hash.Hash]FieldMeta // Field constraints inferred from query }
ParsedGroupedQuery represents a validated, sanitized group query.
func (*ParsedGroupedQuery) FilterStartIndex ¶
func (q *ParsedGroupedQuery) FilterStartIndex() int
FilterStartIndex returns the start index of fields in query filters if any.
func (*ParsedGroupedQuery) NewGroupedResults ¶
func (q *ParsedGroupedQuery) NewGroupedResults() *GroupedResults
NewGroupedResults creates a new grouped results from the parsed grouped query.
func (*ParsedGroupedQuery) NumFieldsForQuery ¶
func (q *ParsedGroupedQuery) NumFieldsForQuery() int
NumFieldsForQuery returns the total number of fields involved in executing the query. NB: `OrderBy` fields are covered by either `GroupBy` or `Calculations`
func (*ParsedGroupedQuery) NumFilters ¶
func (q *ParsedGroupedQuery) NumFilters() int
NumFilters returns the number of filters in the query.
func (*ParsedGroupedQuery) TimestampFieldIndex ¶
func (q *ParsedGroupedQuery) TimestampFieldIndex() int
TimestampFieldIndex returns the index of the timestamp field.
type ParsedQuery ¶
type ParsedQuery struct { Namespace string StartTimeNanos int64 EndTimeNanos int64 TimeGranularity *time.Duration Filters []FilterList GroupBy [][]string Calculations []Calculation OrderBy []OrderBy Limit int // contains filtered or unexported fields }
ParsedQuery represents a validated, sanitized query object produced from a raw query.
func (*ParsedQuery) GroupedQuery ¶
func (q *ParsedQuery) GroupedQuery() (ParsedGroupedQuery, error)
GroupedQuery returns the parsed grouped query.
func (*ParsedQuery) RawQuery ¶
func (q *ParsedQuery) RawQuery() (ParsedRawQuery, error)
RawQuery returns the parsed raw query.
func (*ParsedQuery) TimeBucketQuery ¶
func (q *ParsedQuery) TimeBucketQuery() (ParsedTimeBucketQuery, error)
TimeBucketQuery returns the parsed time bucket query.
type ParsedRawQuery ¶
type ParsedRawQuery struct { Namespace string StartNanosInclusive int64 EndNanosExclusive int64 Filters []FilterList OrderBy []OrderBy Limit int ValuesLessThanFn field.ValuesLessThanFn ValuesReverseLessThanFn field.ValuesLessThanFn // Derived fields. ResultLessThanFn RawResultLessThanFn ResultReverseLessThanFn RawResultLessThanFn FieldConstraints map[hash.Hash]FieldMeta // Field constraints inferred from query }
ParsedRawQuery represents a validated, sanitized raw query.
func (*ParsedRawQuery) FilterStartIndex ¶
func (q *ParsedRawQuery) FilterStartIndex() int
FilterStartIndex returns the start index of fields in query filters if any.
func (*ParsedRawQuery) NewRawResults ¶
func (q *ParsedRawQuery) NewRawResults() *RawResults
NewRawResults creates a new raw results from the parsed raw query.
func (*ParsedRawQuery) NumFieldsForQuery ¶
func (q *ParsedRawQuery) NumFieldsForQuery() int
NumFieldsForQuery returns the total number of fields involved in executing the query.
func (*ParsedRawQuery) NumFilters ¶
func (q *ParsedRawQuery) NumFilters() int
NumFilters returns the number of filters in the query.
func (*ParsedRawQuery) RawDocSourceFieldIndex ¶
func (q *ParsedRawQuery) RawDocSourceFieldIndex() int
RawDocSourceFieldIndex returns the index of the raw doc source field.
func (*ParsedRawQuery) TimestampFieldIndex ¶
func (q *ParsedRawQuery) TimestampFieldIndex() int
TimestampFieldIndex returns the index of the timestamp field.
type ParsedTimeBucketQuery ¶
type ParsedTimeBucketQuery struct { Namespace string StartNanosInclusive int64 EndNanosExclusive int64 Granularity time.Duration Filters []FilterList // Derived fields. FieldConstraints map[hash.Hash]FieldMeta // Field constraints inferred from query }
ParsedTimeBucketQuery represents a validated, sanitized time bucket query. Query results are a list of time buckets sorted by time in ascending order, each which contains the count of documents whose timestamps fall in the bucket.
func (*ParsedTimeBucketQuery) FilterStartIndex ¶
func (q *ParsedTimeBucketQuery) FilterStartIndex() int
FilterStartIndex returns the start index of fields in query filters if any.
func (*ParsedTimeBucketQuery) NewTimeBucketResults ¶
func (q *ParsedTimeBucketQuery) NewTimeBucketResults() *TimeBucketResults
NewTimeBucketResults creates a new time bucket results from the parsed time bucket query.
func (*ParsedTimeBucketQuery) NumFieldsForQuery ¶
func (q *ParsedTimeBucketQuery) NumFieldsForQuery() int
NumFieldsForQuery returns the total number of fields involved in executing the query.
func (*ParsedTimeBucketQuery) NumFilters ¶
func (q *ParsedTimeBucketQuery) NumFilters() int
NumFilters returns the number of filters in the query.
func (*ParsedTimeBucketQuery) TimestampFieldIndex ¶
func (q *ParsedTimeBucketQuery) TimestampFieldIndex() int
TimestampFieldIndex returns the index of the timestamp field.
type RawCalculation ¶
type RawCalculation struct { Field *string `json:"field"` Op calculation.Op `json:"op"` }
RawCalculation represents a raw calculation object.
func ToCalculation ¶
func ToCalculation(pbCalculation servicepb.Calculation) (RawCalculation, error)
ToCalculation converts a calculation in protobuf to an internal calculation object.
func ToCalculations ¶
func ToCalculations(pbCalculations []servicepb.Calculation) ([]RawCalculation, error)
ToCalculations converts a list of calculation clauses in protobuf to a list of internal calculation objects.
func (RawCalculation) ToProto ¶
func (calc RawCalculation) ToProto() (servicepb.Calculation, error)
ToProto converts a raw calculation to a calculation protobuf message.
type RawCalculations ¶
type RawCalculations []RawCalculation
RawCalculations is a list of raw calculations.
func (RawCalculations) ToProto ¶
func (calcs RawCalculations) ToProto() ([]servicepb.Calculation, error)
ToProto converts a list of raw calculation clauses to a list of calculation protobuf messages.
type RawFilter ¶
type RawFilter struct { Field string `json:"field"` Op filter.Op `json:"op"` Value interface{} `json:"value"` }
RawFilter represents a raw query filter.
type RawFilterList ¶
type RawFilterList struct { Filters RawFilters `json:"filters"` FilterCombinator *filter.Combinator `json:"filter_combinator"` }
RawFilterList is a list of raw filters.
func ToFilterList ¶
func ToFilterList(pbFilterList servicepb.FilterList) (RawFilterList, error)
ToFilterList converts a filter list in protobuf to an internal filter list.
func ToFilterLists ¶
func ToFilterLists(pbFilterLists []servicepb.FilterList) ([]RawFilterList, error)
ToFilterLists converts filter lists in protobuf to a list of internal filter lists.
func (*RawFilterList) ToProto ¶
func (l *RawFilterList) ToProto() (servicepb.FilterList, error)
ToProto converts the raw filter list to a filter list protobuf message.
type RawFilterLists ¶
type RawFilterLists []RawFilterList
RawFilterLists is a list of raw filter list.
func (RawFilterLists) ToProto ¶
func (rl RawFilterLists) ToProto() ([]servicepb.FilterList, error)
ToProto converts a list of raw filter lists to a list of filter lists protobuf messages.
type RawOrderBy ¶
type RawOrderBy struct { Field *string `json:"field"` Op *calculation.Op `json:"op"` Order *SortOrder `json:"order"` }
RawOrderBy represents a list of criteria for ordering results.
func ToOrderBy ¶
func ToOrderBy(pbOrderBy servicepb.OrderBy) (RawOrderBy, error)
ToOrderBy converts an orderBy clauses in protobuf to an internal orderBy object.
func ToOrderByList ¶
func ToOrderByList(pbOrderByList []servicepb.OrderBy) ([]RawOrderBy, error)
ToOrderByList converts a list of orderBy clauses in protobuf to a list of internal orderBy objects.
type RawQueryResults ¶
type RawQueryResults struct {
Raw [][]byte `json:"raw"`
}
RawQueryResults contains the results for a raw query. This is used to send results back to clients.
func NewRawQueryResultsFromProto ¶
func NewRawQueryResultsFromProto( pbRes *servicepb.RawQueryResults, ) (*RawQueryResults, error)
NewRawQueryResultsFromProto creates a new raw query results from corresponding protobuf message.
type RawResult ¶
type RawResult struct { Data []byte // This is the raw doc source data OrderByValues field.Values // For ordering purposes, empty for unsorted raw results }
RawResult is a single raw result returned from a raw query.
func (RawResult) MarshalJSON ¶
MarshalJSON marshals the raw results as a JSON object using the data field.
type RawResultAddOptions ¶
type RawResultAddOptions struct { CopyOnAdd bool CopyFn func(v RawResult) RawResult CopyToFn func(src RawResult, target *RawResult) }
RawResultAddOptions provide the options for adding a value.
type RawResultHeap ¶
type RawResultHeap struct {
// contains filtered or unexported fields
}
RawResultHeap is a heap storing a list of values. The ordering of such items are determined by `lessThanFn`. The smallest item will be at the top of the heap.
func NewRawResultHeap ¶
func NewRawResultHeap( initCapacity int, lessThanFn func(v1, v2 RawResult) bool, ) *RawResultHeap
NewRawResultHeap creates a new values heap.
func (RawResultHeap) Cap ¶
func (h RawResultHeap) Cap() int
Cap returns the heap capacity before a reallocation is needed.
func (RawResultHeap) Len ¶
func (h RawResultHeap) Len() int
Len returns the number of items in the heap.
func (RawResultHeap) Less ¶
func (h RawResultHeap) Less(i, j int) bool
Less returns true if item `i` is less than item `j`.
func (RawResultHeap) Min ¶
func (h RawResultHeap) Min() RawResult
Min returns the "smallest" heap element according to the `lessThan` function.
func (*RawResultHeap) Push ¶
func (h *RawResultHeap) Push(value RawResult)
Push pushes a value onto the heap.
func (RawResultHeap) RawData ¶
func (h RawResultHeap) RawData() []RawResult
RawData returns the underlying backing array in no particular order.
func (*RawResultHeap) Reset ¶
func (h *RawResultHeap) Reset()
Reset resets the internal backing array.
func (*RawResultHeap) SortInPlace ¶
func (h *RawResultHeap) SortInPlace() []RawResult
SortInPlace sorts the heap in place and returns the sorted data, with the smallest element at the end of the returned array. This is done by repeated swapping the smallest element with the last element of the current heap and shrinking the heap size. NB: The heap becomes invalid after this is called.
func (RawResultHeap) Swap ¶
func (h RawResultHeap) Swap(i, j int)
Swap swaps item `i` with item `j`.
type RawResultLessThanFn ¶
RawResultLessThanFn compares two raw results.
type RawResults ¶
type RawResults struct { OrderBy []OrderBy Limit int ValuesLessThanFn field.ValuesLessThanFn ValuesReverseLessThanFn field.ValuesLessThanFn ResultLessThanFn RawResultLessThanFn ResultReverseLessThanFn RawResultLessThanFn // Field types for ensuring single-type fields. // These are derived from the first result group processed during query execution. OrderByFieldTypes field.ValueTypeArray // An unordered list of raw results for raw query that does not have `orderBy` clauses. Unordered []RawResult // An ordered list of raw results that keep the top N raw results according to the // criteria defined by the `orderBy` clauses. Ordered *TopNRawResults // contains filtered or unexported fields }
RawResults is a collection of raw results.
func (*RawResults) AddOrdered ¶
func (r *RawResults) AddOrdered(rr RawResult, opts RawResultAddOptions)
AddOrdered adds a raw result to the ordered result collection. If the results have not reached limit yet, the incoming results are added in order until the limit is reached, after which the incoming results are inserted and the results beyond limit are dropped.
func (*RawResults) AddUnordered ¶
func (r *RawResults) AddUnordered(rr RawResult)
AddUnordered adds a raw result to the unordered result collection. - If the results have not reached limit yet, the incoming result is appended at the end. - Otherwise, the incoming result is dropped.
func (*RawResults) FieldValuesLessThanFn ¶
func (r *RawResults) FieldValuesLessThanFn() field.ValuesLessThanFn
FieldValuesLessThanFn returns the function to compare two set of field values.
func (*RawResults) HasOrderedFilter ¶
func (r *RawResults) HasOrderedFilter() bool
HasOrderedFilter returns true if the raw results supports filtering ordered values. This is used to determine whether the result should be used to fast eliminate ineligible segments by filtering out those whose range fall outside the current result value range.
func (*RawResults) IsComplete ¶
func (r *RawResults) IsComplete() bool
IsComplete returns true if the query result is complete and can be returned immediately without performing any further subqueries if any. This currently means the result should be unordered and the result collection size has reached the size limit. For ordered results, we should continue performing the subqueries if any since there may be future results that are ordered higher than the current results.
func (*RawResults) IsEmpty ¶
func (r *RawResults) IsEmpty() bool
IsEmpty returns true if the result collection is empty.
func (*RawResults) IsOrdered ¶
func (r *RawResults) IsOrdered() bool
IsOrdered returns true if the raw results are kept in order.
func (*RawResults) LimitReached ¶
func (r *RawResults) LimitReached() bool
LimitReached returns true if we have collected enough raw results.
func (*RawResults) MarshalJSON ¶
func (r *RawResults) MarshalJSON() ([]byte, error)
MarshalJSON marshals the raw results as a JSON objedct.
func (*RawResults) MaxOrderByValues ¶
func (r *RawResults) MaxOrderByValues() field.Values
MaxOrderByValues returns the orderBy field values for the largest result in the result collection.
func (*RawResults) MergeInPlace ¶
func (r *RawResults) MergeInPlace(other *RawResults) error
MergeInPlace merges the other raw results into the current raw results in place. The other raw results become invalid after the merge. Precondition: The current raw results and the other raw results are generated from the same query.
func (*RawResults) MinOrderByValues ¶
func (r *RawResults) MinOrderByValues() field.Values
MinOrderByValues returns the orderBy field values for the smallest result in the result collection. NB: Determining the min result requires a linear scan and more expensive than determining the max result values. However this is okay because the limit is usually not too large so linear scan is tolerable. Additionally from an algorithm perspective, keeping the results in a heap and sorting at the end is strictly better than always keeping the results sorted (2NlogN + N vs 3NlogN + 2N per segment), so even with the additional O(N) complexity of a linear scan this is still cheaper than always keeping results sorted, and the resulting data structure is easier to maintain.
func (*RawResults) ToProto ¶
func (r *RawResults) ToProto() *servicepb.RawQueryResults
ToProto converts the raw results to raw results protobuf message. TODO(xichen): Pass in a string array pool here.
type SetUnsafeBytesOptions ¶
SetUnsafeBytesOptions is a set of options to use when setting a value with the SetUnsafe method.
type SetUnsafeOptions ¶
SetUnsafeOptions is a set of options to use when setting a value with the SetUnsafe method.
type SingleKeyGroupQueryResult ¶
type SingleKeyGroupQueryResult struct { Key field.ValueUnion `json:"key"` Values calculation.Values `json:"values"` }
SingleKeyGroupQueryResult contains the result for a single-key group.
func NewSingleKeyGroupedQueryResultFromProto ¶
func NewSingleKeyGroupedQueryResultFromProto( pbRes servicepb.SingleKeyGroupQueryResult, ) (SingleKeyGroupQueryResult, error)
NewSingleKeyGroupedQueryResultFromProto creates a new single-key grouped query result from protobuf message.
type SingleKeyGroupQueryResults ¶
type SingleKeyGroupQueryResults struct {
Groups []SingleKeyGroupQueryResult `json:"groups"`
}
SingleKeyGroupQueryResults contains the results for a single-groupBy-key grouped query.
func NewSingleKeyGroupedQueryResultsFromProto ¶
func NewSingleKeyGroupedQueryResultsFromProto( pbRes *servicepb.SingleKeyGroupQueryResults, ) (*SingleKeyGroupQueryResults, error)
NewSingleKeyGroupedQueryResultsFromProto creates a new single-key grouped query results from protobuf message.
type SingleKeyResultGroups ¶
type SingleKeyResultGroups struct {
// contains filtered or unexported fields
}
SingleKeyResultGroups stores the result mappings keyed on values from a single field whose values are of the same type.
func NewSingleKeyResultGroups ¶
func NewSingleKeyResultGroups( keyType field.ValueType, resultArrayProtoType calculation.ResultArray, orderBy []OrderBy, sizeLimit int, initCapacity int, ) (*SingleKeyResultGroups, error)
NewSingleKeyResultGroups creates a new single key result groups.
func (*SingleKeyResultGroups) Clear ¶
func (m *SingleKeyResultGroups) Clear()
Clear clears the result groups.
func (*SingleKeyResultGroups) GetOrInsertNoCheck ¶
func (m *SingleKeyResultGroups) GetOrInsertNoCheck( key *field.ValueUnion, ) (calculation.ResultArray, InsertionStatus)
GetOrInsertNoCheck gets the calculation result array from the result for a given key.
- If the key exists, the existing result array is returned with `Existent`.
- If the key does not exist, and the size limit hasn't been reached yet, the key is inserted into the map along with a new calculation result array, and `Inserted`.
- If the key does not exist, and the size limit has already been reached, the key is not inserted, a nil result array is returned with `RejectedDueToLimit`.
NB: No check is performed to ensure the incoming key is not null and has the same type as that associated with the map for performance reasons. NB: The caller should guarantee the key to insert is not null and guaranteed to have the same type as that in the result map.
func (*SingleKeyResultGroups) Len ¶
func (m *SingleKeyResultGroups) Len() int
Len returns the number of keys in the group.
func (*SingleKeyResultGroups) MarshalJSON ¶
func (m *SingleKeyResultGroups) MarshalJSON(numGroups int, topNRequired bool) ([]byte, error)
MarshalJSON marshals `numGroups` result groups as a JSON object. If `topNRequired` is true, top N groups are selected based on the corresponding `ReverseLessThanFn`. Otherwise, an arbitrary set of groups is selected.
func (*SingleKeyResultGroups) MergeInPlace ¶
func (m *SingleKeyResultGroups) MergeInPlace(other *SingleKeyResultGroups)
MergeInPlace merges the other result gruops into the current groups in place. The other result groups become invalid after the merge. Precondition: The two result groups collect results for the same query, and as such both result groups have the same key type and are under the same size limit.
func (*SingleKeyResultGroups) ToProto ¶
func (m *SingleKeyResultGroups) ToProto( numGroups int, topNRequired bool, ) *servicepb.SingleKeyGroupQueryResults
ToProto converts the single key result groups to single key result groups proto message.
type SortOrder ¶
type SortOrder int
SortOrder represents a sort order.
func ToSortOrder ¶
ToSortOrder converts a sort order in protobuf to an internal sort order.
func ToSortOrderPtr ¶
func ToSortOrderPtr( pbSortOrder servicepb.OptionalSortOrder, ) (*SortOrder, error)
ToSortOrderPtr converts an optional sort order in protobuf to an internal sort order pointer.
func (SortOrder) CompareBoolFn ¶
func (f SortOrder) CompareBoolFn() (compare.BoolCompareFn, error)
CompareBoolFn compares two boolean values.
func (SortOrder) CompareBytesFn ¶
func (f SortOrder) CompareBytesFn() (compare.BytesCompareFn, error)
CompareBytesFn compares two string values.
func (SortOrder) CompareCalcValue ¶
func (f SortOrder) CompareCalcValue(v1, v2 calculation.ValueUnion) (int, error)
CompareCalcValue compares two calculation values.
func (SortOrder) CompareCalcValueFn ¶
func (f SortOrder) CompareCalcValueFn() (calculation.ValueCompareFn, error)
CompareCalcValueFn returns the function to compare two calculation values.
func (SortOrder) CompareDoubleFn ¶
func (f SortOrder) CompareDoubleFn() (compare.DoubleCompareFn, error)
CompareDoubleFn compares two double values.
func (SortOrder) CompareFieldValue ¶
func (f SortOrder) CompareFieldValue(v1, v2 field.ValueUnion) (int, error)
CompareFieldValue compares two field values.
func (SortOrder) CompareFieldValueFn ¶
func (f SortOrder) CompareFieldValueFn() (field.ValueCompareFn, error)
CompareFieldValueFn returns the function to compare two field values.
func (SortOrder) CompareIntFn ¶
func (f SortOrder) CompareIntFn() (compare.IntCompareFn, error)
CompareIntFn compares two int values.
func (SortOrder) CompareTimeFn ¶
func (f SortOrder) CompareTimeFn() (compare.TimeCompareFn, error)
CompareTimeFn compares two time values.
func (SortOrder) MustCompareCalcValue ¶
func (f SortOrder) MustCompareCalcValue(v1, v2 calculation.ValueUnion) int
MustCompareCalcValue compares two calculation values, and panics if an error is encountered.
func (SortOrder) MustCompareFieldValue ¶
func (f SortOrder) MustCompareFieldValue(v1, v2 field.ValueUnion) int
MustCompareFieldValue compares two field values, or panics if an error is encountered.
func (*SortOrder) ToProto ¶
func (f *SortOrder) ToProto() (servicepb.OptionalSortOrder, error)
ToProto converts a sort order to an optional sort order protobuf message.
func (*SortOrder) UnmarshalJSON ¶
UnmarshalJSON unmarshals a JSON object as a sort order.
type TimeBucketQueryResult ¶
type TimeBucketQueryResult struct { StartAtNanos int64 `json:"startAtNanos"` // Start time of the bucket in nanoseconds Value int `json:"value"` // Count }
TimeBucketQueryResult contains the query result for a single time bucket. This is used to send results back to clients.
type TimeBucketQueryResults ¶
type TimeBucketQueryResults struct { GranularityNanos int64 `json:"granularity"` Buckets []TimeBucketQueryResult `json:"buckets"` }
TimeBucketQueryResults contains the results for a time bucket query.
func NewTimeBucketQueryResultsFromProto ¶
func NewTimeBucketQueryResultsFromProto( pbRes *servicepb.TimeBucketQueryResults, ) (*TimeBucketQueryResults, error)
NewTimeBucketQueryResultsFromProto creates a new time bucket query results from corresponding protobuf message.
type TimeBucketResults ¶
type TimeBucketResults struct { StartBucketNanos int64 // Inclusive BucketSizeNanos int64 NumBuckets int // contains filtered or unexported fields }
TimeBucketResults is a collection of time buckets recording the counts for documents falling in each bucket.
func (*TimeBucketResults) AddAt ¶
func (r *TimeBucketResults) AddAt(timestampNanos int64)
AddAt adds a document at the given timestamp.
func (*TimeBucketResults) Clear ¶
func (r *TimeBucketResults) Clear()
Clear clears the grouped results.
func (*TimeBucketResults) IsEmpty ¶
func (r *TimeBucketResults) IsEmpty() bool
IsEmpty returns true if the result has not collected any values.
func (*TimeBucketResults) MarshalJSON ¶
func (r *TimeBucketResults) MarshalJSON() ([]byte, error)
MarshalJSON marshals the time bucket results as a JSON object.
func (*TimeBucketResults) MergeInPlace ¶
func (r *TimeBucketResults) MergeInPlace(other *TimeBucketResults) error
MergeInPlace merges the other results into the current results in place. The other results become invalid after the merge. Precondition: The current results and the other results are generated from the same query.
func (*TimeBucketResults) ToProto ¶
func (r *TimeBucketResults) ToProto() *servicepb.TimeBucketQueryResults
ToProto converts the time bucket results to time bucket results proto message.
type TopNRawResults ¶
type TopNRawResults struct {
// contains filtered or unexported fields
}
TopNRawResults keeps track of the top n values in a value sequence for the order defined by the `lessThanFn`. In particular if `lessThanFn` defines an increasing order (returning true if `v1` < `v2`), the collection stores the top N largest values, and vice versa.
func NewTopNRawResults ¶
func NewTopNRawResults( n int, lessThanFn func(v1, v2 RawResult) bool, ) *TopNRawResults
NewTopNRawResults creates a new top n value collection.
func (*TopNRawResults) Add ¶
func (v *TopNRawResults) Add(val RawResult, opts RawResultAddOptions)
Add adds a value to the collection.
func (TopNRawResults) Len ¶
func (v TopNRawResults) Len() int
Len returns the number of items in the collection.
func (TopNRawResults) RawData ¶
func (v TopNRawResults) RawData() []RawResult
RawData returns the underlying array backing the heap in no particular order.
func (*TopNRawResults) Reset ¶
func (v *TopNRawResults) Reset()
Reset resets the internal array backing the heap.
func (*TopNRawResults) SortInPlace ¶
func (v *TopNRawResults) SortInPlace() []RawResult
SortInPlace sorts the backing heap in place and returns the sorted data. NB: The value collection becomes invalid after this is called.
func (TopNRawResults) Top ¶
func (v TopNRawResults) Top() RawResult
Top returns the "smallest" value according to the `lessThan` function.
type Type ¶
type Type int
Type is the type of a query.
const ( // RawQuery is a query that retrieves raw documents without grouping, // returning a list of raw documents with optional ordering applied. RawQuery Type = iota // GroupedQuery is a query that groups documents by fields and applies // calculations within each group, returning the grouped calculation results. GroupedQuery // TimeBucketQuery is a query that bucketizes the query time range into // time buckets and counts the number of documents falling into each bucket, // returning a list of counts ordered by time in ascending order. TimeBucketQuery )
A list of supported query types.
type UnparsedGroupedQuery ¶
type UnparsedGroupedQuery UnparsedQuery
UnparsedGroupedQuery is an unparsed grouped query.
func ToUnparsedGroupedQuery ¶
func ToUnparsedGroupedQuery( q *servicepb.GroupedQuery, ) (UnparsedGroupedQuery, error)
ToUnparsedGroupedQuery converts a grouped query represented in protobuf to an unparsed grouped
func (*UnparsedGroupedQuery) Parse ¶
func (q *UnparsedGroupedQuery) Parse(opts ParseOptions) (ParsedGroupedQuery, error)
Parse parses an unparsed grouped query into a parsed grouped query.
func (*UnparsedGroupedQuery) ToProto ¶
func (q *UnparsedGroupedQuery) ToProto() (*servicepb.GroupedQuery, error)
ToProto converts an unparsed grouped query to an unparsed grouped query protobuf message.
type UnparsedQuery ¶
type UnparsedQuery struct { // Namespace the query will be executed against. // NB: This does not allow cross-namespace searches, but fine for now. Namespace string `json:"namespace"` // Time range portion of the query. StartTime *int64 `json:"start_time"` EndTime *int64 `json:"end_time"` TimeUnit *xtime.Unit `json:"time_unit"` TimeRange *xtime.Duration `json:"time_range"` TimeGranularity *xtime.Duration `json:"time_granularity"` // Filters. Filters RawFilterLists `json:"filters"` // A list of fields to group the results by. GroupBy []string `json:"group_by"` // A list of calculations to perform within each group. // If no groups are specified, the calculations are performed against // the entire group. Calculations RawCalculations `json:"calculations"` // A list of criteria to order the results by. Each criteria must appear // either in the group by list or in the calculations list. OrderBy RawOrderBys `json:"order_by"` // Maximum number of results returned. Limit *int `json:"limit"` }
UnparsedQuery represents an unparsed document query useful for serializing/deserializing in JSON.
func (*UnparsedQuery) Parse ¶
func (q *UnparsedQuery) Parse(opts ParseOptions) (ParsedQuery, error)
Parse parses the raw query, returning any errors encountered.
type UnparsedRawQuery ¶
type UnparsedRawQuery UnparsedQuery
UnparsedRawQuery is an unparsed raw query.
func ToUnparsedRawQuery ¶
func ToUnparsedRawQuery( q *servicepb.RawQuery, ) (UnparsedRawQuery, error)
ToUnparsedRawQuery converts a raw query represented in protobuf to an unparsed raw query.
func (*UnparsedRawQuery) Parse ¶
func (q *UnparsedRawQuery) Parse(opts ParseOptions) (ParsedRawQuery, error)
Parse parses an unparsed raw query into a parsed raw query.
type UnparsedTimeBucketQuery ¶
type UnparsedTimeBucketQuery UnparsedQuery
UnparsedTimeBucketQuery is an unparsed time bucket query.
func ToUnparsedTimeBucketQuery ¶
func ToUnparsedTimeBucketQuery( q *servicepb.TimeBucketQuery, ) (UnparsedTimeBucketQuery, error)
ToUnparsedTimeBucketQuery converts a time bucket query represented in protobuf to an unparsed time bucket
func (*UnparsedTimeBucketQuery) Parse ¶
func (q *UnparsedTimeBucketQuery) Parse(opts ParseOptions) (ParsedTimeBucketQuery, error)
Parse parses an unparsed grouped query into a parsed grouped query.
func (*UnparsedTimeBucketQuery) ToProto ¶
func (q *UnparsedTimeBucketQuery) ToProto() (*servicepb.TimeBucketQuery, error)
ToProto converts an unparsed time bucket query to an unparsed time bucket query protobuf message.
type ValuesCopyFunc ¶
ValuesCopyFunc is the copy key function to execute when copying the key.
type ValuesEqualsFunc ¶
ValuesEqualsFunc is the equals key function to execute when detecting equality of a key.
type ValuesFinalizeFunc ¶
ValuesFinalizeFunc is the finalize key function to execute when finished with a key.
type ValuesHashFunc ¶
type ValuesHashFunc func(field.Values) ValuesResultArrayHashHash
ValuesHashFunc is the hash function to execute when hashing a key.
type ValuesResultArrayHash ¶
type ValuesResultArrayHash struct {
// contains filtered or unexported fields
}
ValuesResultArrayHash uses the genny package to provide a generic hash map that can be specialized by running the following command from this root of the repository: ``` make hashmap-gen pkg=outpkg key_type=Type value_type=Type out_dir=/tmp ``` Or if you would like to use bytes or ident.ID as keys you can use the partially specialized maps to generate your own maps as well: ``` make byteshashmap-gen pkg=outpkg value_type=Type out_dir=/tmp make idhashmap-gen pkg=outpkg value_type=Type out_dir=/tmp ``` This will output to stdout the generated source file to use for your map. It uses linear probing by incrementing the number of the hash created when hashing the identifier if there is a collision. ValuesResultArrayHash is a value type and not an interface to allow for less painful upgrades when adding/removing methods, it is not likely to need mocking so an interface would not be super useful either.
func NewValuesResultArrayMap ¶
func NewValuesResultArrayMap(initialSize int) *ValuesResultArrayHash
NewValuesResultArrayMap creates a new values result array map.
func (*ValuesResultArrayHash) Contains ¶
func (m *ValuesResultArrayHash) Contains(k field.Values) bool
Contains returns true if value exists for key, false otherwise, it is shorthand for a call to Get that doesn't return the value.
func (*ValuesResultArrayHash) Delete ¶
func (m *ValuesResultArrayHash) Delete(k field.Values)
Delete will remove a value set in the map for the specified key.
func (*ValuesResultArrayHash) Get ¶
func (m *ValuesResultArrayHash) Get(k field.Values) (calculation.ResultArray, bool)
Get returns a value in the map for an identifier if found.
func (*ValuesResultArrayHash) Iter ¶
func (m *ValuesResultArrayHash) Iter() map[ValuesResultArrayHashHash]ValuesResultArrayHashEntry
Iter provides the underlying map to allow for using a native Go for loop to iterate the map, however callers should only ever read and not write the map.
func (*ValuesResultArrayHash) Len ¶
func (m *ValuesResultArrayHash) Len() int
Len returns the number of map entries in the map.
func (*ValuesResultArrayHash) Reallocate ¶
func (m *ValuesResultArrayHash) Reallocate()
Reallocate will avoid deleting all keys and reallocate a new map, this is useful if you believe you have a large map and will not need to grow back to a similar size.
func (*ValuesResultArrayHash) Reset ¶
func (m *ValuesResultArrayHash) Reset()
Reset will reset the map by simply deleting all keys to avoid allocating a new map.
func (*ValuesResultArrayHash) Set ¶
func (m *ValuesResultArrayHash) Set(k field.Values, v calculation.ResultArray)
Set will set the value for an identifier.
func (*ValuesResultArrayHash) SetUnsafe ¶
func (m *ValuesResultArrayHash) SetUnsafe(k field.Values, v calculation.ResultArray, opts SetUnsafeOptions)
SetUnsafe will set the value for an identifier with unsafe options for how the map treats the key.
type ValuesResultArrayHashEntry ¶
type ValuesResultArrayHashEntry struct {
// contains filtered or unexported fields
}
ValuesResultArrayHashEntry is an entry in the map, this is public to support iterating over the map using a native Go for loop.
func (ValuesResultArrayHashEntry) Key ¶
func (e ValuesResultArrayHashEntry) Key() field.Values
Key returns the map entry key.
func (ValuesResultArrayHashEntry) Value ¶
func (e ValuesResultArrayHashEntry) Value() calculation.ResultArray
Value returns the map entry value.
type ValuesResultArrayHashHash ¶
type ValuesResultArrayHashHash uint64
ValuesResultArrayHashHash is the hash for a given map entry, this is public to support iterating over the map using a native Go for loop.
Source Files ¶
- bool_result_group_heap.gen.go
- bytes_result_array_map.gen.go
- bytes_result_array_new_map.gen.go
- bytes_result_group_heap.gen.go
- double_result_group_heap.gen.go
- filter.go
- grouped_query.go
- grouped_result.go
- int_result_group_heap.gen.go
- multi_key_result_group_heap.gen.go
- multi_key_result_groups.go
- parsed_query.go
- proto.go
- raw_query.go
- raw_result.go
- raw_result_heap.gen.go
- result_group.go
- result_groups.go
- single_key_result_groups.go
- sort_order.go
- time_bucket_query.go
- time_bucket_result.go
- time_result_group_heap.gen.go
- unparsed_query.go
- values_result_array_map.gen.go
- values_result_array_new_map.go