Documentation
¶
Overview ¶
Package sql provides SQL query parsing and execution for DataFrames
Index ¶
- Constants
- type Executor
- type FromClause
- type Function
- type GroupByClause
- type HavingClause
- type JoinClause
- type JoinType
- type Lexer
- type LimitClause
- type OrderByClause
- type OrderByItem
- type OrderDirection
- type Parser
- type Query
- 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) (*Query, error)
- func (e *SQLExecutor) RegisterTable(name string, df *dataframe.DataFrame)
- func (e *SQLExecutor) ValidateQuery(query string) error
- type SQLTranslator
- func (t *SQLTranslator) ClearTables()
- func (t *SQLTranslator) GetRegisteredTables() []string
- func (t *SQLTranslator) TranslateFunctionCall(fn *Function) (expr.Expr, error)
- func (t *SQLTranslator) TranslateStatement(stmt Statement) (*dataframe.LazyFrame, error)
- func (t *SQLTranslator) ValidateSQLSyntax(stmt Statement) error
- type SelectItem
- type SelectStatement
- type Statement
- type StatementType
- 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.
const ( // OffsetOnlyLimit is a special value used in LimitClause.Count to indicate // that this is an OFFSET-only query (no LIMIT constraint). OffsetOnlyLimit = -1 )
Constants for LIMIT clause handling.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Executor ¶ added in v0.3.1
type Executor struct {
// contains filtered or unexported fields
}
Executor executes SQL queries against registered DataFrames.
func NewExecutor ¶ added in v0.3.1
NewExecutor creates a new SQL executor.
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 Query ¶ added in v0.3.1
type Query struct {
// contains filtered or unexported fields
}
Query represents a prepared SQL query for reuse.
type SQLExecutor ¶
type SQLExecutor struct {
// contains filtered or unexported fields
}
SQLExecutor is deprecated, use Executor instead.
func NewSQLExecutor ¶
func NewSQLExecutor(mem memory.Allocator) *SQLExecutor
NewSQLExecutor creates a new SQL executor. Deprecated: Use NewExecutor instead.
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) (*Query, 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 SQLTranslator ¶
type SQLTranslator struct {
*sqlutil.BaseTranslator
// 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) TranslateFunctionCall ¶
func (t *SQLTranslator) TranslateFunctionCall(fn *Function) (expr.Expr, error)
TranslateFunctionCall translates SQL function calls to Gorilla expressions.
func (*SQLTranslator) TranslateStatement ¶
func (t *SQLTranslator) TranslateStatement(stmt Statement) (*dataframe.LazyFrame, error)
TranslateStatement translates a SQL statement to a LazyFrame.
func (*SQLTranslator) ValidateSQLSyntax ¶
func (t *SQLTranslator) ValidateSQLSyntax(stmt Statement) 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() StatementType
func (*SelectStatement) String ¶
func (s *SelectStatement) String() string
type Statement ¶ added in v0.3.1
type Statement interface {
StatementType() StatementType
String() string
}
Statement interface for all SQL statement types.
type StatementType ¶ added in v0.3.1
type StatementType int
StatementType represents the type of SQL statement.
const ( SelectStatementType StatementType = iota InsertStatementType UpdateStatementType DeleteStatementType )
type TokenType ¶
type TokenType int
TokenType represents the type of a SQL token.
const ( // EOF represents end of file token. EOF TokenType = iota ILLEGAL // IDENT represents identifier tokens like column names, table names, function names. IDENT INT // integers FLOAT // floating point numbers STRING // string literals // SELECT represents the SELECT keyword. 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 // EQ represents the equals operator (=). EQ NE // != or <> LT // < LE // <= GT // > GE // >= PLUS // + MINUS // - MULT // * DIV // / MOD // % // COMMA represents the comma delimiter (,). COMMA SEMICOLON // ; LPAREN // ( RPAREN // ) DOT // . )
type WhereClause ¶
WhereClause represents the WHERE clause.
func (*WhereClause) String ¶
func (w *WhereClause) String() string