CollectionComposer
CollectionComposer is the entry point of Asgarde. It wraps a PCollection, applies the steps of the flow with error
handling, and keeps the failures of all the steps.
Create a composer
Section titled “Create a composer”CollectionComposer.of(wordPCollection)CollectionComposer.of(wordPCollection)CollectionComposer.of(word_pcollection)Chain the steps
Section titled “Chain the steps”Each step has a name, used as the Beam transform name and as the pipelineStep of its failures.
The apply method accepts:
- the Beam
MapElementsandFlatMapElements: the composer addsexceptionsIntoandexceptionsViafor you; - the Asgarde
DoFnclasses:MapElementFn,MapProcessContextFn,FlatMapElementFn,FlatMapProcessContextFnandFilterFn(see Transforms); - your own
DoFnclasses extendingBaseElementFn(see Custom DoFn); - any
PTransformreturning aWithFailures.Result<PCollection<T>, Failure>.
CollectionComposer.of(input) .apply("Map", MapElements.into(TypeDescriptors.integers()).via((String word) -> 1 / word.length())) .apply("Filter", FilterFn.by(count -> count > 0))MapElements and FlatMapElements with your own exceptionsInto/exceptionsVia are accepted too, as long as they
produce Asgarde Failure objects:
CollectionComposer.of(input) .apply("Map", MapElements .into(TypeDescriptors.integers()) .via((String word) -> 1 / word.length()) .exceptionsInto(TypeDescriptor.of(Failure.class)) .exceptionsVia(exElt -> Failure.from("Map", exElt)))The Kotlin extensions give a concise syntax for each kind of step (see Kotlin extensions):
CollectionComposer.of(input) .map("Map") { word -> 1 / word.length } .filter("Filter") { count -> count > 0 }The composer exposes the map, flat_map and filter operators (see Operators):
(CollectionComposer.of(input) .map('Map', lambda word: 1 / len(word)) .filter('Filter', lambda count: count > 0))Get the result
Section titled “Get the result”getResult() returns a Beam WithFailures.Result with the output of the last step and the failures of all the
steps:
final WithFailures.Result<PCollection<Integer>, Failure> result = composer.getResult();
final PCollection<Integer> output = result.output();final PCollection<Failure> failures = result.failures();val result: Result<PCollection<Int>, Failure> = composer.result
val output: PCollection<Int> = result.output()val failures: PCollection<Failure> = result.failures()outputs = composer.outputs # Output of the last stepfailures = composer.failures # Failures of all the steps