rel

package
v0.0.0-...-261b5b0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2016 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

AST Structures and Parsers for the SQL, and FilterQL, and Expression dialects.

Package rel is a generated protocol buffer package.

It is generated from these files:
	sql.proto

It has these top-level messages:
	SqlStatementPb
	SqlSelectPb
	SqlSourcePb
	SqlWherePb
	ProjectionPb
	ResultColumnPb
	KvInt
	ColumnPb
	CommandColumnPb

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidLengthSql = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowSql   = fmt.Errorf("proto: integer overflow")
)

Functions

func MapIntFromPb

func MapIntFromPb(kv []KvInt) map[string]int

func ParseJsonArray

func ParseJsonArray(pg expr.TokenPager) ([]interface{}, error)

func ParseJsonObject

func ParseJsonObject(pg expr.TokenPager, jh u.JsonHelper) error

func ParseKeyValue

func ParseKeyValue(pg expr.TokenPager, jh u.JsonHelper) error

func ParseWith

func ParseWith(pg expr.TokenPager) (u.JsonHelper, error)

Types

type Column

type Column struct {
	ParentIndex int       // slice idx position in parent query cols
	Index       int       // slice idx position in original query cols
	SourceIndex int       // slice idx position in source []driver.Value
	SourceField string    // field name of underlying field
	As          string    // As field, auto-populate the Field Name if exists
	Comment     string    // optional in-line comments
	Order       string    // (ASC | DESC)
	Star        bool      // *
	Agg         bool      // aggregate function column?   count(*), avg(x) etc
	Expr        expr.Node // Expression, optional, often Identity.Node
	Guard       expr.Node // column If guard, non-standard sql column guard
	// contains filtered or unexported fields
}

Column represents the Column as expressed in a [SELECT] expression

func NewColumn

func NewColumn(col string) *Column

func NewColumnFromToken

func NewColumnFromToken(tok lex.Token) *Column

func NewColumnValue

func NewColumnValue(tok lex.Token) *Column

func (*Column) Copy

func (m *Column) Copy() *Column

func (*Column) CopyRewrite

func (m *Column) CopyRewrite(alias string) *Column

Create a new copy of this column for rewrite purposes re-alias

func (*Column) CountStar

func (m *Column) CountStar() bool

Is this a select count(*) column

func (*Column) Equal

func (m *Column) Equal(c *Column) bool

func (*Column) FingerPrint

func (m *Column) FingerPrint(r rune) string

func (*Column) InFinalProjection

func (m *Column) InFinalProjection() bool

func (*Column) Key

func (m *Column) Key() string

func (*Column) LeftRight

func (m *Column) LeftRight() (string, string, bool)

Return left, right values if is of form `table.column` and also return true/false for if it even has left/right

func (*Column) String

func (m *Column) String() string

func (*Column) ToPB

func (m *Column) ToPB() *ColumnPb

type ColumnPb

type ColumnPb struct {
	SourceQuote      []byte       `protobuf:"bytes,1,opt,name=sourceQuote" json:"sourceQuote,omitempty"`
	AsQuoteByte      []byte       `protobuf:"bytes,2,opt,name=asQuoteByte" json:"asQuoteByte,omitempty"`
	OriginalAs       *string      `protobuf:"bytes,3,opt,name=originalAs" json:"originalAs,omitempty"`
	Left             *string      `protobuf:"bytes,4,opt,name=left" json:"left,omitempty"`
	Right            *string      `protobuf:"bytes,5,opt,name=right" json:"right,omitempty"`
	ParentIndex      int32        `protobuf:"varint,6,opt,name=parentIndex" json:"parentIndex"`
	Index            int32        `protobuf:"varint,7,opt,name=index" json:"index"`
	SourceIndex      int32        `protobuf:"varint,8,opt,name=sourceIndex" json:"sourceIndex"`
	SourceField      *string      `protobuf:"bytes,9,opt,name=sourceField" json:"sourceField,omitempty"`
	As               string       `protobuf:"bytes,11,opt,name=as" json:"as"`
	Comment          *string      `protobuf:"bytes,12,opt,name=comment" json:"comment,omitempty"`
	Order            *string      `protobuf:"bytes,13,opt,name=order" json:"order,omitempty"`
	Star             *bool        `protobuf:"varint,14,opt,name=star" json:"star,omitempty"`
	Agg              bool         `protobuf:"varint,15,opt,name=agg" json:"agg"`
	Expr             *expr.NodePb `protobuf:"bytes,16,opt,name=Expr,json=expr" json:"Expr,omitempty"`
	Guard            *expr.NodePb `protobuf:"bytes,17,opt,name=Guard,json=guard" json:"Guard,omitempty"`
	XXX_unrecognized []byte       `json:"-"`
}

func ColumnsToPb

func ColumnsToPb(c Columns) []*ColumnPb

func (*ColumnPb) Descriptor

func (*ColumnPb) Descriptor() ([]byte, []int)

func (*ColumnPb) GetAgg

func (m *ColumnPb) GetAgg() bool

func (*ColumnPb) GetAs

func (m *ColumnPb) GetAs() string

func (*ColumnPb) GetAsQuoteByte

func (m *ColumnPb) GetAsQuoteByte() []byte

func (*ColumnPb) GetComment

func (m *ColumnPb) GetComment() string

func (*ColumnPb) GetExpr

func (m *ColumnPb) GetExpr() *expr.NodePb

func (*ColumnPb) GetGuard

func (m *ColumnPb) GetGuard() *expr.NodePb

func (*ColumnPb) GetIndex

func (m *ColumnPb) GetIndex() int32

func (*ColumnPb) GetLeft

func (m *ColumnPb) GetLeft() string

func (*ColumnPb) GetOrder

func (m *ColumnPb) GetOrder() string

func (*ColumnPb) GetOriginalAs

func (m *ColumnPb) GetOriginalAs() string

func (*ColumnPb) GetParentIndex

func (m *ColumnPb) GetParentIndex() int32

func (*ColumnPb) GetRight

