Documentation
¶
Overview ¶
Package cep 实现 MATCH_RECOGNIZE 模式识别(SQL:2016)。
架构:
- pattern.go 组合式模式树 → NFA(Thompson 构造),支持序列/量词/选择/分组/PERMUTE。
- nfa.go NFA 状态机 + epsilon 闭包。
- eval.go DEFINE/MEASURES 求值:表达式在 NewEngine 期预编译(prepare), 导航/聚合/符号限定字段改写为占位符,复用手写 expr 引擎求值。
- engine.go 分区 NFA 模拟 + LRU + WITHIN/行数上限(有界)+ MEASURES 投影 + 匹配输出。
CEP 是独立子系统,不依赖也不污染现有直连/窗口/分析路径与三套求值器。
Index ¶
- func EvalDefine(cond string, buffer []map[string]any, labels []string, ...) bool
- func EvalDefineWithSubsets(cond string, buffer []map[string]any, labels []string, ...) bool
- func EvalMeasure(expression string, rows []map[string]any, labels []string, ...) (any, bool)
- func EvalMeasureWithSubsets(expression string, rows []map[string]any, labels []string, ...) (any, bool)
- func Validate(spec *types.MatchRecognizeSpec) error
- type Engine
- func (e *Engine) Flush() []map[string]any
- func (e *Engine) Process(row map[string]any, partitionKey string) []map[string]any
- func (e *Engine) SetLogger(l logger.Logger)
- func (e *Engine) SetMaxPartitions(n int)
- func (e *Engine) SetMaxRunRows(n int)
- func (e *Engine) SetMaxRuns(n int)
- func (e *Engine) Start()
- func (e *Engine) Stop()
- type NFA
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EvalDefine ¶
func EvalDefine(cond string, buffer []map[string]any, labels []string, candidate map[string]any, candLabel string, symbols map[string]bool) bool
EvalDefine 即时编译并求值符号的 DEFINE 条件(布尔)。仅供测试/外部使用; 引擎热路径用 Engine.evalDefine(预编译产物)。buffer=已匹配行,candidate=待分类行。 不携带 SUBSET 成员表——含 SUBSET 限定的引用(如 S.v)需用 EvalDefineWithSubsets。
func EvalDefineWithSubsets ¶
func EvalDefineWithSubsets(cond string, buffer []map[string]any, labels []string, candidate map[string]any, candLabel string, symbols map[string]bool, subsets map[string][]string) bool
EvalDefineWithSubsets 同 EvalDefine,但携带 SUBSET 成员表,支持 SUBSET 限定的引用。
func EvalMeasure ¶
func EvalMeasure(expression string, rows []map[string]any, labels []string, cur, matchNumber int, symbols map[string]bool) (any, bool)
EvalMeasure 即时编译并求值 MEASURES 表达式(值)。仅供测试/外部使用。 不携带 SUBSET 成员表——含 SUBSET 限定的引用需用 EvalMeasureWithSubsets。
func EvalMeasureWithSubsets ¶
func EvalMeasureWithSubsets(expression string, rows []map[string]any, labels []string, cur, matchNumber int, symbols map[string]bool, subsets map[string][]string) (any, bool)
EvalMeasureWithSubsets 同 EvalMeasure,但携带 SUBSET 成员表,支持 SUBSET 限定的引用。
func Validate ¶
func Validate(spec *types.MatchRecognizeSpec) error
Validate 校验 spec 可编译(模式树、ORDER BY、DEFINE/MEASURES 表达式)。供 Execute 期 fail-fast。
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine 是一个 MATCH_RECOGNIZE 查询的 CEP 引擎:按分区维护 NFA 运行态,逐事件推进, 匹配完成时产出 MEASURES 投影行。线程安全(Process 串行;分区 LRU)。
func NewEngine ¶
func NewEngine(spec *types.MatchRecognizeSpec) (*Engine, error)
NewEngine 编译 spec 为 NFA 并构建引擎,预编译全部 DEFINE/MEASURES 表达式。
func (*Engine) Flush ¶
Flush 冲刷所有分区中「已可接受但未终结」的部分匹配(如流末未界的 A+ 突发)。 适配器在 Stop 时调用,避免流末未闭合的匹配丢失。返回冲刷出的输出行。