Documentation
¶
Overview ¶
Package sql implements the Elasticsearch SQL API: it parses a subset of SQL SELECT, translates it to the zed query DSL and formats the result.
Index ¶
- Constants
- func BuildDSL(stmt *Statement, fields FieldTypes, fetchSize int) (map[string]interface{}, error)
- func BuildQuery(dsl map[string]interface{}) (*meta.ZedQuery, error)
- func ContentType(format string) string
- func ParseFormat(format, accept string) (string, error)
- func Translate(sql string, fetchSize int) (map[string]interface{}, error)
- type Column
- type Condition
- type Error
- type FieldTypes
- type GroupKey
- type OrderKey
- type Response
- type ResultColumn
- type Statement
Constants ¶
const ( FormatJSON = "json" FormatTXT = "txt" FormatCSV = "csv" FormatTSV = "tsv" )
supported response formats.
const ( AggNone = "" AggCountStar = "count_star" AggCount = "value_count" AggCountDistinct = "cardinality" AggSum = "sum" AggAvg = "avg" AggMin = "min" AggMax = "max" )
aggregate kinds, named after the DSL aggregation they translate to.
const ( GroupTerms = "terms" GroupDateHistogram = "date_histogram" GroupHistogram = "histogram" )
GROUP BY kinds, named after the DSL bucket aggregation they translate to.
const DefaultFetchSize = 1000
DefaultFetchSize bounds a SELECT that carries no LIMIT.
const GroupAggName = "groupby"
GroupAggName is the name of the GROUP BY bucket aggregation.
const MaxBuckets = 1000
MaxBuckets bounds the number of groups a GROUP BY query considers.
Variables ¶
This section is empty.
Functions ¶
func BuildDSL ¶
func BuildDSL(stmt *Statement, fields FieldTypes, fetchSize int) (map[string]interface{}, error)
BuildDSL translates a statement into the zed query DSL. fetchSize, when positive, caps the requested number of rows.
func BuildQuery ¶
BuildQuery converts a DSL document into the query object the search engine consumes.
func ContentType ¶
ContentType is the response content type of a format.
func ParseFormat ¶
ParseFormat resolves the response format from the request format (body or query string) and the Accept header.
Types ¶
type Column ¶
type Column struct {
Label string // output name: the alias, or the canonical expression text
Field string // source field, empty for COUNT(*)
Agg string // one of the Agg* constants
Group bool // column is the GROUP BY key
}
Column is one output column of the SELECT.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error marks a SQL request zed cannot answer: a parse failure or an unsupported construct. Handlers render it as HTTP 400.
type FieldTypes ¶
FieldTypes maps a field name to its zed mapping type. Unmapped fields resolve to the empty string and are treated as keywords.
type GroupKey ¶
type GroupKey struct {
Label string
Field string
Kind string // one of the Group* constants
Interval string // date_histogram interval, e.g. 1d
Step float64 // histogram interval
}
GroupKey is the single supported GROUP BY key.
type Response ¶
type Response struct {
Columns []ResultColumn `json:"columns"`
Rows [][]interface{} `json:"rows"`
}
Response is the result of a SQL query, in the Elasticsearch SQL shape.
type ResultColumn ¶
ResultColumn describes one output column.