func (m *ColumnPb) GetRight() string

func (*ColumnPb) GetSourceField

func (m *ColumnPb) GetSourceField() string

func (*ColumnPb) GetSourceIndex

func (m *ColumnPb) GetSourceIndex() int32

func (*ColumnPb) GetSourceQuote

func (m *ColumnPb) GetSourceQuote() []byte

func (*ColumnPb) GetStar

func (m *ColumnPb) GetStar() bool

func (*ColumnPb) Marshal

func (m *ColumnPb) Marshal() (data []byte, err error)

func (*ColumnPb) MarshalTo

func (m *ColumnPb) MarshalTo(data []byte) (int, error)

func (*ColumnPb) ProtoMessage

func (*ColumnPb) ProtoMessage()

func (*ColumnPb) Reset

func (m *ColumnPb) Reset()

func (*ColumnPb) Size

func (m *ColumnPb) Size() (n int)

func (*ColumnPb) String

func (m *ColumnPb) String() string

func (*ColumnPb) Unmarshal

func (m *ColumnPb) Unmarshal(data []byte) error

type Columns

type Columns []*Column

List of Columns in SELECT [columns]

func ColumnsFromPb

func ColumnsFromPb(c []*ColumnPb) Columns

func (*Columns) AliasedFieldNames

func (m *Columns) AliasedFieldNames() []string

func (*Columns) ByAs

func (m *Columns) ByAs(as string) (*Column, bool)

func (*Columns) ByName

func (m *Columns) ByName(name string) (*Column, bool)

func (*Columns) FieldNames

func (m *Columns) FieldNames() []string

func (*Columns) FingerPrint

func (m *Columns) FingerPrint(r rune) string

func (*Columns) String

func (m *Columns) String() string

func (*Columns) UnAliasedFieldNames

func (m *Columns) UnAliasedFieldNames() []string

type ColumnsStatement

type ColumnsStatement interface {
	AddColumn(col Column) error
}

type CommandColumn

type CommandColumn struct {
	Expr expr.Node // column expression
	Name string    // Original path/name for command field
}

Command column is single column such as "autocommit"

func (*CommandColumn) FingerPrint

func (m *CommandColumn) FingerPrint(r rune) string

func (*CommandColumn) Key

func (m *CommandColumn) Key() string

func (*CommandColumn) String

func (m *CommandColumn) String() string

type CommandColumnPb

type CommandColumnPb struct {
	Expr             *expr.NodePb `protobuf:"bytes,1,opt,name=Expr,json=expr" json:"Expr,omitempty"`
	Name             string       `protobuf:"bytes,2,req,name=name" json:"name"`
	XXX_unrecognized []byte       `json:"-"`
}

func (*CommandColumnPb) Descriptor

func (*CommandColumnPb) Descriptor() ([]byte, []int)

func (*CommandColumnPb) GetExpr

func (m *CommandColumnPb) GetExpr() *expr.NodePb

func (*CommandColumnPb) GetName

func (m *CommandColumnPb) GetName() string

func (*CommandColumnPb) Marshal

func (m *CommandColumnPb) Marshal() (data []byte, err error)

func (*CommandColumnPb) MarshalTo

func (m *CommandColumnPb) MarshalTo(data []byte) (int, error)

func (*CommandColumnPb) ProtoMessage

func (*CommandColumnPb) ProtoMessage()

func (*CommandColumnPb) Reset

func (m *CommandColumnPb) Reset()

func (*CommandColumnPb) Size

func (m *CommandColumnPb) Size() (n int)

func (*CommandColumnPb) String

func (m *CommandColumnPb) String() string

func (*CommandColumnPb) Unmarshal

func (m *CommandColumnPb) Unmarshal(data []byte) error

type CommandColumns

type CommandColumns []*CommandColumn

SQL commands such as:

set autocommit
SET @@local.sort_buffer_size=10000;
USE myschema;

func (*CommandColumns) FingerPrint

func (m *CommandColumns) FingerPrint(r rune) string

func (*CommandColumns) String

func (m *CommandColumns) String() string

type Filter

type Filter interface {
	String() string
}

type FilterExpr

type FilterExpr struct {
	IncludeFilter *FilterStatement // Memoized Include

	// Do we negate this entire Filter?  Default = false (ie, don't negate)
	// This should NOT be available to Expr nodes which have their own built
	// in negation/urnary
	Negate bool

	// Exactly one of these will be non-nil
	Include  string    // name of foreign named alias filter to embed
	Expr     expr.Node // Node might be nil in which case must have filter
	Filter   *Filters  // might be nil, must have expr
	MatchAll bool      // * = match all
}

Single Filter expression

func NewFilterExpr

func NewFilterExpr() *FilterExpr

func (*FilterExpr) Includes

func (fe *FilterExpr) Includes() []string

Recurse this expression and find all includes

func (*FilterExpr) String

func (fe *FilterExpr) String() string

String representation of FilterExpression for diagnostic purposes.

type FilterSelect

type FilterSelect struct {
	*FilterStatement
	Columns Columns
}

func NewFilterSelect

func NewFilterSelect() *FilterSelect

func ParseFilterSelect

func ParseFilterSelect(query string) (*FilterSelect, error)

func (*FilterSelect) AddColumn

func (m *FilterSelect) AddColumn(colArg Column) error

func (*FilterSelect) FingerPrint

func (m *FilterSelect) FingerPrint(r rune) string

func (*FilterSelect) FingerPrintID

func (m *FilterSelect) FingerPrintID() int64

func (*FilterSelect) Includes

func (m *FilterSelect) Includes() []string

Recurse this statement and find all includes

func (*FilterSelect) String

func (m *FilterSelect) String() string

String representation of FilterSelect

type FilterStatement

type FilterStatement struct {
	Description string       // initial pre-start comments
	Raw         string       // full original raw statement
	Filter      *Filters     // A top level filter
	From        string       // From is optional
	Limit       int          // Limit
	HasDateMath bool         // does this have date math?
	Alias       string       // Non-Standard sql, alias/name of sql another way of expression Prepared Statement
	With        u.JsonHelper // Non-Standard SQL for properties/config info, similar to Cassandra with, purse json
}

