transform

package
v0.0.0-...-0f04091 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SafeEnv

func SafeEnv() map[string]any

SafeEnv 返回沙箱化表达式运行环境

Types

type Config

type Config struct {
	Rules  []MappingRule `json:"mapping_rules"`
	Filter string        `json:"filter_expr,omitempty"` // 过滤条件,返回 bool
}

Config 任务级转换配置

type Engine

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

func NewEngine

func NewEngine() *Engine

NewEngine 初始化映射引擎(线程安全)

func (*Engine) Compile

func (e *Engine) Compile(cfg Config) error

Compile 预编译所有映射规则与过滤表达式(任务启动时调用一次)

func (*Engine) Execute

func (e *Engine) Execute(ctx context.Context, row map[string]any) (map[string]any, bool, error)

Execute 逐行执行:过滤 → 映射 → 返回结果 返回值: (目标行, 是否通过过滤, 错误)

type Manager

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

Manager 管理任务级转换引擎的生命周期

func NewManager

func NewManager() *Manager

func (*Manager) CompileAndCache

func (m *Manager) CompileAndCache(taskID string, cfg Config) error

CompileAndCache 预编译配置并缓存。若已存在则覆盖。

func (*Manager) Get

func (m *Manager) Get(taskID string) (*Engine, bool)

Get 获取已缓存的引擎。未编译或不存在返回 false。

func (*Manager) Invalidate

func (m *Manager) Invalidate(taskID string)

Invalidate 清理缓存(任务删除/配置变更时调用)

type MappingRule

type MappingRule struct {
	TargetCol string `json:"target_col"`
	SourceCol string `json:"source_col,omitempty"` // 直连字段(可选)
	Expr      string `json:"expr"`                 // 表达式(优先级高于 SourceCol)
}

MappingRule 定义目标字段的映射来源或计算表达式

Jump to

Keyboard shortcuts

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