Documentation ¶
Index ¶
- func ExpressionToString(e *Expression) (string, error)
- type AST
- type Condition
- type Dimension
- type DimensionCompute
- type DimensionComputeTimeFloor
- type Executor
- func (e *Executor) Cacheable(qry *Query) bool
- func (e *Executor) Close()
- func (e *Executor) Export(ctx context.Context, qry *Query, executionTime *time.Time, ...) (string, error)
- func (e *Executor) Query(ctx context.Context, qry *Query, executionTime *time.Time) (*drivers.Result, error)
- func (e *Executor) Schema(ctx context.Context) (*runtimev1.StructType, error)
- func (e *Executor) Search(ctx context.Context, qry *SearchQuery, executionTime *time.Time) ([]SearchResult, error)
- func (e *Executor) ValidateMetricsView(ctx context.Context) error
- func (e *Executor) ValidateQuery(qry *Query) error
- func (e *Executor) Watermark(ctx context.Context) (time.Time, error)
- type ExprNode
- type Expression
- type FieldNode
- type JoinType
- type Measure
- type MeasureCompute
- type MeasureComputeComparisonDelta
- type MeasureComputeComparisonRatio
- type MeasureComputeComparisonValue
- type MeasureComputeCountDistinct
- type MeasureComputePercentOfTotal
- type MeasureComputeURI
- type Operator
- type OrderFieldNode
- type Query
- type SearchQuery
- type SearchResult
- type SelectNode
- type Sort
- type Spine
- type Subquery
- type TimeGrain
- type TimeRange
- type TimeSpine
- type WhereSpine
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExpressionToString ¶
func ExpressionToString(e *Expression) (string, error)
Types ¶
type AST ¶
type AST struct { // Root of the AST Root *SelectNode // List of CTEs to add to the query CTEs []*SelectNode // contains filtered or unexported fields }
AST is the abstract syntax tree for a metrics SQL query.
func NewAST ¶
func NewAST(mv *runtimev1.MetricsViewSpec, sec *runtime.ResolvedSecurity, qry *Query, dialect drivers.Dialect) (*AST, error)
NewAST builds a new SQL AST based on a metrics query.
Dynamic time ranges in the qry must be resolved to static start/end timestamps before calling this function. This is due to NewAST not being able (or intended) to resolve external time anchors such as watermarks.
The qry's PivotOn must be empty. Pivot queries must be rewritten/handled upstream of NewAST.
type Condition ¶
type Condition struct { Operator Operator `mapstructure:"op"` Expressions []*Expression `mapstructure:"exprs"` }
type Dimension ¶
type Dimension struct { Name string `mapstructure:"name"` Compute *DimensionCompute `mapstructure:"compute"` }
type DimensionCompute ¶
type DimensionCompute struct {
TimeFloor *DimensionComputeTimeFloor `mapstructure:"time_floor"`
}
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor is capable of executing queries and other operations against a metrics view.
func NewExecutor ¶
func NewExecutor(ctx context.Context, rt *runtime.Runtime, instanceID string, mv *runtimev1.MetricsViewSpec, sec *runtime.ResolvedSecurity, priority int) (*Executor, error)
NewExecutor creates a new Executor for the provided metrics view.
func (*Executor) Cacheable ¶ added in v0.48.0
Cacheable returns whether the result of running the given query is cacheable.
func (*Executor) Close ¶
func (e *Executor) Close()
Close releases the resources held by the Executor.
func (*Executor) Export ¶
func (e *Executor) Export(ctx context.Context, qry *Query, executionTime *time.Time, format drivers.FileFormat) (string, error)
Export executes and exports the provided query against the metrics view. It returns a path to a temporary file containing the export. The caller is responsible for cleaning up the file.
func (*Executor) Query ¶
func (e *Executor) Query(ctx context.Context, qry *Query, executionTime *time.Time) (*drivers.Result, error)
Query executes the provided query against the metrics view.
func (*Executor) Search ¶ added in v0.49.0
func (e *Executor) Search(ctx context.Context, qry *SearchQuery, executionTime *time.Time) ([]SearchResult, error)
SearchQuery executes the provided query against the metrics view.
func (*Executor) ValidateMetricsView ¶
ValidateMetricsView validates the dimensions and measures in the executor's metrics view.
func (*Executor) ValidateQuery ¶
ValidateQuery validates the provided query against the executor's metrics view.
type Expression ¶
type Expression struct { Name string `mapstructure:"name"` Value any `mapstructure:"val"` Condition *Condition `mapstructure:"cond"` Subquery *Subquery `mapstructure:"subquery"` }
func NewExpressionFromProto ¶
func NewExpressionFromProto(expr *runtimev1.Expression) *Expression
type FieldNode ¶
FieldNode represents a column in a SELECT clause. It also carries metadata related to the dimension/measure it was derived from. The Name must always match a the name of a dimension/measure in the metrics view or a computed field specified in the request. This means that if two columns in different places in the AST have the same Name, they're guaranteed to resolve to the same value.
type Measure ¶
type Measure struct { Name string `mapstructure:"name"` Compute *MeasureCompute `mapstructure:"compute"` }
type MeasureCompute ¶
type MeasureCompute struct { Count bool `mapstructure:"count"` CountDistinct *MeasureComputeCountDistinct `mapstructure:"count_distinct"` ComparisonValue *MeasureComputeComparisonValue `mapstructure:"comparison_value"` ComparisonDelta *MeasureComputeComparisonDelta `mapstructure:"comparison_delta"` ComparisonRatio *MeasureComputeComparisonRatio `mapstructure:"comparison_ratio"` PercentOfTotal *MeasureComputePercentOfTotal `mapstructure:"percent_of_total"` URI *MeasureComputeURI `mapstructure:"uri"` }
func (*MeasureCompute) Validate ¶
func (m *MeasureCompute) Validate() error
type MeasureComputeComparisonDelta ¶
type MeasureComputeComparisonDelta struct {
Measure string `mapstructure:"measure"`
}
type MeasureComputeComparisonRatio ¶
type MeasureComputeComparisonRatio struct {
Measure string `mapstructure:"measure"`
}
type MeasureComputeComparisonValue ¶
type MeasureComputeComparisonValue struct {
Measure string `mapstructure:"measure"`
}
type MeasureComputeCountDistinct ¶
type MeasureComputeCountDistinct struct {
Dimension string `mapstructure:"dimension"`
}
type MeasureComputePercentOfTotal ¶ added in v0.49.0
type MeasureComputeURI ¶ added in v0.49.0
type MeasureComputeURI struct {
Dimension string `mapstructure:"dimension"`
}
type Operator ¶
type Operator string
const ( OperatorUnspecified Operator = "" OperatorEq Operator = "eq" OperatorNeq Operator = "neq" OperatorLt Operator = "lt" OperatorLte Operator = "lte" OperatorGt Operator = "gt" OperatorGte Operator = "gte" OperatorIn Operator = "in" OperatorNin Operator = "nin" OperatorIlike Operator = "ilike" OperatorNilike Operator = "nilike" OperatorOr Operator = "or" OperatorAnd Operator = "and" )
type OrderFieldNode ¶
OrderFieldNode represents a field in an ORDER BY clause.
type Query ¶
type Query struct { MetricsView string `mapstructure:"metrics_view"` Dimensions []Dimension `mapstructure:"dimensions"` Measures []Measure `mapstructure:"measures"` PivotOn []string `mapstructure:"pivot_on"` Spine *Spine `mapstructure:"spine"` Sort []Sort `mapstructure:"sort"` TimeRange *TimeRange `mapstructure:"time_range"` ComparisonTimeRange *TimeRange `mapstructure:"comparison_time_range"` Where *Expression `mapstructure:"where"` Having *Expression `mapstructure:"having"` Limit *int64 `mapstructure:"limit"` Offset *int64 `mapstructure:"offset"` TimeZone string `mapstructure:"time_zone"` UseDisplayNames bool `mapstructure:"use_display_names"` }
type SearchQuery ¶ added in v0.49.0
type SearchQuery struct { MetricsView string `mapstructure:"metrics_view"` Dimensions []string `mapstructure:"dimensions"` Search string `mapstructure:"search"` Where *Expression `mapstructure:"where"` Having *Expression `mapstructure:"having"` TimeRange *TimeRange `mapstructure:"time_range"` Limit *int64 `mapstructure:"limit"` }
type SearchResult ¶ added in v0.49.0
type SelectNode ¶
type SelectNode struct { Alias string // Alias for the node used by outer SELECTs to reference it. IsCTE bool // Whether this node is a Common Table Expression DimFields []FieldNode // Dimensions fields to select MeasureFields []FieldNode // Measure fields to select FromTable *string // Underlying table expression to select from (if set, FromSelect must not be set) FromSelect *SelectNode // Sub-select to select from (if set, FromTable must not be set) SpineSelect *SelectNode // Sub-select that returns a spine of dimensions. Currently it will be right-joined onto FromSelect. LeftJoinSelects []*SelectNode // Sub-selects to left join onto FromSelect, to enable "per-dimension" measures JoinComparisonSelect *SelectNode // Sub-select to join onto FromSelect for comparison measures JoinComparisonType JoinType // Type of join to use for JoinComparisonSelect Unnests []string // Unnest expressions to add in the FROM clause Group bool // Whether the SELECT is grouped. If yes, it will group by all DimFields. Where *ExprNode // Expression for the WHERE clause TimeWhere *ExprNode // Expression for the time range to add to the WHERE clause Having *ExprNode // Expression for the HAVING clause. If HAVING is not allowed in the current context, it will added as a WHERE in a wrapping SELECT. OrderBy []OrderFieldNode // Fields to order by Limit *int64 // Limit for the query Offset *int64 // Offset for the query }
SelectNode represents a query that computes measures by dimensions. The from/join clauses are not all compatible. The allowed combinations are:
- FromTable
- FromSelect and optionally SpineSelect and/or LeftJoinSelects
- FromSelect and optionally JoinComparisonSelect (for comparison CTE based optimization, this combination is used, both should be set and one of them will be used as CTE)
type Spine ¶
type Spine struct { Where *WhereSpine `mapstructure:"where"` TimeRange *TimeSpine `mapstructure:"time"` }
type Subquery ¶
type Subquery struct { Dimension Dimension `mapstructure:"dimension"` Measures []Measure `mapstructure:"measures"` Where *Expression `mapstructure:"where"` Having *Expression `mapstructure:"having"` }
type TimeGrain ¶
type TimeGrain string
const ( TimeGrainUnspecified TimeGrain = "" TimeGrainMillisecond TimeGrain = "millisecond" TimeGrainSecond TimeGrain = "second" TimeGrainMinute TimeGrain = "minute" TimeGrainHour TimeGrain = "hour" TimeGrainDay TimeGrain = "day" TimeGrainWeek TimeGrain = "week" TimeGrainMonth TimeGrain = "month" TimeGrainQuarter TimeGrain = "quarter" TimeGrainYear TimeGrain = "year" )
func TimeGrainFromProto ¶
func (TimeGrain) ToTimeutil ¶
type TimeRange ¶
type WhereSpine ¶
type WhereSpine struct {
Expression *Expression `mapstructure:"expr"`
}
Source Files ¶
- ast.go
- astexpr.go
- astsql.go
- executor.go
- executor_export.go
- executor_pivot.go
- executor_rewrite_approx_comparisons.go
- executor_rewrite_druid_exactify.go
- executor_rewrite_druid_groups.go
- executor_rewrite_enforce_caps.go
- executor_rewrite_limit_pushdown.go
- executor_rewrite_percent_of_totals.go
- executor_rewrite_time.go
- query.go
- query_expression.go
- query_expression_pb.go