Filter Statement is a statement of type = Filter

func NewFilterStatement

func NewFilterStatement() *FilterStatement

func ParseFilterQL

func ParseFilterQL(filter string) (*FilterStatement, error)

Parses Tokens and returns an request.

func ParseFilterQLVm

func ParseFilterQLVm(filter string) (*FilterStatement, error)

func (*FilterStatement) FingerPrint

func (m *FilterStatement) FingerPrint(r rune) string

func (*FilterStatement) FingerPrintID

func (m *FilterStatement) FingerPrintID() int64

func (*FilterStatement) Includes

func (m *FilterStatement) Includes() []string

Recurse this statement and find all includes

func (*FilterStatement) String

func (m *FilterStatement) String() string

String representation of FilterStatement

type Filters

type Filters struct {
	Negate  bool          // Should we negate this response?
	Op      lex.TokenType // OR, AND
	Filters []*FilterExpr
}

A list of Filter Expressions

func NewFilters

func NewFilters(tt lex.TokenType) *Filters

func (*Filters) Includes

func (m *Filters) Includes() []string

Recurse these filters and find all includes

func (*Filters) String

func (m *Filters) String() string

String representation of Filters

type KvInt

type KvInt struct {
	K                string `protobuf:"bytes,1,req,name=k" json:"k"`
	V                int32  `protobuf:"varint,2,req,name=v" json:"v"`
	XXX_unrecognized []byte `json:"-"`
}

func (*KvInt) Descriptor

func (*KvInt) Descriptor() ([]byte, []int)

func (*KvInt) GetK

func (m *KvInt) GetK() string

func (*KvInt) GetV

func (m *KvInt) GetV() int32

func (*KvInt) Marshal

func (m *KvInt) Marshal() (data []byte, err error)

func (*KvInt) MarshalTo

func (m *KvInt) MarshalTo(data []byte) (int, error)

func (*KvInt) ProtoMessage

func (*KvInt) ProtoMessage()

func (*KvInt) Reset

func (m *KvInt) Reset()

func (*KvInt) Size

func (m *KvInt) Size() (n int)

func (*KvInt) String

func (m *KvInt) String() string

func (*KvInt) Unmarshal

func (m *KvInt) Unmarshal(data []byte) error

type PreparedStatement

type PreparedStatement struct {
	Alias     string
	Statement SqlStatement
}

Prepared/Aliased SQL statement

func NewPreparedStatement

func NewPreparedStatement() *PreparedStatement

func (*PreparedStatement) FingerPrint

func (m *PreparedStatement) FingerPrint(r rune) string

func (*PreparedStatement) Keyword

func (m *PreparedStatement) Keyword() lex.TokenType

func (*PreparedStatement) String

func (m *PreparedStatement) String() string

type Projection

type Projection struct {
	Distinct bool
	Final    bool // Is this a Final Projection? or intermiediate?

	Columns ResultColumns
	// contains filtered or unexported fields
}

Projection describes the results to expect from sql statement ie the ResultColumns for a result-set

func NewProjection

func NewProjection() *Projection

func ProjectionFromPb

func ProjectionFromPb(pb *ProjectionPb) *Projection

func (*Projection) AddColumn

func (m *Projection) AddColumn(col *Column, vt value.ValueType)

func (*Projection) AddColumnShort

func (m *Projection) AddColumnShort(colName string, vt value.ValueType)

func (*Projection) Equal

func (m *Projection) Equal(s *Projection) bool

func (*Projection) FromPB

func (m *Projection) FromPB(pb *ProjectionPb) *Projection

func (*Projection) ToPB

func (m *Projection) ToPB() *ProjectionPb

type ProjectionPb

type ProjectionPb struct {
	Distinct         bool              `protobuf:"varint,1,req,name=distinct" json:"distinct"`
	Final            bool              `protobuf:"varint,2,req,name=final" json:"final"`
	ColNames         []string          `protobuf:"bytes,3,rep,name=colNames" json:"colNames,omitempty"`
	Columns          []*ResultColumnPb `protobuf:"bytes,4,rep,name=columns" json:"columns,omitempty"`
	XXX_unrecognized []byte            `json:"-"`
}

func (*ProjectionPb) Descriptor

func (*ProjectionPb) Descriptor() ([]byte, []int)

func (*ProjectionPb) GetColNames

func (m *ProjectionPb) GetColNames() []string

func (*ProjectionPb) GetColumns

func (m *ProjectionPb) GetColumns() []*ResultColumnPb

func (*ProjectionPb) GetDistinct

func (m *ProjectionPb) GetDistinct() bool

func (*ProjectionPb) GetFinal

func (m *ProjectionPb) GetFinal() bool

func (*ProjectionPb) Marshal

func (m *ProjectionPb) Marshal() (data []byte, err error)

func (*ProjectionPb) MarshalTo

func (m *ProjectionPb) MarshalTo(data []byte) (int, error)

func (*ProjectionPb) ProtoMessage

func (*ProjectionPb) ProtoMessage()

func (*ProjectionPb) Reset

func (m *ProjectionPb) Reset()

func (*ProjectionPb) Size

func (m *ProjectionPb) Size() (n int)

func (*ProjectionPb) String

func (m *ProjectionPb) String() string

func (*ProjectionPb) Unmarshal

func (m *ProjectionPb) Unmarshal(data []byte) error

type ResultColumn

type ResultColumn struct {
	Final  bool            // Is this part of final projection (ie, response)
	Name   string          // Original path/name for query field
	ColPos int             // Ordinal position in sql (or partial sql) statement
	Col    *Column         // the original sql column
	Star   bool            // Was this a select * ??
	As     string          // aliased
	Type   value.ValueType // Data Type
}

Result Column used in projection

func NewResultColumn

func NewResultColumn(as string, ordinal int, col *Column, valtype value.ValueType) *ResultColumn

