rsql

package
v0.0.0-...-662b5c6 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatErrorContext

func FormatErrorContext(input string, position int, contextLength int) string

FormatErrorContext 格式化错误上下文

func Parse

func Parse(sql string) (*types.Config, string, error)

Parse 是包级别的Parse函数,用于解析SQL字符串并返回配置和条件

func ParseAggregateTypeWithExpression

func ParseAggregateTypeWithExpression(exprStr string) (aggType aggregator.AggregateType, name string, expression string, allFields []string)

解析聚合函数,并返回表达式信息

Types

type ErrorRecovery

type ErrorRecovery struct {
	// contains filtered or unexported fields
}

ErrorRecovery 错误恢复策略

func NewErrorRecovery

func NewErrorRecovery(parser *Parser) *ErrorRecovery

NewErrorRecovery 创建错误恢复实例

func (*ErrorRecovery) AddError

func (er *ErrorRecovery) AddError(err *ParseError)

AddError 添加错误

func (*ErrorRecovery) GetErrors

func (er *ErrorRecovery) GetErrors() []*ParseError

GetErrors 获取所有错误

func (*ErrorRecovery) HasErrors

func (er *ErrorRecovery) HasErrors() bool

HasErrors 检查是否有错误

func (*ErrorRecovery) RecoverFromError

func (er *ErrorRecovery) RecoverFromError(errorType ErrorType) bool

RecoverFromError 从错误中恢复

type ErrorType

type ErrorType int

ErrorType 定义错误类型

const (
	ErrorTypeSyntax ErrorType = iota
	ErrorTypeLexical
	ErrorTypeSemantics
	ErrorTypeUnexpectedToken
	ErrorTypeMissingToken
	ErrorTypeInvalidExpression
	ErrorTypeUnknownKeyword
	ErrorTypeInvalidNumber
	ErrorTypeUnterminatedString
	ErrorTypeMaxIterations
	ErrorTypeUnknownFunction
)

type Field

type Field struct {
	Expression string
	Alias      string
	AggType    string
}

type FunctionCall

type FunctionCall struct {
	Name     string
	Position int
}

FunctionCall 函数调用信息

type FunctionValidator

type FunctionValidator struct {
	// contains filtered or unexported fields
}

FunctionValidator 函数验证器

func NewFunctionValidator

func NewFunctionValidator(errorRecovery *ErrorRecovery) *FunctionValidator

NewFunctionValidator 创建函数验证器

func (*FunctionValidator) ValidateExpression

func (fv *FunctionValidator) ValidateExpression(expression string, position int)

ValidateExpression 验证表达式中的函数

type Lexer

type Lexer struct {
	// contains filtered or unexported fields
}

func NewLexer

func NewLexer(input string) *Lexer

func (*Lexer) GetPosition

func (l *Lexer) GetPosition() (int, int, int)

GetPosition 获取当前位置信息

func (*Lexer) NextToken

func (l *Lexer) NextToken() Token

func (*Lexer) SetErrorRecovery

func (l *Lexer) SetErrorRecovery(er *ErrorRecovery)

SetErrorRecovery 设置错误恢复实例

type ParseError

type ParseError struct {
	Type        ErrorType
	Message     string
	Position    int
	Line        int
	Column      int
	Token       string
	Expected    []string
	Suggestions []string
	Context     string
	Recoverable bool
}

ParseError 增强的解析错误结构

func CreateLexicalError

func CreateLexicalError(message string, position int, char byte) *ParseError

CreateLexicalError 创建词法错误

func CreateLexicalErrorWithPosition

func CreateLexicalErrorWithPosition(message string, position int, line int, column int, char byte) *ParseError

CreateLexicalErrorWithPosition 创建词法错误(带准确位置信息)

func CreateMissingTokenError

func CreateMissingTokenError(expected string, position int) *ParseError

CreateMissingTokenError 创建缺失token错误

func CreateSyntaxError

func CreateSyntaxError(message string, position int, token string, expected []string) *ParseError

CreateSyntaxError 创建语法错误

func CreateUnexpectedTokenError

func CreateUnexpectedTokenError(found string, expected []string, position int) *ParseError

CreateUnexpectedTokenError 创建意外token错误

func CreateUnknownFunctionError

func CreateUnknownFunctionError(functionName string, position int) *ParseError

CreateUnknownFunctionError 创建未知函数错误

func (*ParseError) Error

func (e *ParseError) Error() string

Error 实现 error 接口

func (*ParseError) IsRecoverable

func (e *ParseError) IsRecoverable() bool

IsRecoverable 检查错误是否可恢复

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

func NewParser

func NewParser(input string) *Parser

func (*Parser) GetErrors

func (p *Parser) GetErrors() []*ParseError

GetErrors 获取解析过程中的所有错误

func (*Parser) HasErrors

func (p *Parser) HasErrors() bool

HasErrors 检查是否有错误

func (*Parser) Parse

func (p *Parser) Parse() (*SelectStatement, error)

type SelectStatement

type SelectStatement struct {
	Fields    []Field
	Distinct  bool
	SelectAll bool // 新增:标识是否是SELECT *查询
	Source    string
	Condition string
	Window    WindowDefinition
	GroupBy   []string
	Limit     int
	Having    string
}

func (*SelectStatement) ToStreamConfig

func (s *SelectStatement) ToStreamConfig() (*types.Config, string, error)

ToStreamConfig 将AST转换为Stream配置

type Token

type Token struct {
	Type   TokenType
	Value  string
	Pos    int
	Line   int
	Column int
}

type TokenType

type TokenType int
const (
	TokenEOF TokenType = iota
	TokenIdent
	TokenNumber
	TokenString
	TokenComma
	TokenLParen
	TokenRParen
	TokenPlus
	TokenMinus
	TokenAsterisk
	TokenSlash
	TokenEQ
	TokenNE
	TokenGT
	TokenLT
	TokenGE
	TokenLE
	TokenAND
	TokenOR
	TokenSELECT
	TokenFROM
	TokenWHERE
	TokenGROUP
	TokenBY
	TokenAS
	TokenTumbling
	TokenSliding
	TokenCounting
	TokenSession
	TokenWITH
	TokenTimestamp
	TokenTimeUnit
	TokenOrder
	TokenDISTINCT
	TokenLIMIT
	TokenHAVING
	TokenLIKE
	TokenIS
	TokenNULL
	TokenNOT
	// CASE表达式相关token
	TokenCASE
	TokenWHEN
	TokenTHEN
	TokenELSE
	TokenEND
	// 数组索引相关token
	TokenLBracket
	TokenRBracket
)

type WindowDefinition

type WindowDefinition struct {
	Type     string
	Params   []interface{}
	TsProp   string
	TimeUnit time.Duration
}

Jump to

Keyboard shortcuts

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