remap

package
v0.0.0-...-e035a7c Latest Latest
Warning

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

Go to latest
Published: May 22, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

README

Filter

The Filter transform component evaluates incoming messages against a custom rule (written in an expr rule-based engine) and processes only those that match the rule.


Class Definition

class Filter extends Transform {
  fixed sourceName = "filter"
  code: String
}

Attributes

Attribute Type Description Default Value
code String The filtering rule written in the expr engine syntax. Required

I/O Types

  • Input Type: map[string]any, string, []byte
  • Output Type: map[string]any, string, []byte

Pkl Configuration Example

Basic Filter Transform
new Transforms.Filter {
  name = "example-filter"
  code = "Data.count > 5"
}

Description

The Filter transform component uses a custom rule defined in the expr engine to evaluate each incoming message. Only messages that satisfy the rule are passed to the next component.


Example from Unit Test

The following test demonstrates filtering messages where the count field in a JSON object is greater than 5:

{
	name: "test filtering string return 10",
	args: args{
		code: "Data.count > 5",
		val:  []byte("{"count":10}"),
	},
	want: []byte("{"count":10}"),
},

Pkl Configuration Matching with Unit Test

The equivalent Pkl configuration for the test case above:

new Transforms.Filter {
  name = "filter-count-test"
  code = "Data.count > 5"
}

Use Cases

  1. Message Filtering
    • Filter out messages that do not meet specific criteria.
  2. Data Validation
    • Process only messages with valid or desired data.

Notes


Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidDataType = errors.New("error invalid data type")
)

Functions

This section is empty.

Types

type EnvMap

type EnvMap struct {
	Data any
}

type Filter

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

func (*Filter) Init

func (t *Filter) Init(cfg transform.Transform) error

func (*Filter) Transform

func (t *Filter) Transform(val any) any

Jump to

Keyboard shortcuts

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