func (*ResultColumn) Equal

func (m *ResultColumn) Equal(s *ResultColumn) bool

func (*ResultColumn) SourceName

func (m *ResultColumn) SourceName() string

The source column name

type ResultColumnPb

type ResultColumnPb struct {
	Final            *bool     `protobuf:"varint,1,opt,name=final" json:"final,omitempty"`
	Name             string    `protobuf:"bytes,2,req,name=name" json:"name"`
	ColPos           int32     `protobuf:"varint,3,req,name=colPos" json:"colPos"`
	Column           *ColumnPb `protobuf:"bytes,4,opt,name=column" json:"column,omitempty"`
	Star             *bool     `protobuf:"varint,5,opt,name=star" json:"star,omitempty"`
	As               string    `protobuf:"bytes,6,req,name=as" json:"as"`
	ValueType        int32     `protobuf:"varint,7,req,name=valueType" json:"valueType"`
	XXX_unrecognized []byte    `json:"-"`
}

func (*ResultColumnPb) Descriptor

func (*ResultColumnPb) Descriptor() ([]byte, []int)

func (*ResultColumnPb) GetAs

func (m *ResultColumnPb) GetAs() string

func (*ResultColumnPb) GetColPos

func (m *ResultColumnPb) GetColPos() int32

func (*ResultColumnPb) GetColumn

func (m *ResultColumnPb) GetColumn() *ColumnPb

func (*ResultColumnPb) GetFinal

func (m *ResultColumnPb) GetFinal() bool

func (*ResultColumnPb) GetName

func (m *ResultColumnPb) GetName() string

func (*ResultColumnPb) GetStar

func (m *ResultColumnPb) GetStar() bool

func (*ResultColumnPb) GetValueType

func (m *ResultColumnPb) GetValueType() int32

func (*ResultColumnPb) Marshal

func (m *ResultColumnPb) Marshal() (data []byte, err error)

func (*ResultColumnPb) MarshalTo

func (m *ResultColumnPb) MarshalTo(data []byte) (int, error)

func (*ResultColumnPb) ProtoMessage

func (*ResultColumnPb) ProtoMessage()

func (*ResultColumnPb) Reset

func (m *ResultColumnPb) Reset()

func (*ResultColumnPb) Size

func (m *ResultColumnPb) Size() (n int)

func (*ResultColumnPb) String

func (m *ResultColumnPb) String() string

func (*ResultColumnPb) Unmarshal

func (m *ResultColumnPb) Unmarshal(data []byte) error

type ResultColumns

type ResultColumns []*ResultColumn

List of ResultColumns used to describe projection response columns

type SqlCommand

type SqlCommand struct {
	Columns  CommandColumns // can have multiple columns in command
	Identity string         //
	Value    expr.Node      //
	// contains filtered or unexported fields
}

Sql Command is admin command such as "SET"

func (*SqlCommand) FingerPrint

func (m *SqlCommand) FingerPrint(r rune) string

func (*SqlCommand) Keyword

func (m *SqlCommand) Keyword() lex.TokenType

func (*SqlCommand) String

func (m *SqlCommand) String() string

type SqlDelete

type SqlDelete struct {
	Table string
	Where *SqlWhere
	Limit int
}

SQL Delete Statement

func NewSqlDelete

func NewSqlDelete() *SqlDelete

func (*SqlDelete) FingerPrint

func (m *SqlDelete) FingerPrint(r rune) string

func (*SqlDelete) Keyword

func (m *SqlDelete) Keyword() lex.TokenType

func (*SqlDelete) SqlSelect

func (m *SqlDelete) SqlSelect() *SqlSelect

func (*SqlDelete) String

func (m *SqlDelete) String() string

type SqlDescribe

type SqlDescribe struct {
	Raw      string    // full original raw statement
	Identity string    // Describe
	Tok      lex.Token // Explain, Describe, Desc
	Stmt     SqlStatement
}

SQL Describe statement

func (*SqlDescribe) FingerPrint

func (m *SqlDescribe) FingerPrint(r rune) string

func (*SqlDescribe) Keyword

func (m *SqlDescribe) Keyword() lex.TokenType

func (*SqlDescribe) String

func (m *SqlDescribe) String() string

type SqlInsert

type SqlInsert struct {
	Table   string           // table name
	Columns Columns          // Column Names
	Rows    [][]*ValueColumn // Values to insert
	Select  *SqlSelect       //
	// contains filtered or unexported fields
}

SQL Insert Statement

func NewSqlInsert

func NewSqlInsert() *SqlInsert

func (*SqlInsert) ColumnNames

func (m *SqlInsert) ColumnNames() []string

func (*SqlInsert) FingerPrint

func (m *SqlInsert) FingerPrint(r rune) string

func (*SqlInsert) Keyword

func (m *SqlInsert) Keyword() lex.TokenType

func (*SqlInsert) String

func (m *SqlInsert) String() string

type SqlInto

type SqlInto struct {
	Table string
}

SQL INTO statement (select a,b,c from y INTO z)

func NewSqlInto

func NewSqlInto(table string) *SqlInto

func (*SqlInto) Equal

func (m *SqlInto) Equal(s *SqlInto) bool

func (*SqlInto) FingerPrint

func (m *SqlInto) FingerPrint(r rune) string

func (*SqlInto) Keyword

func (m *SqlInto) Keyword() lex.TokenType

func (*SqlInto) String

func (m *SqlInto) String() string

type SqlSelect

type SqlSelect struct {
	Db       string       // If provided a use "dbname"
	Raw      string       // full original raw statement
	Star     bool         // for select * from ...
	Distinct bool         // Distinct flag?
	Columns  Columns      // An array (ordered) list of columns
	From     []*SqlSource // From, Join
	Into     *SqlInto     // Into "table"
	Where    *SqlWhere    // Expr Node, or *SqlSelect
	Having   expr.Node    // Filter results
	GroupBy  Columns
	OrderBy  Columns
	Limit    int
	Offset   int
	Alias    string       // Non-Standard sql, alias/name of sql another way of expression Prepared Statement
	With     u.JsonHelper // Non-Standard SQL for properties/config info, similar to Cassandra with, purse json
	// contains filtered or unexported fields
}

