Meta
Meta transforms apply other transforms.
meta.err
Catches errors returned by other transforms and returns messages.
Settings
Field | Type | Description | Required |
---|---|---|---|
transform | object | Transform 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
Field | Type | Description | Required |
---|---|---|---|
object.source_key | string | Retrieves a value from an object for transformation. | Yes |
object.target_key | string | Places a value into an object after transformation. | Yes |
transform | object | Transform 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
Field | Type | Description | Required |
---|---|---|---|
metric.name | string | Name of the metric. | Yes |
metric.destination | object | Metrics Destination configuration that reports the metric to an external system. | Yes |
transform | object | Transform that is applied. | Yes |
metric.attributes | map | Map (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
Field | Type | Description | Required |
---|---|---|---|
object.source_key | string | Retrieves a value from an object for transformation. | No |
object.target_key | string | Sets a value into an object after transformation. | No |
transforms | object | Transforms 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
Field | Type | Description | Required |
---|---|---|---|
cases.condition | []object | Array of conditions that apply a transform. | No |
cases.transform | []object | Array 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.
Updated 10 months ago