HomeGuides
Try a DemoGet the Latest ReleaseSee the CHANGELOGCreate a Feature Request / Bug ReportJoin the Conversation
Guides

Meta

Meta transforms apply other transforms.

meta.err

Catches errors returned by other transforms and returns messages.

Settings

FieldTypeDescriptionRequired
transformobjectTransform that is applied.Yes

Example

sub.tf.meta.err(
  settings={transform: sub.tf.enrich.http.get([...])}
)
sub.tf.meta.err({transform: sub.tf.enrich.http.get([...])})

meta.for_each

Applies transform to every element of a JSON array.

Settings

FieldTypeDescriptionRequired
object.source_keystringRetrieves a value from an object for transformation.Yes
object.target_keystringPlaces a value into an object after transformation.Yes
transformobjectTransform that is applied.Yes

Example

sub.tf.meta.for_each(
  settings={object: {source_key: 'arr', target_key: 'arr'}, transform: sub.tf.enrich.http.get([...])}
)
sub.tf.meta.for_each({obj: {src: 'arr', trg: 'arr'}, transform: sub.tf.enrich.http.get([...])})

meta.metric.duration

Generates a metric that reports the execution time (duration) of the transform.

Settings

FieldTypeDescriptionRequired
metric.namestringName of the metric.Yes
metric.destinationobjectMetrics Destination configuration that reports the metric to an external system.Yes
transformobjectTransform that is applied.Yes
metric.attributesmapMap (dictionary) of strings that are included in the metric as attributes or labels.No

Example

sub.tf.meta.metric.duration(
  settings={
    metric: { name: 'ObjectCopyDuration', destination: { type: 'aws_cloudwatch_embedded_metrics' } },
    transform: sub.tf.object.copy(
      settings={ object: { source_key: 'a', target_key: 'z' } },
    ),
  },
)
sub.tf.meta.metric.duration({
  metric: { name: 'ObjectCopyDuration', destination: { type: 'aws_cloudwatch_embedded_metrics' } },
  transform: sub.tf.object.copy({ obj: { src: 'a', trg: 'z' } }),
})

meta.pipeline

Applies multiple transform in a series.

Settings

FieldTypeDescriptionRequired
object.source_keystringRetrieves a value from an object for transformation.No
object.target_keystringSets a value into an object after transformation.No
transformsobjectTransforms that are applied.Yes

Example

sub.tf.meta.pipeline(
  settings={transforms: [
    sub.tf.enrich.http.get([...]),
    sub.tf.object.copy([...]),
  ]}
)
sub.tf.meta.pipe(
  settings={transforms: [
    sub.tf.enrich.http.get([...]),
    sub.tf.obj.cp([...]),
  ]}
)

meta.switch

Conditionally applies transforms using conditional statements:

  • if
  • if ... else
  • if ... elif ... else

Settings

FieldTypeDescriptionRequired
cases.condition[]objectArray of conditions that apply a transform.No
cases.transform[]objectArray of transforms conditionally applied.Yes

Example

sub.tf.meta.switch(
  settings={ cases: [
    {condition: [...], transform: [...]},
    {condition: [...], transform: [...]},
  ]}
)

Use Cases

If Statement

An if statement is created by configuring a single meta.switch statement. This examples copies a string value if it contains a specific character:

sub.tf.meta.switch(
  settings={ cases: [
    { 
      condition: sub.cnd.any(sub.cnd.string.contains(settings={object: {source_key: 'a'}, value: 'b'}),
      transform: sub.tf.object.copy(settings={object: {source_key: 'a', target_key: 'z'}}),
    }
  ]}
)
sub.tf.meta.switch(
  settings={ switch: [
    { 
      condition: sub.cnd.any(sub.cnd.str.has(settings={object: {src: 'a'}, value: 'b'}),
      transform: sub.tf.obj.cp(settings={object: {src: 'a', trg: 'z'}}),
    }
  ]}
)
sub.pattern.tf.conditional(
  // tf.conditional pattern automatically applies the ANY operator if no operator is provided.
  condition=sub.cnd.str.contains(settings={obj: {src: 'a'}, value: 'b'},
  transform=sub.tf.obj.cp(settings={obj: {src: 'a', trg: 'z'}}),
)

If ... Else Statement

An if ... else statement is created by configuring two meta.switch statements:

  • The first statement is configured with a condition
  • The second statement is configured without a condition

This example aggregates JSON text into an array, otherwise the messages are dropped if they are not valid JSON.

sub.tf.meta.switch(
  settings={ cases: [
    { 
      condition: sub.cnd.any(sub.cnd.format.json()),
      transform: sub.tf.aggregate.to.array(),
    },
    {
      transform: sub.tf.utility.drop(),
    }
  ]}
)
sub.tf.meta.switch(
  settings={ switch: [
    { 
      condition: sub.cnd.any(sub.cnd.fmt.json()),
      transform: sub.tf.agg.to.arr(),
    },
    {
      transform: sub.tf.util.drop(),
    }
  ]}
)

More statements can be added to create if ... elif ... else statements.