SQL Select statement

func NewSqlSelect

func NewSqlSelect() *SqlSelect

func ParseSqlSelect

func ParseSqlSelect(sqlQuery string) (*SqlSelect, error)

func ParseSqlSelectResolver

func ParseSqlSelectResolver(sqlQuery string, fr expr.FuncResolver) (*SqlSelect, error)

func SqlSelectFromPb

func SqlSelectFromPb(pb *SqlSelectPb) *SqlSelect

func (*SqlSelect) AddColumn

func (m *SqlSelect) AddColumn(colArg Column) error

func (*SqlSelect) AliasedColumns

func (m *SqlSelect) AliasedColumns() map[string]*Column

func (*SqlSelect) ColIndexes

func (m *SqlSelect) ColIndexes() map[string]int

func (*SqlSelect) CountStar

func (m *SqlSelect) CountStar() bool

Is this a select count(*) FROM ... query?

func (*SqlSelect) Equal

func (m *SqlSelect) Equal(ss SqlStatement) bool

func (*SqlSelect) Finalize

func (m *SqlSelect) Finalize() error

Finalize this Query plan by preparing sub-sources

ie we need to rewrite some things into sub-statements
- we need to share the join expression across sources

func (*SqlSelect) FingerPrint

func (m *SqlSelect) FingerPrint(r rune) string

func (*SqlSelect) FingerPrintID

func (m *SqlSelect) FingerPrintID() int64

func (*SqlSelect) FromPB

func (m *SqlSelect) FromPB(spb *SqlSelectPb) *SqlSelect

func (*SqlSelect) IsAggQuery

func (m *SqlSelect) IsAggQuery() bool

func (*SqlSelect) IsLiteral

func (m *SqlSelect) IsLiteral() bool

func (*SqlSelect) Keyword

func (m *SqlSelect) Keyword() lex.TokenType

func (*SqlSelect) Rewrite

func (m *SqlSelect) Rewrite()

func (*SqlSelect) SetSystemQry

func (m *SqlSelect) SetSystemQry()

func (*SqlSelect) String

func (m *SqlSelect) String() string

func (*SqlSelect) SystemQry

func (m *SqlSelect) SystemQry() bool

func (*SqlSelect) ToPB

func (m *SqlSelect) ToPB() *SqlSelectPb

func (*SqlSelect) ToPbStatement

func (m *SqlSelect) ToPbStatement() *SqlStatementPb

func (*SqlSelect) UnAliasedColumns

func (m *SqlSelect) UnAliasedColumns() map[string]*Column

type SqlSelectPb

type SqlSelectPb struct {
	Db               string         `protobuf:"bytes,1,req,name=db" json:"db"`
	Raw              string         `protobuf:"bytes,2,req,name=raw" json:"raw"`
	Star             bool           `protobuf:"varint,3,req,name=star" json:"star"`
	Distinct         bool           `protobuf:"varint,4,req,name=distinct" json:"distinct"`
	Columns          []*ColumnPb    `protobuf:"bytes,5,rep,name=columns" json:"columns,omitempty"`
	From             []*SqlSourcePb `protobuf:"bytes,6,rep,name=from" json:"from,omitempty"`
	Into             *string        `protobuf:"bytes,7,opt,name=into" json:"into,omitempty"`
	Where            *SqlWherePb    `protobuf:"bytes,8,opt,name=where" json:"where,omitempty"`
	Having           *expr.NodePb   `protobuf:"bytes,9,opt,name=having" json:"having,omitempty"`
	GroupBy          []*ColumnPb    `protobuf:"bytes,11,rep,name=groupBy" json:"groupBy,omitempty"`
	OrderBy          []*ColumnPb    `protobuf:"bytes,10,rep,name=orderBy" json:"orderBy,omitempty"`
	Limit            int32          `protobuf:"varint,12,opt,name=limit" json:"limit"`
	Offset           int32          `protobuf:"varint,13,opt,name=offset" json:"offset"`
	Alias            *string        `protobuf:"bytes,14,opt,name=alias" json:"alias,omitempty"`
	Projection       *ProjectionPb  `protobuf:"bytes,15,opt,name=projection" json:"projection,omitempty"`
	IsAgg            bool           `protobuf:"varint,16,req,name=isAgg" json:"isAgg"`
	Finalized        bool           `protobuf:"varint,17,req,name=finalized" json:"finalized"`
	Schemaqry        bool           `protobuf:"varint,18,req,name=schemaqry" json:"schemaqry"`
	With             []byte         `protobuf:"bytes,19,opt,name=with" json:"with,omitempty"`
	XXX_unrecognized []byte         `json:"-"`
}

func SqlSelectToPb

func SqlSelectToPb(m *SqlSelect) *SqlSelectPb

func (*SqlSelectPb) Descriptor

func (*SqlSelectPb) Descriptor() ([]byte, []int)

func (*SqlSelectPb) GetAlias

func (m *SqlSelectPb) GetAlias() string

func (*SqlSelectPb) GetColumns

func (m *SqlSelectPb) GetColumns() []*ColumnPb

func (*SqlSelectPb) GetDb

func (m *SqlSelectPb) GetDb() string

func (*SqlSelectPb) GetDistinct

func (m *SqlSelectPb) GetDistinct() bool

func (*SqlSelectPb) GetFinalized

func (m *SqlSelectPb) GetFinalized() bool

func (*SqlSelectPb) GetFrom

func (m *SqlSelectPb) GetFrom() []*SqlSourcePb

func (*SqlSelectPb) GetGroupBy

func (m *SqlSelectPb) GetGroupBy() []*ColumnPb

func (*SqlSelectPb) GetHaving

func (m *SqlSelectPb) GetHaving() *expr.NodePb

func (*SqlSelectPb) GetInto

func (m *SqlSelectPb) GetInto() string

