expr

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeNumber      = "number"      // 数字常量
	TypeField       = "field"       // 字段引用
	TypeOperator    = "operator"    // 运算符
	TypeFunction    = "function"    // 函数调用
	TypeParenthesis = "parenthesis" // 括号
	TypeCase        = "case"        // CASE表达式
	TypeString      = "string"      // 字符串常量
)

表达式类型

Variables

This section is empty.

Functions

This section is empty.

Types

type ExprNode

type ExprNode struct {
	Type  string
	Value string
	Left  *ExprNode
	Right *ExprNode
	Args  []*ExprNode // 用于函数调用的参数

	// CASE表达式专用字段
	CaseExpr    *ExprNode    // CASE后面的表达式(简单CASE)
	WhenClauses []WhenClause // WHEN子句列表
	ElseExpr    *ExprNode    // ELSE表达式
}

表达式节点

type Expression

type Expression struct {
	Root *ExprNode
	// contains filtered or unexported fields
}

Expression 表示一个可计算的表达式

func NewExpression

func NewExpression(exprStr string) (*Expression, error)

NewExpression 创建一个新的表达式

func (*Expression) Evaluate

func (e *Expression) Evaluate(data map[string]interface{}) (float64, error)

Evaluate 计算表达式的值

func (*Expression) EvaluateWithNull

func (e *Expression) EvaluateWithNull(data map[string]interface{}) (float64, bool, error)

EvaluateWithNull 提供公开接口,用于聚合函数调用

func (*Expression) GetFields

func (e *Expression) GetFields() []string

GetFields 获取表达式中引用的所有字段

type WhenClause

type WhenClause struct {
	Condition *ExprNode // WHEN条件
	Result    *ExprNode // THEN结果
}

CASE表达式的WHEN子句

Jump to

Keyboard shortcuts

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