-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
29 additions
and
42 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
examples/build/config/transform/array/group/config.jsonnet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// This example groups an array of arrays into an array of objects | ||
// based on index and configured keys. | ||
local sub = import '../../../../../../build/config/substation.libsonnet'; | ||
|
||
local files_key = 'meta files'; | ||
|
||
{ | ||
concurrency: 1, | ||
transforms: [ | ||
// This example sends data to stdout at each step to iteratively show | ||
// how the data is transformed. | ||
sub.tf.send.stdout(), | ||
// Copy the object to metadata, where it is grouped. | ||
sub.tf.obj.cp({ object: { target_key: files_key } }), | ||
// Elements from the file_name array are transformed and derived file extensions | ||
// are added to a new array. | ||
sub.tf.meta.for_each({ | ||
object: { source_key: sub.helpers.object.get_element(files_key, 'file_name'), target_key: sub.helpers.object.append(files_key, 'file_extension') }, | ||
transform: sub.tf.string.capture(settings={ pattern: '\\.([^\\.]+)$' }), | ||
}), | ||
// The arrays grouped into an array of objects, then copied to the message's data field. | ||
// For example: | ||
// | ||
// [{name: name1, type: type1, size: size1, extension: extension1}, {name: name2, type: type2, size: size2, extension: extension2}] | ||
sub.tf.object.cp({ object: { source_key: files_key + '|@group' } }), | ||
sub.tf.send.stdout(), | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"file_name":["foo.txt","bar.html"],"file_type":["text/plain","text/html"],"file_size":[100,500]} |
41 changes: 0 additions & 41 deletions
41
examples/build/config/transform/array/to_object/config.jsonnet
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.