func (*SqlSelectPb) GetIsAgg

func (m *SqlSelectPb) GetIsAgg() bool

func (*SqlSelectPb) GetLimit

func (m *SqlSelectPb) GetLimit() int32

func (*SqlSelectPb) GetOffset

func (m *SqlSelectPb) GetOffset() int32

func (*SqlSelectPb) GetOrderBy

func (m *SqlSelectPb) GetOrderBy() []*ColumnPb

func (*SqlSelectPb) GetProjection

func (m *SqlSelectPb) GetProjection() *ProjectionPb

func (*SqlSelectPb) GetRaw

func (m *SqlSelectPb) GetRaw() string

func (*SqlSelectPb) GetSchemaqry

func (m *SqlSelectPb) GetSchemaqry() bool

func (*SqlSelectPb) GetStar

func (m *SqlSelectPb) GetStar() bool

func (*SqlSelectPb) GetWhere

func (m *SqlSelectPb) GetWhere() *SqlWherePb

func (*SqlSelectPb) GetWith

func (m *SqlSelectPb) GetWith() []byte

func (*SqlSelectPb) Marshal

func (m *SqlSelectPb) Marshal() (data []byte, err error)

func (*SqlSelectPb) MarshalTo

func (m *SqlSelectPb) MarshalTo(data []byte) (int, error)

func (*SqlSelectPb) ProtoMessage

func (*SqlSelectPb) ProtoMessage()

func (*SqlSelectPb) Reset

func (m *SqlSelectPb) Reset()

func (*SqlSelectPb) Size

func (m *SqlSelectPb) Size() (n int)

func (*SqlSelectPb) String

func (m *SqlSelectPb) String() string

func (*SqlSelectPb) Unmarshal

func (m *SqlSelectPb) Unmarshal(data []byte) error

type SqlShow

type SqlShow struct {
	Raw        string // full raw statement
	Db         string // Database/Schema name
	Full       bool   // SHOW FULL TABLE FROM
	Scope      string // {FULL, GLOBAL, SESSION}
	ShowType   string // object type, [tables, columns, etc]
	From       string // `table`   or `schema`.`table`
	Identity   string // `table`   or `schema`.`table`
	Create     bool
	CreateWhat string
	Where      expr.Node
	Like       expr.Node
}

SQL SHOW Statement

func (*SqlShow) FingerPrint

func (m *SqlShow) FingerPrint(r rune) string

func (*SqlShow) Keyword

func (m *SqlShow) Keyword() lex.TokenType

func (*SqlShow) String

func (m *SqlShow) String() string

type SqlSource

type SqlSource struct {
	Source      *SqlSelect    // Sql Select Source query, written by Rewrite
	Raw         string        // Raw Partial Query
	Name        string        // From Name (optional, empty if join, subselect)
	Alias       string        // From name aliased
	Schema      string        //  FROM `schema`.`table`
	Op          lex.TokenType // In, =, ON
	LeftOrRight lex.TokenType // Left, Right
	JoinType    lex.TokenType // INNER, OUTER
	JoinExpr    expr.Node     // Join expression       x.y = q.y
	SubQuery    *SqlSelect    // optional, Join/SubSelect statement

	// Plan Hints, move to a dedicated planner
	Seekable bool
	// contains filtered or unexported fields
}

Source is a table name, sub-query, or join as used in SELECT <columns> FROM <SQLSOURCE>

  • SELECT .. FROM table_name
  • SELECT .. from (select a,b,c from tableb)
  • SELECT .. FROM tablex INNER JOIN ...

func NewSqlSource

func NewSqlSource(table string) *SqlSource

func SqlSourceFromPb

func SqlSourceFromPb(pb *SqlSourcePb) *SqlSource

func (*SqlSource) BuildColIndex

func (m *SqlSource) BuildColIndex(colNames []string) error

func (*SqlSource) ColumnPositions

func (m *SqlSource) ColumnPositions() map[string]int

Get a list of Column names to position

func (*SqlSource) Equal

func (m *SqlSource) Equal(s *SqlSource) bool

func (*SqlSource) Finalize

func (m *SqlSource) Finalize() error

func (*SqlSource) FingerPrint

func (m *SqlSource) FingerPrint(r rune) string

func (*SqlSource) FromPB

func (m *SqlSource) FromPB(n *SqlSourcePb) *SqlSource

func (*SqlSource) IsLiteral

func (m *SqlSource) IsLiteral() bool

func (*SqlSource) JoinNodes

func (m *SqlSource) JoinNodes() []expr.Node

We need to be able to rewrite statements to convert a stmt such as:

		FROM users AS u
			INNER JOIN orders AS o
			ON u.user_id = o.user_id

 So that we can evaluate the Join Key on left/right
    in this case, it is simple, just

   =>   user_id

 or this one:

		FROM users AS u
			INNER JOIN orders AS o
			ON LOWER(u.email) = LOWER(o.email)

   =>  LOWER(user_id)

func (*SqlSource) Keyword

func (m *SqlSource) Keyword() lex.TokenType

func (*SqlSource) Rewrite

func (m *SqlSource) Rewrite(parentStmt *SqlSelect) *SqlSelect

Rewrite this Source to act as a stand-alone query to backend

@parentStmt = the parent statement that this a partial source to

func (*SqlSource) SourceName

func (m *SqlSource) SourceName() string

func (*SqlSource) String

func (m *SqlSource) String() string

func (*SqlSource) ToPB

func (m *SqlSource) ToPB() *SqlSourcePb

func (*SqlSource) UnAliasedColumns

func (m *SqlSource) UnAliasedColumns() map[string]*Column

Get a list of Un-Aliased Columns, ie columns with column

names that have NOT yet been aliased

type SqlSourcePb

