remap

package
v1.2.2 Latest Latest
Warning

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

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

README

Remap

The Remap transform component uses an expr-based engine to transform incoming messages by applying custom remapping logic.


Class Definition

class Remap extends Transform {
  fixed sourceName = "remap"
  code: String
}

Attributes

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

I/O Types

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

Pkl Configuration Example

Basic Remap Transform
new Transforms.Remap {
  name = "example-remap"
  code = "{ "value_name": Data.name, "value_price": Data.price }"
}

Description

The Remap transform component allows you to transform or modify incoming messages based on custom rules defined in the expr language. This is particularly useful for altering the structure or content of messages before they are passed downstream.


Unit Test Example in Go

The following test demonstrates remapping a message by extracting specific fields and creating a new structure:

{
	name: "test expr maps return nil",
	args: args{
		val: map[string]any{
			"id":       1,
			"name":     "iPhone 12",
			"price":    999,
			"quantity": 1,
		},
		code: "{ "value_name": Data.name, "value_price": Data.price }",
	},
	want: map[string]any{
		"value_name":  "iPhone 12",
		"value_price": 999,
	},
},

Pkl Configuration Matching Unit Test

The equivalent Pkl configuration for the test case above:

new Transforms.Remap {
  name = "remap-extract-fields"
  code = "{ "value_name": Data.name, "value_price": Data.price }"
}

Use Cases

  1. Data Transformation
    • Modify fields in incoming messages, such as scaling values or changing formats.
  2. Data Enrichment
    • Add new fields or compute derived values based on existing fields.

Notes

  • The code attribute must be a valid expr rule.
  • Ensure the rule logic aligns with the structure of incoming messages for accurate transformations.

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 Config

type Config struct {
	Code string `pipelane:"code"`
}

type EnvMap

type EnvMap struct {
	Data any
}

type Remap

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

func (*Remap) Init

func (e *Remap) Init(cfg transform.Transform) error

func (*Remap) Transform

func (e *Remap) Transform(val any) any

Jump to

Keyboard shortcuts

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