query

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2021 License: MIT Imports: 4 Imported by: 2

Documentation

Overview

Package query provides the datatypes for construction queries and working with their results.

The base for every query is the Query type:

q := query.Query{
	// ...
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aggregation

type Aggregation struct {
	// Op is the operation of the aggregation.
	Op AggregationOp `json:"op"`
	// Field the aggregation operation is performed on.
	Field string `json:"field"`
	// Argument to the aggregation. Only valid for OpTopk and OpPercentiles
	// aggregations.
	Argument interface{} `json:"argument"`
}

Aggregation performed as part of a query.

type AggregationOp

type AggregationOp string

An AggregationOp can be applied on queries to aggrgate based on different conditions.

const (
	// Works with all types, field should be `*`.
	OpCount         AggregationOp = "count"
	OpCountDistinct AggregationOp = "distinct"

	// Only works for numbers.
	OpSum         AggregationOp = "sum"
	OpAvg         AggregationOp = "avg"
	OpMin         AggregationOp = "min"
	OpMax         AggregationOp = "max"
	OpTopk        AggregationOp = "topk"
	OpPercentiles AggregationOp = "percentiles"
	OpHistogram   AggregationOp = "histogram"
)

All available query aggregation operations.

type Entry

type Entry struct {
	// Time is the time the event occurred. Matches SysTime if not specified
	// during ingestion.
	Time time.Time `json:"_time"`
	// SysTime is the time the event was recorded on the server.
	SysTime time.Time `json:"_sysTime"`
	// RowID is the unique ID of the event row.
	RowID string `json:"_rowId"`
	// Data contains the raw data of the event (with filters and aggregations
	// applied).
	Data map[string]interface{} `json:"data"`
}

Entry is an event that matched a query and is thus part of the result set.

type EntryGroup

type EntryGroup struct {
	// ID is the unique the group.
	ID uint64 `json:"id"`
	// Group maps the fieldnames to the unique values for the entry.
	Group map[string]interface{} `json:"group"`
	// Aggregations of the group.
	Aggregations []EntryGroupAgg `json:"aggregations"`
}

EntryGroup is a group of queried event.

type EntryGroupAgg

type EntryGroupAgg struct {
	// Op is the aggregations operation.
	Op AggregationOp `json:"op"`
	// Value is the result value of the aggregation.
	Value interface{} `json:"value"`
}

EntryGroupAgg is an aggregation which is part of a group of queried events.

type Filter

type Filter struct {
	// Op is the operation of the filter.
	Op FilterOp `json:"op"`
	// Field the filter operation is performed on.
	Field string `json:"field"`
	// Value to perform the filter operation against.
	Value interface{} `json:"value"`
	// CaseSensitive specifies if the filter is case sensitive or not. Only
	// valid for OpStartsWith, OpNotStartsWith, OpEndsWith, OpNotEndsWith,
	// OpContains and OpNotContains.
	CaseSensitive bool `json:"caseSensitive"`
	// Children specifies child filters for the filter. Only valid for OpAnd,
	// OpOr and OpNot.
	Children []Filter `json:"children"`
}

Filter applied as part of a query.

type FilterOp

type FilterOp string

A FilterOp can be applied on queries to filter based on different conditions.

const (
	OpAnd FilterOp = "and"
	OpOr  FilterOp = "or"
	OpNot FilterOp = "not"

	// Works for strings and numbers.
	OpEqual     FilterOp = "=="
	OpNotEqual  FilterOp = "!="
	OpExists    FilterOp = "exists"
	OpNotExists FilterOp = "not-exists"

	// Only works for numbers.
	OpGreaterThan      FilterOp = ">"
	OpGreaterThanEqual FilterOp = ">="
	OpLessThan         FilterOp = "<"
	OpLessThanEqual    FilterOp = "<="

	// Only works for strings.
	OpStartsWith    FilterOp = "starts-with"
	OpNotStartsWith FilterOp = "not-starts-with"
	OpEndsWith      FilterOp = "ends-with"
	OpNotEndsWith   FilterOp = "not-ends-with"
	OpRegexp        FilterOp = "regexp"
	OpNotRegexp     FilterOp = "not-regexp"

	// Works for strings and arrays.
	OpContains    FilterOp = "contains"
	OpNotContains FilterOp = "not-contains"
)

All available query filter operations.

type Interval

type Interval struct {
	// StartTime of the interval.
	StartTime time.Time `json:"startTime"`
	// EndTime of the interval.
	EndTime time.Time `json:"endTime"`
	// Groups of the interval.
	Groups []EntryGroup `json:"groups"`
}

Interval is the interval of queried time series.

type Message

type Message struct {
	// Priority of the message.
	Priority MessagePriority `json:"priority"`
	// Count describes how often a message of this type was raised by the query.
	Count uint `json:"count"`
	// Code of the message.
	Code MessageCode `json:"code"`
	// Text is a human readable text representation of the message.
	Text string `json:"msg"`
}

Message is a message associated with a query result.

type MessageCode

type MessageCode uint8

MessageCode represents the code of a message associated with a query.

const (
	VirtualFieldFinalizeError   MessageCode = iota + 1 // virtual_field_finalize_error
	MissingColumn                                      // missing_column
	LicenseLimitForQueryWarning                        // license_limit_for_query_warning
)

All available message codes.

func (MessageCode) String

func (i MessageCode) String() string

func (*MessageCode) UnmarshalJSON

func (mc *MessageCode) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler. It is in place to unmarshal the MessageCode from the string representation the server returns.

type MessagePriority

type MessagePriority uint8

MessagePriority represents the priority of a message associated with a query.

const (
	Trace MessagePriority = iota + 1 // trace
	Debug                            // debug
	Info                             // info
	Warn                             // warn
	Error                            // error
	Fatal                            // fatal
)

All available message priorities.

func (MessagePriority) String

func (i MessagePriority) String() string

func (*MessagePriority) UnmarshalJSON

func (mp *MessagePriority) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler. It is in place to unmarshal the MessagePriority from the string representation the server returns.

type Options

type Options struct {
	// StreamingDuration of a query.
	StreamingDuration time.Duration `url:"streaming-duration,omitempty"`
	// NoCache omits the query cache.
	NoCache bool `url:"no-cache,omitempty"`
}

Options specifies the parameters for the Query method of the Datasets service.

type Order

type Order struct {
	// Field to order on.
	Field string `json:"field"`
	// Desc specifies if the field is ordered ascending or descending.
	Desc bool `json:"desc"`
}

Order specifies the order a queries result will be in.

type Projection

type Projection struct {
	// Field to project to the query result.
	Field string `json:"field"`
	// Alias to reference the projected field by. Optional.
	Alias string `json:"alias"`
}

A Projection is a field that is projected to the query result.

type Query

type Query struct {
	// StartTime of the query. Required.
	StartTime time.Time `json:"startTime"`
	// EndTime of the query. Required.
	EndTime time.Time `json:"endTime"`
	// Resolution of the queries graph. Valid values are the queries time
	// range / 100 at maximum and / 1000 at minimum. Use zero value for
	// serve-side auto-detection.
	Resolution time.Duration `json:"resolution"`
	// Aggregations performed as part of the query.
	Aggregations []Aggregation `json:"aggregations"`
	// Filter applied on the queried results.
	Filter Filter `json:"filter"`
	// GroupBy is a list of field names to group the query result by.
	GroupBy []string `json:"groupBy"`
	// Order is a list of order rules that specify the order of the query
	// result.
	Order []Order `json:"order"`
	// Limit the amount of results returned from the query.
	Limit uint32 `json:"limit"`
	// VirtualFields is a list of virtual fields that can be referenced by
	// aggregations, filters and orders.
	VirtualFields []VirtualField `json:"virtualFields"`
	// Projections is a list of projections that can be referenced by
	// aggregations, filters and orders. Leaving it empty projects all available
	// fields to the query result.
	Projections []Projection `json:"project"`
	// Cursor is the query cursor. It should be set to the Cursor returned with
	// a previous query result if it was partial.
	Cursor string `json:"cursor"`
	// ContinuationToken is used to get more results of a previous query. It is
	// not valid for starred queries or otherwise stored queries.
	ContinuationToken string `json:"continuationToken"`
}

Query represents a query that gets executed on a dataset.

func (Query) MarshalJSON

func (q Query) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It is in place to marshal the Resolutions zero value to its proper string representation because that's what the server expects.

func (*Query) UnmarshalJSON

func (q *Query) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler. It is in place to unmarshal the Resolutionstring value to a proper time.Duration because that's what the server returns.

type Result

type Result struct {
	// Status of the query result.
	Status Status `json:"status"`
	// Matches are the events that matched the query.
	Matches []Entry `json:"matches"`
	// Buckets are the time series buckets.
	Buckets Timeseries `json:"buckets"`
}

Result is the result of a query.

type Status

type Status struct {
	// ElapsedTime is the duration it took the query to execute.
	ElapsedTime time.Duration `json:"elapsedTime"`
	// BlocksExamined is the amount of blocks that have been examined by the
	// query.
	BlocksExamined uint64 `json:"blocksExamined"`
	// RowsExamined is the amount of rows that have been examined by the query.
	RowsExamined uint64 `json:"rowsExamined"`
	// RowsMatched is the amount of rows that matched the query.
	RowsMatched uint64 `json:"rowsMatched"`
	// NumGroups is the amount of groups returned by the query.
	NumGroups uint32 `json:"numGroups"`
	// IsPartial describes if the query result is a partial result.
	IsPartial bool `json:"isPartial"`
	// ContinuationToken is populated when IsPartial is true and must be passed
	// to the next query request to retrieve the next result set.
	ContinuationToken string `json:"continuationToken"`
	// IsEstimate describes if the query result is estimated.
	IsEstimate bool `json:"isEstimate"`
	// MinBlockTime is the timestamp of the oldest block examined.
	MinBlockTime time.Time `json:"minBlockTime"`
	// MaxBlockTime is the timestamp of the newest block examined.
	MaxBlockTime time.Time `json:"maxBlockTime"`
	// Messages associated with the query.
	Messages []Message `json:"messages"`
}

Status is the status of a query result.

func (Status) MarshalJSON

func (s Status) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It is in place to marshal the ElapsedTime into its microsecond representation because that's what the server expects.

func (*Status) UnmarshalJSON

func (s *Status) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler. It is in place to unmarshal the ElapsedTime into a proper time.Duration value because the server returns it in microseconds.

type Timeseries

type Timeseries struct {
	// Series are the intervals that build a time series.
	Series []Interval `json:"series"`
	// Totals of the time series.
	Totals []EntryGroup `json:"totals"`
}

Timeseries are queried time series.

type VirtualField

type VirtualField struct {
	// Alias the virtual field is referenced by.
	Alias string `json:"alias"`
	// Expression which specifies the virtual fields value.
	Expression string `json:"expr"`
}

A VirtualField is not part of a dataset and its value is derived from an expression. Aggregations, filters and orders can reference this field like any other field.

Jump to

Keyboard shortcuts

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