sql

package
v0.0.0-...-df46cc1 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package sql provides the ability to parse SQL queries. This pacakge contains some code taking from the Go standard library's time package. Go is licensed as per https://golang.org/LICENSE.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSelectNoName                  = errors.New("All expressions in SELECT must either reference a column name or include an AS alias")
	ErrIfArity                       = errors.New("IF requires two parameters, like IF(dim = 1, SUM(b))")
	ErrBoundedArity                  = errors.New("BOUNDED requires three parameters, like BOUNDED(b, 0, 100)")
	ErrPercentileArity               = errors.New("PERCENTILE requires either two or five parameters, like PERCENTILE(b, 99.9, 0, 1000, 3)")
	ErrPercentileOptWrap             = errors.New("PERCENTILE with two parameters may only wrap an existing PERCENTILE expression")
	ErrShiftArity                    = errors.New("SHIFT requires two parameters, like SHIFT(SUM(b), '-1h')")
	ErrCrosshiftArity                = errors.New("CROSSHIFT requires three parameters, like CROSSHIFT(SUM(b), '1h', '-1d')")
	ErrCrosshiftZeroCutoffOrInterval = errors.New("CROSSHIFT cutoff and interval must be non-zero")
	ErrCROSSTABArity                 = errors.New("CROSSTAB requires at least one argument")
	ErrCROSSTABUnique                = errors.New("Only one CROSSTAB statement allowed per query")
	ErrAggregateArity                = errors.New("Aggregate functions take only one parameter, like SUM(b)")
	ErrWildcardNotAllowed            = errors.New("Wildcard * is not supported")
	ErrNestedFunctionCall            = errors.New("Nested function calls are not currently supported in SELECT")
	ErrInvalidPeriod                 = errors.New("Please specify a period in the form period(5s) where 5s can be any valid Go duration expression")
	ErrInvalidStride                 = errors.New("Please specify a stride in the form stride(5s) where 5s can be any valid Go duration expression")
)

Functions

func ParseDuration

func ParseDuration(s string) (time.Duration, error)

ParseDuration parses a duration string. A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".

func RegisterAlias

func RegisterAlias(alias string, template string)

func RegisterUnaryDIMFunction

func RegisterUnaryDIMFunction(name string, fn func(goexpr.Expr) goexpr.Expr) error

func TableFor

func TableFor(sql string) (string, error)

TableFor returns the table in the FROM clause of this query

Types

type Query

type Query struct {
	SQL string
	// Fields are the fields from the SELECT clause in the order they appear,
	// including the synthetic _having field if there's a HAVING clause.
	Fields core.FieldSource
	// FieldsNoHaving is like Fields but without the synthetic HAVING clause
	FieldsNoHaving    core.FieldSource
	HasSelectAll      bool
	HasSpecificFields bool
	// From is the Table from the FROM clause
	From         string
	FromSubQuery *Query
	FromSQL      string
	Resolution   time.Duration
	Where        goexpr.Expr
	WhereSQL     string
	AsOf         time.Time
	AsOfOffset   time.Duration
	Until        time.Time
	UntilOffset  time.Duration
	Stride       time.Duration
	// GroupBy are the GroupBy expressions ordered alphabetically by name.
	GroupBy    []core.GroupBy
	GroupByAll bool
	// Crosstab is the goexpr.Expr used for crosstabs (goes into columns rather than rows)
	Crosstab              goexpr.Expr
	CrosstabIncludesTotal bool
	HasHaving             bool
	HavingSQL             string
	OrderBy               []core.OrderBy
	Offset                int
	Limit                 int
	ForceFresh            bool
}

Query represents the result of parsing a SELECT query.

func Parse

func Parse(sql string) (*Query, error)

Parse parses a SQL statement and returns a corresponding *Query object.

type SubQuery

type SubQuery struct {
	Dim string
	SQL string
	// contains filtered or unexported fields
}

SubQuery is a placeholder for a sub query within a query. Executors of a query should first execute all SubQueries and then call SetResult to set the results of the subquery. The subquery

func (*SubQuery) SetResult

func (sq *SubQuery) SetResult(result []interface{})

func (*SubQuery) Values

func (sq *SubQuery) Values() []goexpr.Expr

Jump to

Keyboard shortcuts

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