Documentation ¶
Index ¶
- Variables
- func FormatSQLTimestamp(t time.Time) string
- type AliasedExpression
- type AndCondition
- type Between
- type Boolean
- type CastFunc
- type Compare
- type Condition
- type ConditionOperand
- type ConditionRHS
- type CountFunc
- type DateAddFunc
- type DateDiffFunc
- type Expression
- type ExtractFunc
- type FuncExpr
- type FuncName
- type Identifier
- type In
- type JSONPath
- type JSONPathElement
- type Like
- type LitValue
- type LiteralString
- type MultOp
- type NegatedTerm
- type ObjectKey
- type OpFactor
- type OpUnaryTerm
- type Operand
- type PrimaryTerm
- type QuotedIdentifier
- type Record
- type Select
- type SelectExpression
- type SelectObjectFormat
- type SelectStatement
- func (e *SelectStatement) AggregateResult(output Record) error
- func (e *SelectStatement) AggregateRow(input Record) error
- func (e *SelectStatement) Eval(input, output Record) (Record, error)
- func (e *SelectStatement) EvalFrom(format string, input Record) (Record, error)
- func (e *SelectStatement) IsAggregated() bool
- func (e *SelectStatement) LimitReached() bool
- type SimpleArgFunc
- type SubstringFunc
- type TableExpression
- type TrimFunc
- type UnaryTerm
- type Value
- func (v *Value) CSVString() string
- func (v *Value) GetTypeString() string
- func (v *Value) IsNull() bool
- func (v *Value) Repr() string
- func (v *Value) ToBool() (val bool, ok bool)
- func (v *Value) ToBytes() ([]byte, bool)
- func (v *Value) ToFloat() (val float64, ok bool)
- func (v *Value) ToInt() (val int64, ok bool)
- func (v *Value) ToString() (val string, ok bool)
- func (v *Value) ToTimestamp() (t time.Time, ok bool)
Constants ¶
This section is empty.
Variables ¶
var ( // SQLParser is used to parse SQL statements SQLParser = participle.MustBuild( &Select{}, participle.Lexer(sqlLexer), participle.CaseInsensitive("Keyword"), participle.CaseInsensitive("Timeword"), ) )
Functions ¶
func FormatSQLTimestamp ¶
FormatSQLTimestamp - returns the a string representation of the timestamp as used in S3 Select
Types ¶
type AliasedExpression ¶
type AliasedExpression struct { Expression *Expression `parser:"@@"` As string `parser:"[ \"AS\" @Ident ]"` }
AliasedExpression is an expression that can be optionally named
type AndCondition ¶
type AndCondition struct {
Condition []*Condition `parser:"@@ ( \"AND\" @@ )*"`
}
AndCondition represents logical conjunction of clauses
type Between ¶
type Between struct { Not bool `parser:" @\"NOT\"? "` Start *Operand `parser:" \"BETWEEN\" @@ "` End *Operand `parser:" \"AND\" @@ "` }
Between represents the RHS of a BETWEEN expression
type CastFunc ¶
type CastFunc struct { Expr *Expression `parser:" \"CAST\" \"(\" @@ "` CastType string `` /* 128-byte string literal not displayed */ }
CastFunc represents CAST sql function
type Compare ¶
type Compare struct { Operator string `parser:"@( \"<>\" | \"<=\" | \">=\" | \"=\" | \"<\" | \">\" | \"!=\" )"` Operand *Operand `parser:" @@"` }
Compare represents the RHS of a comparison expression
type Condition ¶
type Condition struct { Operand *ConditionOperand `parser:" @@"` Not *Condition `parser:"| \"NOT\" @@"` }
Condition represents a negation or a condition operand
type ConditionOperand ¶
type ConditionOperand struct { Operand *Operand `parser:"@@"` ConditionRHS *ConditionRHS `parser:"@@?"` }
ConditionOperand is a operand followed by an an optional operation expression
type ConditionRHS ¶
type ConditionRHS struct { Compare *Compare `parser:" @@"` Between *Between `parser:"| @@"` In *In `parser:"| \"IN\" \"(\" @@ \")\""` Like *Like `parser:"| @@"` }
ConditionRHS represents the right-hand-side of Compare, Between, In or Like expressions.
type CountFunc ¶
type CountFunc struct { StarArg bool `parser:" \"COUNT\" \"(\" ( @\"*\"?"` ExprArg *Expression `parser:" @@? )! \")\""` }
CountFunc represents the COUNT sql function
type DateAddFunc ¶
type DateAddFunc struct { DatePart string `` /* 161-byte string literal not displayed */ Quantity *Operand `parser:" @@ \",\""` Timestamp *PrimaryTerm `parser:" @@ \")\""` }
DateAddFunc represents the DATE_ADD function
type DateDiffFunc ¶
type DateDiffFunc struct { DatePart string `` /* 163-byte string literal not displayed */ Timestamp1 *PrimaryTerm `parser:" @@ \",\" "` Timestamp2 *PrimaryTerm `parser:" @@ \")\" "` }
DateDiffFunc represents the DATE_DIFF function
type Expression ¶
type Expression struct {
And []*AndCondition `parser:"@@ ( \"OR\" @@ )*"`
}
Expression represents a logical disjunction of clauses
type ExtractFunc ¶
type ExtractFunc struct { Timeword string `` /* 215-byte string literal not displayed */ From *PrimaryTerm `parser:" \"FROM\" @@ \")\" "` }
ExtractFunc represents EXTRACT sql function
type FuncExpr ¶
type FuncExpr struct { SFunc *SimpleArgFunc `parser:" @@"` Count *CountFunc `parser:"| @@"` Cast *CastFunc `parser:"| @@"` Substring *SubstringFunc `parser:"| @@"` Extract *ExtractFunc `parser:"| @@"` Trim *TrimFunc `parser:"| @@"` DateAdd *DateAddFunc `parser:"| @@"` DateDiff *DateDiffFunc `parser:"| @@"` // contains filtered or unexported fields }
FuncExpr represents a function call
type Identifier ¶
type Identifier struct { Unquoted *string `parser:" @Ident"` Quoted *QuotedIdentifier `parser:"| @QuotIdent"` }
Identifier represents a parsed identifier
func (*Identifier) String ¶
func (i *Identifier) String() string
Removes double quotes in quoted identifiers
type In ¶
type In struct {
Expressions []*Expression `parser:"@@ ( \",\" @@ )*"`
}
In represents the RHS of an IN expression
type JSONPath ¶
type JSONPath struct { BaseKey *Identifier `parser:" @@"` PathExpr []*JSONPathElement `parser:"(@@)*"` }
JSONPath represents a keypath
type JSONPathElement ¶
type JSONPathElement struct { Key *ObjectKey `parser:" @@"` // ['name'] and .name forms Index *int `parser:"| \"[\" @Number \"]\""` // [3] form ObjectWildcard bool `parser:"| @\".*\""` // .* form ArrayWildcard bool `parser:"| @\"[*]\""` // [*] form }
JSONPathElement represents a keypath component
func (*JSONPathElement) String ¶
func (e *JSONPathElement) String() string
type Like ¶
type Like struct { Not bool `parser:" @\"NOT\"? "` Pattern *Operand `parser:" \"LIKE\" @@ "` EscapeChar *Operand `parser:" (\"ESCAPE\" @@)? "` }
Like represents the RHS of a LIKE expression
type LitValue ¶
type LitValue struct { Number *float64 `parser:"( @Number"` String *LiteralString `parser:" | @LitString"` Boolean *Boolean `parser:" | @(\"TRUE\" | \"FALSE\")"` Null bool `parser:" | @\"NULL\")"` }
LitValue represents a literal value parsed from the sql
type LiteralString ¶
type LiteralString string
LiteralString is a type for parsed SQL string literals
func (*LiteralString) Capture ¶
func (ls *LiteralString) Capture(values []string) error
Capture interface used by participle
type MultOp ¶
type MultOp struct { Left *UnaryTerm `parser:"@@"` Right []*OpUnaryTerm `parser:"(@@)*"` }
MultOp represents a single term followed by an optional sequence of terms separated by *, / or % operators.
type NegatedTerm ¶
type NegatedTerm struct {
Term *PrimaryTerm `parser:"\"-\" @@"`
}
NegatedTerm has a leading minus sign.
type ObjectKey ¶
type ObjectKey struct { Lit *LiteralString `parser:" \"[\" @LitString \"]\""` ID *Identifier `parser:"| \".\" @@"` }
ObjectKey is a type for parsed strings occurring in key paths
type OpUnaryTerm ¶
type OpUnaryTerm struct { Op string `parser:"@(\"*\" | \"/\" | \"%\")"` Right *UnaryTerm `parser:"@@"` }
OpUnaryTerm represents the right side of *, / or % binary operations.
type Operand ¶
An Operand is a single term followed by an optional sequence of terms separated by +/-
type PrimaryTerm ¶
type PrimaryTerm struct { Value *LitValue `parser:" @@"` JPathExpr *JSONPath `parser:"| @@"` SubExpression *Expression `parser:"| \"(\" @@ \")\""` // Include function expressions here. FuncCall *FuncExpr `parser:"| @@"` }
PrimaryTerm represents a Value, Path expression, a Sub-expression or a function call.
type QuotedIdentifier ¶
type QuotedIdentifier string
QuotedIdentifier is a type for parsed strings that are double quoted.
func (*QuotedIdentifier) Capture ¶
func (qi *QuotedIdentifier) Capture(values []string) error
Capture interface used by participle
type Record ¶
type Record interface { Get(name string) (*Value, error) Set(name string, value *Value) error MarshalCSV(fieldDelimiter rune) ([]byte, error) MarshalJSON() ([]byte, error) // Returns underlying representation Raw() (SelectObjectFormat, interface{}) // Replaces the underlying data Replace(k jstream.KVS) error }
Record - is a type containing columns and their values.
type Select ¶
type Select struct { Expression *SelectExpression `parser:"\"SELECT\" @@"` From *TableExpression `parser:"\"FROM\" @@"` Where *Expression `parser:"( \"WHERE\" @@ )?"` Limit *LitValue `parser:"( \"LIMIT\" @@ )?"` }
Select is the top level AST node type
type SelectExpression ¶
type SelectExpression struct { All bool `parser:" @\"*\""` Expressions []*AliasedExpression `parser:"| @@ { \",\" @@ }"` }
SelectExpression represents the items requested in the select statement
type SelectObjectFormat ¶
type SelectObjectFormat int
SelectObjectFormat specifies the format of the underlying data
const ( // SelectFmtUnknown - unknown format (default value) SelectFmtUnknown SelectObjectFormat = iota // SelectFmtCSV - CSV format SelectFmtCSV // SelectFmtJSON - JSON format SelectFmtJSON // SelectFmtParquet - Parquet format SelectFmtParquet )
type SelectStatement ¶
type SelectStatement struct {
// contains filtered or unexported fields
}
SelectStatement is the top level parsed and analyzed structure
func ParseSelectStatement ¶
func ParseSelectStatement(s string) (stmt SelectStatement, err error)
ParseSelectStatement - parses a select query from the given string and analyzes it.
func (*SelectStatement) AggregateResult ¶
func (e *SelectStatement) AggregateResult(output Record) error
AggregateResult - returns the aggregated result after all input records have been processed. Applies only to aggregation queries.
func (*SelectStatement) AggregateRow ¶
func (e *SelectStatement) AggregateRow(input Record) error
AggregateRow - aggregates the input record. Applies only to aggregation queries.
func (*SelectStatement) Eval ¶
func (e *SelectStatement) Eval(input, output Record) (Record, error)
Eval - evaluates the Select statement for the given record. It applies only to non-aggregation queries.
func (*SelectStatement) EvalFrom ¶
func (e *SelectStatement) EvalFrom(format string, input Record) (Record, error)
EvalFrom evaluates the From clause on the input record. It only applies to JSON input data format (currently).
func (*SelectStatement) IsAggregated ¶
func (e *SelectStatement) IsAggregated() bool
IsAggregated returns if the statement involves SQL aggregation
func (*SelectStatement) LimitReached ¶
func (e *SelectStatement) LimitReached() bool
LimitReached - returns true if the number of records output has reached the value of the `LIMIT` clause.
type SimpleArgFunc ¶
type SimpleArgFunc struct { FunctionName string `` /* 193-byte string literal not displayed */ ArgsList []*Expression `parser:"\"(\" (@@ (\",\" @@)*)?\")\""` }
SimpleArgFunc represents functions with simple expression arguments.
type SubstringFunc ¶
type SubstringFunc struct { Expr *PrimaryTerm `parser:" \"SUBSTRING\" \"(\" @@ "` From *Operand `parser:" ( \"FROM\" @@ "` For *Operand `parser:" (\"FOR\" @@)? \")\" "` Arg2 *Operand `parser:" | \",\" @@ "` Arg3 *Operand `parser:" (\",\" @@)? \")\" )"` }
SubstringFunc represents SUBSTRING sql function
type TableExpression ¶
type TableExpression struct { Table *JSONPath `parser:"@@"` As string `parser:"( \"AS\"? @Ident )?"` }
TableExpression represents the FROM clause
func (*TableExpression) HasKeypath ¶
func (from *TableExpression) HasKeypath() bool
HasKeypath returns if the from clause has a key path - e.g. S3object[*].id
type TrimFunc ¶
type TrimFunc struct { TrimWhere *string `parser:" \"TRIM\" \"(\" ( @( \"LEADING\" | \"TRAILING\" | \"BOTH\" ) "` TrimChars *PrimaryTerm `parser:" @@? "` TrimFrom *PrimaryTerm `parser:" \"FROM\" )? @@ \")\" "` }
TrimFunc represents TRIM sql function
type UnaryTerm ¶
type UnaryTerm struct { Negated *NegatedTerm `parser:" @@"` Primary *PrimaryTerm `parser:"| @@"` }
UnaryTerm represents a single negated term or a primary term
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value represents a value of restricted type reduced from an expression represented by an ASTNode. Only one of the fields is non-nil.
In cases where we are fetching data from a data source (like csv), the type may not be determined yet. In these cases, a byte-slice is used.
func FromTimestamp ¶
FromTimestamp creates a Value from a timestamp
func (*Value) GetTypeString ¶
GetTypeString returns a string representation for vType
func (*Value) ToBool ¶
ToBool returns the bool value; second return value refers to if the bool conversion succeeded.