type SqlSourcePb struct {
	Final            bool           `protobuf:"varint,1,opt,name=final" json:"final"`
	AliasInner       *string        `protobuf:"bytes,2,opt,name=aliasInner" json:"aliasInner,omitempty"`
	Columns          []*ColumnPb    `protobuf:"bytes,3,rep,name=columns" json:"columns,omitempty"`
	ColIndex         []KvInt        `protobuf:"bytes,4,rep,name=colIndex" json:"colIndex"`
	JoinNodes        []*expr.NodePb `protobuf:"bytes,5,rep,name=joinNodes" json:"joinNodes,omitempty"`
	Source           *SqlSelectPb   `protobuf:"bytes,6,opt,name=source" json:"source,omitempty"`
	Raw              string         `protobuf:"bytes,7,opt,name=raw" json:"raw"`
	Name             string         `protobuf:"bytes,8,opt,name=name" json:"name"`
	Alias            string         `protobuf:"bytes,9,opt,name=alias" json:"alias"`
	Op               int32          `protobuf:"varint,10,req,name=op" json:"op"`
	LeftOrRight      int32          `protobuf:"varint,11,req,name=leftOrRight" json:"leftOrRight"`
	JoinType         int32          `protobuf:"varint,12,req,name=joinType" json:"joinType"`
	JoinExpr         *expr.NodePb   `protobuf:"bytes,13,opt,name=joinExpr" json:"joinExpr,omitempty"`
	SubQuery         *SqlSelectPb   `protobuf:"bytes,14,opt,name=subQuery" json:"subQuery,omitempty"`
	Seekable         bool           `protobuf:"varint,15,opt,name=seekable" json:"seekable"`
	XXX_unrecognized []byte         `json:"-"`
}

func (*SqlSourcePb) Descriptor

func (*SqlSourcePb) Descriptor() ([]byte, []int)

func (*SqlSourcePb) GetAlias

func (m *SqlSourcePb) GetAlias() string

func (*SqlSourcePb) GetAliasInner

func (m *SqlSourcePb) GetAliasInner() string

func (*SqlSourcePb) GetColIndex

func (m *SqlSourcePb) GetColIndex() []KvInt

func (*SqlSourcePb) GetColumns

func (m *SqlSourcePb) GetColumns() []*ColumnPb

func (*SqlSourcePb) GetFinal

func (m *SqlSourcePb) GetFinal() bool

func (*SqlSourcePb) GetJoinExpr

func (m *SqlSourcePb) GetJoinExpr() *expr.NodePb

func (*SqlSourcePb) GetJoinNodes

func (m *SqlSourcePb) GetJoinNodes() []*expr.NodePb

func (*SqlSourcePb) GetJoinType

func (m *SqlSourcePb) GetJoinType() int32

func (*SqlSourcePb) GetLeftOrRight

func (m *SqlSourcePb) GetLeftOrRight() int32

func (*SqlSourcePb) GetName

func (m *SqlSourcePb) GetName() string

func (*SqlSourcePb) GetOp

func (m *SqlSourcePb) GetOp() int32

func (*SqlSourcePb) GetRaw

func (m *SqlSourcePb) GetRaw() string

func (*SqlSourcePb) GetSeekable

func (m *SqlSourcePb) GetSeekable() bool

func (*SqlSourcePb) GetSource

func (m *SqlSourcePb) GetSource() *SqlSelectPb

func (*SqlSourcePb) GetSubQuery

func (m *SqlSourcePb) GetSubQuery() *SqlSelectPb

func (*SqlSourcePb) Marshal

func (m *SqlSourcePb) Marshal() (data []byte, err error)

func (*SqlSourcePb) MarshalTo

func (m *SqlSourcePb) MarshalTo(data []byte) (int, error)

func (*SqlSourcePb) ProtoMessage

func (*SqlSourcePb) ProtoMessage()

func (*SqlSourcePb) Reset

func (m *SqlSourcePb) Reset()

func (*SqlSourcePb) Size

func (m *SqlSourcePb) Size() (n int)

func (*SqlSourcePb) String

func (m *SqlSourcePb) String() string

func (*SqlSourcePb) Unmarshal

func (m *SqlSourcePb) Unmarshal(data []byte) error

type SqlSourceStatement

type SqlSourceStatement interface {
	// string representation of Node, AST parseable back to itself
	String() string

	// string representation of Node, AST but with values replaced by @rune (? generally)
	//  used to allow statements to be deterministically cached/prepared even without
	//  usage of keyword prepared
	FingerPrint(r rune) string

	Keyword() lex.TokenType
}

The sqlStatement interface, to define the subselect/join-types

Join, SubSelect, From

type SqlStatement

type SqlStatement interface {
	// string representation of Node, AST parseable back to itself
	String() string

	// string representation of Node, AST but with values replaced by @rune (? generally)
	//  used to allow statements to be deterministically cached/prepared even without
	//  usage of keyword prepared
	FingerPrint(r rune) string

	// SQL keyword (select, insert, etc)
	Keyword() lex.TokenType
}

The sqlStatement interface, to define the sql statement

Select, Insert, Update, Delete, Command, Show, Describe etc

func ParseSql

func ParseSql(sqlQuery string) (SqlStatement, error)

ParseSql Parses SqlStatement and returns a statement or error

  • does not parse more than one statement

func ParseSqlStatements

func ParseSqlStatements(sqlQuery string) ([]SqlStatement, error)

func ParseSqlVm

func ParseSqlVm(sqlQuery string) (SqlStatement, error)

func SqlFromPb

func SqlFromPb(pb []byte) (SqlStatement, error)

Create a sql statement from pb

type SqlStatementPb

type SqlStatementPb struct {
	Select           *SqlSelectPb  `protobuf:"bytes,1,opt,name=select" json:"select,omitempty"`
	Source           *SqlSourcePb  `protobuf:"bytes,2,opt,name=source" json:"source,omitempty"`
	Projection       *ProjectionPb `protobuf:"bytes,4,opt,name=projection" json:"projection,omitempty"`
	XXX_unrecognized []byte        `json:"-"`
}

The generic SqlStatement, must be exactly one of these types

func (*SqlStatementPb) Descriptor

func (*SqlStatementPb) Descriptor() ([]byte, []int)

