Documentation
¶
Index ¶
- Variables
- func FormatSQLTimestamp(t time.Time) string
- func IterToValue(iter simdjson.Iter) (interface{}, error)
- 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 ListExpr
- type LitValue
- type LiteralList
- type LiteralString
- type Missing
- 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) Equals(b Value) (ok bool)
- func (v Value) GetTypeString() string
- func (v *Value) InferBytesType() (err error)
- func (v Value) IsArray() (ok bool)
- func (v Value) IsMissing() bool
- func (v Value) IsNull() bool
- func (v Value) MarshalJSON() ([]byte, error)
- func (v Value) Repr() string
- func (v Value) SameTypeAs(b Value) (ok bool)
- func (v Value) String() string
- func (v Value) ToArray() (val []Value, ok bool)
- func (v Value) ToBool() (val bool, ok bool)
- func (v Value) ToBytes() (val []byte, ok 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)
- type WriteCSVOpts
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
func IterToValue ¶
func IterToValue(iter simdjson.Iter) (interface{}, error)
IterToValue converts a simdjson Iter to its underlying value. Objects are returned as simdjson.Object Arrays are returned as []interface{} with parsed values.
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:"@( \"<>\" | \"<=\" | \">=\" | \"=\" | \"<\" | \">\" | \"!=\" | \"IS\" \"NOT\" | \"IS\")"`
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
String removes double quotes in quoted identifiers
type In ¶
type In struct {
ListExpression *Expression `parser:"@@ "`
}
In represents the RHS of an IN expression
type JSONPath ¶
type JSONPath struct {
BaseKey *Identifier `parser:" @@"`
PathExpr []*JSONPathElement `parser:"(@@)*"`
// contains filtered or unexported fields
}
JSONPath represents a keypath. Instances should be treated idempotent and not change once created.
func (*JSONPath) StripTableAlias ¶
func (e *JSONPath) StripTableAlias(tableAlias string) []*JSONPathElement
StripTableAlias removes a table alias from the path. The result is also cached for repeated lookups during SQL query evaluation.
type JSONPathElement ¶
type JSONPathElement struct {
Key *ObjectKey `parser:" @@"` // ['name'] and .name forms
Index *int `parser:"| \"[\" @Int \"]\""` // [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 ListExpr ¶
type ListExpr struct {
Elements []*Expression `parser:"\"(\" @@ ( \",\" @@ )* \")\" | \"[\" @@ ( \",\" @@ )* \"]\""`
}
ListExpr represents a literal list with elements as expressions.
type LitValue ¶
type LitValue struct {
Float *float64 `parser:"( @Float"`
Int *float64 `parser:" | @Int"` // To avoid value out of range, use float64 instead
String *LiteralString `parser:" | @LitString"`
Boolean *Boolean `parser:" | @(\"TRUE\" | \"FALSE\")"`
Null bool `parser:" | @\"NULL\""`
Missing bool `parser:" | @\"MISSING\")"`
}
LitValue represents a literal value parsed from the sql
type LiteralList ¶
type LiteralList []string
LiteralList is a type for parsed SQL lists literals
func (*LiteralList) Capture ¶
func (ls *LiteralList) Capture(values []string) error
Capture interface used by participle
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:"| @@"`
ListExpr *ListExpr `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 a value.
// Can return a different record type.
Set(name string, value *Value) (Record, error)
WriteCSV(writer io.Writer, opts WriteCSVOpts) error
WriteJSON(writer io.Writer) error
// Clone the record and if possible use the destination provided.
Clone(dst Record) Record
Reset()
// Returns underlying representation
Raw() (SelectObjectFormat, interface{})
// Replaces the underlying data
Replace(k interface{}) 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 // SelectFmtSIMDJSON - SIMD JSON format SelectFmtSIMDJSON // 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. The function returns whether the statement passed the WHERE clause and should be outputted.
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) Equals ¶
Equals returns whether the values strictly match. Both type and value must match.
func (Value) GetTypeString ¶
GetTypeString returns a string representation for vType
func (*Value) InferBytesType ¶
InferBytesType will attempt to infer the data type of bytes. Will fail if value type is not bytes or it would result in invalid utf8. ORDER: int, float, bool, JSON (object or array), timestamp, string If the content is valid JSON, the type will still be bytes.
func (Value) MarshalJSON ¶
MarshalJSON provides json marshaling of values.
func (Value) SameTypeAs ¶
SameTypeAs return whether the two types are strictly the same.
func (Value) ToBool ¶
ToBool returns the bool value; second return value refers to if the bool conversion succeeded.