Documentation
¶
Overview ¶
Package sql provides SQL query parsing and execution for DataFrames
Index ¶
- Constants
- type FromClause
- type GroupByClause
- type HavingClause
- type JoinClause
- type JoinType
- type Lexer
- type LimitClause
- type OrderByClause
- type OrderByItem
- type OrderDirection
- type Parser
- type SQLExecutor
- func (e *SQLExecutor) BatchExecute(queries []string) ([]*dataframe.DataFrame, error)
- func (e *SQLExecutor) ClearTables()
- func (e *SQLExecutor) Execute(query string) (*dataframe.DataFrame, error)
- func (e *SQLExecutor) Explain(query string) (string, error)
- func (e *SQLExecutor) GetRegisteredTables() []string
- func (e *SQLExecutor) PrepareQuery(query string) (*SQLQuery, error)
- func (e *SQLExecutor) RegisterTable(name string, df *dataframe.DataFrame)
- func (e *SQLExecutor) ValidateQuery(query string) error
- type SQLFunction
- type SQLQuery
- type SQLStatement
- type SQLStatementType
- type SQLTranslator
- func (t *SQLTranslator) ClearTables()
- func (t *SQLTranslator) GetRegisteredTables() []string
- func (t *SQLTranslator) RegisterTable(name string, df *dataframe.DataFrame)
- func (t *SQLTranslator) TranslateFunctionCall(fn *SQLFunction) (expr.Expr, error)
- func (t *SQLTranslator) TranslateStatement(stmt SQLStatement) (*dataframe.LazyFrame, error)
- func (t *SQLTranslator) ValidateSQLSyntax(stmt SQLStatement) error
- type SelectItem
- type SelectStatement
- type Token
- type TokenType
- type WhereClause
Constants ¶
const ( AscOrder = "ASC" DescOrder = "DESC" )
Sort directions
const ( CountFunction = "COUNT" SumFunction = "SUM" AvgFunction = "AVG" MinFunction = "MIN" MaxFunction = "MAX" )
Aggregation functions
const ( UpperFunction = "UPPER" LowerFunction = "LOWER" LengthFunction = "LENGTH" TrimFunction = "TRIM" SubstrFunction = "SUBSTR" )
String functions
const ( AbsFunction = "ABS" RoundFunction = "ROUND" FloorFunction = "FLOOR" CeilFunction = "CEIL" )
Math functions
const ( NowFunction = "NOW" DateAddFunction = "DATE_ADD" DateSubFunction = "DATE_SUB" DateDiffFunction = "DATE_DIFF" ExtractFunction = "EXTRACT" )
Date functions
const ( LOWEST int LOGICAL // AND, OR EQUALS // == LESSGREATER // > or < SUMPREC // + (precedence) PRODUCT // * PREFIX // -X or !X CALL // myFunction(X) )
Precedence constants for expression parsing
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FromClause ¶
type FromClause struct {
TableName string
Alias string
Joins []JoinClause
}
FromClause represents the FROM clause with table references
func (*FromClause) String ¶
func (f *FromClause) String() string
type GroupByClause ¶
GroupByClause represents the GROUP BY clause
func (*GroupByClause) String ¶
func (g *GroupByClause) String() string
type HavingClause ¶
HavingClause represents the HAVING clause
func (*HavingClause) String ¶
func (h *HavingClause) String() string
type JoinClause ¶
JoinClause represents a JOIN clause
func (*JoinClause) String ¶
func (j *JoinClause) String() string
type Lexer ¶
type Lexer struct {
// contains filtered or unexported fields
}
Lexer tokenizes SQL input
type LimitClause ¶
LimitClause represents the LIMIT clause
func (*LimitClause) String ¶
func (l *LimitClause) String() string
type OrderByClause ¶
type OrderByClause struct {
OrderItems []OrderByItem
}
OrderByClause represents the ORDER BY clause
func (*OrderByClause) String ¶
func (o *OrderByClause) String() string
type OrderByItem ¶
type OrderByItem struct {
Expression expr.Expr
Direction OrderDirection
}
OrderByItem represents an item in the ORDER BY clause
func (*OrderByItem) String ¶
func (o *OrderByItem) String() string
type OrderDirection ¶
type OrderDirection int
OrderDirection represents sort direction
const ( AscendingOrder OrderDirection = iota DescendingOrder )
func (OrderDirection) String ¶
func (od OrderDirection) String() string
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses SQL tokens into AST
type SQLExecutor ¶
type SQLExecutor struct {
// contains filtered or unexported fields
}
SQLExecutor executes SQL queries against registered DataFrames
func NewSQLExecutor ¶
func NewSQLExecutor(mem memory.Allocator) *SQLExecutor
NewSQLExecutor creates a new SQL executor
func (*SQLExecutor) BatchExecute ¶
func (e *SQLExecutor) BatchExecute(queries []string) ([]*dataframe.DataFrame, error)
BatchExecute executes multiple SQL statements in sequence
func (*SQLExecutor) ClearTables ¶
func (e *SQLExecutor) ClearTables()
ClearTables removes all registered tables
func (*SQLExecutor) Execute ¶
func (e *SQLExecutor) Execute(query string) (*dataframe.DataFrame, error)
Execute executes a SQL query and returns the result DataFrame
func (*SQLExecutor) Explain ¶
func (e *SQLExecutor) Explain(query string) (string, error)
Explain returns the execution plan for a SQL query
func (*SQLExecutor) GetRegisteredTables ¶
func (e *SQLExecutor) GetRegisteredTables() []string
GetRegisteredTables returns the list of registered table names
func (*SQLExecutor) PrepareQuery ¶
func (e *SQLExecutor) PrepareQuery(query string) (*SQLQuery, error)
PrepareQuery prepares a SQL query for multiple executions
func (*SQLExecutor) RegisterTable ¶
func (e *SQLExecutor) RegisterTable(name string, df *dataframe.DataFrame)
RegisterTable registers a DataFrame with a table name
func (*SQLExecutor) ValidateQuery ¶
func (e *SQLExecutor) ValidateQuery(query string) error
ValidateQuery validates a SQL query without executing it
type SQLFunction ¶
SQLFunction represents a SQL function call
func (*SQLFunction) String ¶
func (f *SQLFunction) String() string
type SQLQuery ¶
type SQLQuery struct {
// contains filtered or unexported fields
}
SQLQuery represents a prepared SQL query for reuse
type SQLStatement ¶
type SQLStatement interface {
StatementType() SQLStatementType
String() string
}
SQLStatement interface for all SQL statement types
func ParseSQL ¶
func ParseSQL(input string) (SQLStatement, error)
ParseSQL is the main entry point for SQL parsing
type SQLStatementType ¶
type SQLStatementType int
SQLStatementType represents the type of SQL statement
const ( SelectStatementType SQLStatementType = iota InsertStatementType UpdateStatementType DeleteStatementType )
type SQLTranslator ¶
type SQLTranslator struct {
// contains filtered or unexported fields
}
SQLTranslator translates SQL AST to DataFrame operations
func NewSQLTranslator ¶
func NewSQLTranslator(mem memory.Allocator) *SQLTranslator
NewSQLTranslator creates a new SQL translator
func (*SQLTranslator) ClearTables ¶
func (t *SQLTranslator) ClearTables()
ClearTables removes all registered tables
func (*SQLTranslator) GetRegisteredTables ¶
func (t *SQLTranslator) GetRegisteredTables() []string
GetRegisteredTables returns the list of registered table names
func (*SQLTranslator) RegisterTable ¶
func (t *SQLTranslator) RegisterTable(name string, df *dataframe.DataFrame)
RegisterTable registers a DataFrame with a table name for SQL queries
func (*SQLTranslator) TranslateFunctionCall ¶
func (t *SQLTranslator) TranslateFunctionCall(fn *SQLFunction) (expr.Expr, error)
TranslateFunctionCall translates SQL function calls to Gorilla expressions
func (*SQLTranslator) TranslateStatement ¶
func (t *SQLTranslator) TranslateStatement(stmt SQLStatement) (*dataframe.LazyFrame, error)
TranslateStatement translates a SQL statement to a LazyFrame
func (*SQLTranslator) ValidateSQLSyntax ¶
func (t *SQLTranslator) ValidateSQLSyntax(stmt SQLStatement) error
ValidateSQLSyntax performs basic validation of SQL statement
type SelectItem ¶
SelectItem represents an item in the SELECT list
func (*SelectItem) String ¶
func (s *SelectItem) String() string
type SelectStatement ¶
type SelectStatement struct {
SelectList []SelectItem
FromClause *FromClause
WhereClause *WhereClause
GroupByClause *GroupByClause
HavingClause *HavingClause
OrderByClause *OrderByClause
LimitClause *LimitClause
}
SelectStatement represents a SQL SELECT statement
func (*SelectStatement) StatementType ¶
func (s *SelectStatement) StatementType() SQLStatementType
func (*SelectStatement) String ¶
func (s *SelectStatement) String() string
type TokenType ¶
type TokenType int
TokenType represents the type of a SQL token
const ( // Special tokens EOF TokenType = iota ILLEGAL // Literals IDENT // column names, table names, function names INT // integers FLOAT // floating point numbers STRING // string literals // Keywords SELECT FROM WHERE GROUP BY HAVING ORDER LIMIT OFFSET AS AND OR NOT IN EXISTS NULL TRUE FALSE JOIN INNER LEFT RIGHT FULL ON COUNT SUM AVG MIN MAX DISTINCT // Operators EQ // = NE // != or <> LT // < LE // <= GT // > GE // >= PLUS // + MINUS // - MULT // * DIV // / MOD // % // Delimiters COMMA // , SEMICOLON // ; LPAREN // ( RPAREN // ) DOT // . )
type WhereClause ¶
WhereClause represents the WHERE clause
func (*WhereClause) String ¶
func (w *WhereClause) String() string