Class ParseJsons<OutputT>
- All Implemented Interfaces:
Serializable,HasDisplayData
PTransform for parsing JSON Strings. Parse PCollection of Strings in JSON format into a PCollection of objects represented by those JSON
Strings using Jackson.- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class org.apache.beam.sdk.transforms.PTransform
annotations, displayData, name, resourceHints -
Method Summary
Modifier and TypeMethodDescription<NewFailureT>
ParseJsons<OutputT>.ParseJsonsWithFailures<NewFailureT> exceptionsInto(TypeDescriptor<NewFailureT> failureTypeDescriptor) Returns a newParseJsons.ParseJsonsWithFailurestransform that catches exceptions raised while parsing elements, with the given type descriptor used for the failure collection but the exception handler yet to be specified usingParseJsons.ParseJsonsWithFailures.exceptionsVia(ProcessFunction).Returns a newParseJsons.ParseJsonsWithFailurestransform that catches exceptions raised while parsing elements, passing the raised exception instance and the input element being processed through the default exception handlerParseJsons.DefaultExceptionAsMapHandlerand emitting the result to a failure collection.<FailureT> ParseJsons<OutputT>.ParseJsonsWithFailures<FailureT> exceptionsVia(InferableFunction<WithFailures.ExceptionElement<String>, FailureT> exceptionHandler) Returns a newParseJsons.ParseJsonsWithFailurestransform that catches exceptions raised while parsing elements, passing the raised exception instance and the input element being processed through the givenexceptionHandlerand emitting the result to a failure collection.expand(PCollection<String> input) Override this method to specify how thisPTransformshould be expanded on the givenInputT.static <OutputT> ParseJsons<OutputT> Creates aParseJsonsPTransformthat will parse JSONStringsinto aPCollection<OutputT>using a JacksonObjectMapper.withMapper(ObjectMapper mapper) Use custom JacksonObjectMapperinstead of the default one.Methods inherited from class org.apache.beam.sdk.transforms.PTransform
addAnnotation, compose, compose, getAdditionalInputs, getAnnotations, getDefaultOutputCoder, getDefaultOutputCoder, getDefaultOutputCoder, getKindString, getName, getResourceHints, populateDisplayData, setDisplayData, setResourceHints, toString, validate, validate
-
Method Details
-
of
Creates aParseJsonsPTransformthat will parse JSONStringsinto aPCollection<OutputT>using a JacksonObjectMapper. -
withMapper
Use custom JacksonObjectMapperinstead of the default one. -
exceptionsInto
public <NewFailureT> ParseJsons<OutputT>.ParseJsonsWithFailures<NewFailureT> exceptionsInto(TypeDescriptor<NewFailureT> failureTypeDescriptor) Returns a newParseJsons.ParseJsonsWithFailurestransform that catches exceptions raised while parsing elements, with the given type descriptor used for the failure collection but the exception handler yet to be specified usingParseJsons.ParseJsonsWithFailures.exceptionsVia(ProcessFunction).See
WithFailuresdocumentation for usage patterns of the returnedWithFailures.Result. -
exceptionsVia
public <FailureT> ParseJsons<OutputT>.ParseJsonsWithFailures<FailureT> exceptionsVia(InferableFunction<WithFailures.ExceptionElement<String>, FailureT> exceptionHandler) Returns a newParseJsons.ParseJsonsWithFailurestransform that catches exceptions raised while parsing elements, passing the raised exception instance and the input element being processed through the givenexceptionHandlerand emitting the result to a failure collection.See
WithFailuresdocumentation for usage patterns of the returnedWithFailures.Result.Example usage:
WithFailures.Result<PCollection<MyPojo>, KV<String, Map<String, String>>> result = json.apply( ParseJsons.of(MyPojo.class) .exceptionsVia(new WithFailures.ExceptionAsMapHandler<String>() {})); PCollection<MyPojo> output = result.output(); // valid POJOs PCollection<KV<String, Map<String, String>>> failures = result.failures(); -
exceptionsVia
Returns a newParseJsons.ParseJsonsWithFailurestransform that catches exceptions raised while parsing elements, passing the raised exception instance and the input element being processed through the default exception handlerParseJsons.DefaultExceptionAsMapHandlerand emitting the result to a failure collection.See
ParseJsons.DefaultExceptionAsMapHandlerfor more details about default handler behavior.See
WithFailuresdocumentation for usage patterns of the returnedWithFailures.Result.Example usage:
WithFailures.Result<PCollection<MyPojo>, KV<String, Map<String, String>>> result = json.apply( ParseJsons.of(MyPojo.class) .exceptionsVia()); PCollection<MyPojo> output = result.output(); // valid POJOs PCollection<KV<String, Map<String, String>>> failures = result.failures(); -
expand
Description copied from class:PTransformOverride this method to specify how thisPTransformshould be expanded on the givenInputT.NOTE: This method should not be called directly. Instead apply the
PTransformshould be applied to theInputTusing theapplymethod.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:
expandin classPTransform<PCollection<String>,PCollection<OutputT>>
-