func (*SqlStatementPb) GetProjection

func (m *SqlStatementPb) GetProjection() *ProjectionPb

func (*SqlStatementPb) GetSelect

func (m *SqlStatementPb) GetSelect() *SqlSelectPb

func (*SqlStatementPb) GetSource

func (m *SqlStatementPb) GetSource() *SqlSourcePb

func (*SqlStatementPb) Marshal

func (m *SqlStatementPb) Marshal() (data []byte, err error)

func (*SqlStatementPb) MarshalTo

func (m *SqlStatementPb) MarshalTo(data []byte) (int, error)

func (*SqlStatementPb) ProtoMessage

func (*SqlStatementPb) ProtoMessage()

func (*SqlStatementPb) Reset

func (m *SqlStatementPb) Reset()

func (*SqlStatementPb) Size

func (m *SqlStatementPb) Size() (n int)

func (*SqlStatementPb) String

func (m *SqlStatementPb) String() string

func (*SqlStatementPb) Unmarshal

func (m *SqlStatementPb) Unmarshal(data []byte) error

type SqlTokenPager

type SqlTokenPager struct {
	*expr.LexTokenPager
	// contains filtered or unexported fields
}

TokenPager is responsible for determining end of current tree (column, etc)

func NewSqlTokenPager

func NewSqlTokenPager(l *lex.Lexer) *SqlTokenPager

func (*SqlTokenPager) ClauseEnd

func (m *SqlTokenPager) ClauseEnd() bool

func (*SqlTokenPager) IsEnd

func (m *SqlTokenPager) IsEnd() bool

type SqlUpdate

type SqlUpdate struct {
	Values map[string]*ValueColumn
	Where  *SqlWhere
	Table  string
}

SQL Update Statement

func NewSqlUpdate

func NewSqlUpdate() *SqlUpdate

func (*SqlUpdate) FingerPrint

func (m *SqlUpdate) FingerPrint(r rune) string

func (*SqlUpdate) Keyword

func (m *SqlUpdate) Keyword() lex.TokenType

func (*SqlUpdate) SqlSelect

func (m *SqlUpdate) SqlSelect() *SqlSelect

func (*SqlUpdate) String

func (m *SqlUpdate) String() string

type SqlUpsert

type SqlUpsert struct {
	Columns Columns
	Rows    [][]*ValueColumn
	Values  map[string]*ValueColumn
	Where   *SqlWhere
	Table   string
}

SQL Upsert Statement

func NewSqlUpsert

func NewSqlUpsert() *SqlUpsert

func (*SqlUpsert) FingerPrint

func (m *SqlUpsert) FingerPrint(r rune) string

func (*SqlUpsert) Keyword

func (m *SqlUpsert) Keyword() lex.TokenType

func (*SqlUpsert) SqlSelect

func (m *SqlUpsert) SqlSelect() *SqlSelect

func (*SqlUpsert) String

func (m *SqlUpsert) String() string

type SqlWhere

type SqlWhere struct {
	// Either Op + Source exists
	Op     lex.TokenType // (In|=|ON)  for Select Clauses operators
	Source *SqlSelect    // IN (SELECT a,b,c from z)

	// OR expr but not both
	Expr expr.Node // x = y AND q > 5
}

WHERE is select stmt, or set of expressions - WHERE x in (select name from q) - WHERE x = y - WHERE x = y AND z = q - WHERE tolower(x) IN (select name from q)

func NewSqlWhere

func NewSqlWhere(where expr.Node) *SqlWhere

func SqlWhereFromPb

func SqlWhereFromPb(pb *SqlWherePb) *SqlWhere

func (*SqlWhere) Equal

func (m *SqlWhere) Equal(s *SqlWhere) bool

func (*SqlWhere) FingerPrint

func (m *SqlWhere) FingerPrint(r rune) string

func (*SqlWhere) Keyword

func (m *SqlWhere) Keyword() lex.TokenType

func (*SqlWhere) String

func (m *SqlWhere) String() string

type SqlWherePb

type SqlWherePb struct {
	Op               int32        `protobuf:"varint,1,req,name=op" json:"op"`
	Source           *SqlSelectPb `protobuf:"bytes,2,opt,name=source" json:"source,omitempty"`
	Expr             *expr.NodePb `protobuf:"bytes,3,opt,name=Expr,json=expr" json:"Expr,omitempty"`
	XXX_unrecognized []byte       `json:"-"`
}

func SqlWhereToPb

func SqlWhereToPb(m *SqlWhere) *SqlWherePb

func (*SqlWherePb) Descriptor

func (*SqlWherePb) Descriptor() ([]byte, []int)

func (*SqlWherePb) GetExpr

func (m *SqlWherePb) GetExpr() *expr.NodePb

func (*SqlWherePb) GetOp

func (m *SqlWherePb) GetOp() int32

func (*SqlWherePb) GetSource

func (m *SqlWherePb) GetSource() *SqlSelectPb

func (*SqlWherePb) Marshal

func (m *SqlWherePb) Marshal() (data []byte, err error)

func (*SqlWherePb) MarshalTo

func (m *SqlWherePb) MarshalTo(data []byte) (int, error)

func (*SqlWherePb) ProtoMessage

func (*SqlWherePb) ProtoMessage()

func (*SqlWherePb) Reset

func (m *SqlWherePb) Reset()

func (*SqlWherePb) Size

func (m *SqlWherePb) Size() (n int)

func (*SqlWherePb) String

func (m *SqlWherePb) String() string

func (*SqlWherePb) Unmarshal

func (m *SqlWherePb) Unmarshal(data []byte) error

type Sqlbridge

type Sqlbridge struct {
	*SqlTokenPager
	// contains filtered or unexported fields
}

Sqlbridge generic SQL parser evaluates should be sufficient for most

sql compatible languages

type ValueColumn

type ValueColumn struct {
	Value value.Value
	Expr  expr.Node
}

List of Value columns in INSERT into TABLE (colnames) VALUES (valuecolumns)

Jump to

Keyboard shortcuts

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