Class AsJsons.AsJsonsWithFailures<FailureT>

java.lang.Object
org.apache.beam.sdk.transforms.PTransform<PCollection<InputT>,WithFailures.Result<PCollection<String>,FailureT>>
org.apache.beam.sdk.extensions.jackson.AsJsons.AsJsonsWithFailures<FailureT>
All Implemented Interfaces:
Serializable, HasDisplayData
Enclosing class:
AsJsons<InputT>

public class AsJsons.AsJsonsWithFailures<FailureT> extends PTransform<PCollection<InputT>,WithFailures.Result<PCollection<String>,FailureT>>
A PTransform that adds exception handling to AsJsons.
See Also:
  • Method Details

    • exceptionsVia

      Returns a new AsJsons.AsJsonsWithFailures transform that catches exceptions raised while writing JSON elements, passing the raised exception instance and the input element being processed through the given exceptionHandler and emitting the result to a failure collection. It is supposed to be used along with AsJsons.exceptionsInto(TypeDescriptor) and get lambda function as exception handler.

      See WithFailures documentation for usage patterns of the returned WithFailures.Result.

      Example usage:

      
       WithFailures.Result<PCollection<String>, KV<MyPojo, Map<String, String>>> result =
           pojos.apply(
               AsJsons.of(MyPojo.class)
                   .exceptionsInto(
                       TypeDescriptors.kvs(
                           TypeDescriptor.of(MyPojo.class), TypeDescriptors.strings()))
                   .exceptionsVia(
                       f -> KV.of(f.element(), f.exception().getClass().getCanonicalName())));
      
       PCollection<String> output = result.output(); // valid json elements
       PCollection<KV<MyPojo, Map<String, String>>> failures = result.failures();
       
    • expand

      Description copied from class: PTransform
      Override this method to specify how this PTransform should be expanded on the given InputT.

      NOTE: This method should not be called directly. Instead apply the PTransform should be applied to the InputT using the apply method.

      Composite transforms, which are defined in terms of other transforms, should return the output of one of the composed transforms. Non-composite transforms, which do not apply any transforms internally, should return a new unbound output and register evaluators (via backend-specific registration methods).

      Specified by:
      expand in class PTransform<PCollection<InputT>,WithFailures.Result<PCollection<String>,FailureT>>