Java Code Examples for org.apache.beam.sdk.annotations.Experimental.Kind#WITH_EXCEPTIONS

The following examples show how to use org.apache.beam.sdk.annotations.Experimental.Kind#WITH_EXCEPTIONS . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParseJsons.java    From beam with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a new {@link ParseJsonsWithFailures} transform that catches exceptions raised while
 * parsing elements, passing the raised exception instance and the input element being processed
 * through the given {@code exceptionHandler} and emitting the result to a failure collection.
 *
 * <p>See {@link WithFailures} documentation for usage patterns of the returned {@link
 * WithFailures.Result}.
 *
 * <p>Example usage:
 *
 * <pre>{@code
 * 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();
 * }</pre>
 */
@Experimental(Kind.WITH_EXCEPTIONS)
public <FailureT> ParseJsonsWithFailures<FailureT> exceptionsVia(
    InferableFunction<WithFailures.ExceptionElement<String>, FailureT> exceptionHandler) {
  return new ParseJsonsWithFailures<>(
      exceptionHandler, exceptionHandler.getOutputTypeDescriptor());
}
 
Example 2
Source File: ParseJsons.java    From beam with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a new {@link ParseJsonsWithFailures} transform that catches exceptions raised while
 * parsing elements, passing the raised exception instance and the input element being processed
 * through the default exception handler {@link DefaultExceptionAsMapHandler} and emitting the
 * result to a failure collection.
 *
 * <p>See {@link DefaultExceptionAsMapHandler} for more details about default handler behavior.
 *
 * <p>See {@link WithFailures} documentation for usage patterns of the returned {@link
 * WithFailures.Result}.
 *
 * <p>Example usage:
 *
 * <pre>{@code
 * 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();
 * }</pre>
 */
@Experimental(Kind.WITH_EXCEPTIONS)
public ParseJsonsWithFailures<KV<String, Map<String, String>>> exceptionsVia() {
  DefaultExceptionAsMapHandler<String> exceptionHandler =
      new DefaultExceptionAsMapHandler<String>() {};
  return new ParseJsonsWithFailures<>(
      exceptionHandler, exceptionHandler.getOutputTypeDescriptor());
}
 
Example 3
Source File: AsJsons.java    From beam with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a new {@link AsJsonsWithFailures} transform that catches exceptions raised while
 * writing JSON elements, passing the raised exception instance and the input element being
 * processed through the default exception handler {@link DefaultExceptionAsMapHandler} and
 * emitting the result to a failure collection.
 *
 * <p>See {@link DefaultExceptionAsMapHandler} for more details about default handler behavior.
 *
 * <p>See {@link WithFailures} documentation for usage patterns of the returned {@link
 * WithFailures.Result}.
 *
 * <p>Example usage:
 *
 * <pre>{@code
 * WithFailures.Result<PCollection<String>, KV<MyPojo, Map<String, String>>> result =
 *     pojos.apply(
 *         AsJsons.of(MyPojo.class)
 *             .exceptionsVia());
 *
 * PCollection<String> output = result.output(); // valid json elements
 * PCollection<KV<MyPojo, Map<String, String>>> failures = result.failures();
 * }</pre>
 */
@Experimental(Kind.WITH_EXCEPTIONS)
public AsJsonsWithFailures<KV<InputT, Map<String, String>>> exceptionsVia() {
  DefaultExceptionAsMapHandler<InputT> exceptionHandler =
      new DefaultExceptionAsMapHandler<InputT>() {};
  return new AsJsonsWithFailures<>(exceptionHandler, exceptionHandler.getOutputTypeDescriptor());
}
 
Example 4
Source File: FlatMapElements.java    From beam with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a new {@link FlatMapWithFailures} transform that catches exceptions raised while
 * mapping elements, with the given type descriptor used for the failure collection but the
 * exception handler yet to be specified using {@link
 * FlatMapWithFailures#exceptionsVia(ProcessFunction)}.
 *
 * <p>See {@link WithFailures} documentation for usage patterns of the returned {@link
 * WithFailures.Result}.
 */
@Experimental(Kind.WITH_EXCEPTIONS)
public <NewFailureT> FlatMapWithFailures<InputT, OutputT, NewFailureT> exceptionsInto(
    TypeDescriptor<NewFailureT> failureTypeDescriptor) {
  return new FlatMapWithFailures<>(
      fn, originalFnForDisplayData, inputType, outputType, null, failureTypeDescriptor);
}
 
Example 5
Source File: FlatMapElements.java    From beam with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a new {@link FlatMapWithFailures} transform that catches exceptions raised while
 * mapping elements, passing the raised exception instance and the input element being processed
 * through the given {@code exceptionHandler} and emitting the result to a failure collection.
 *
 * <p>This method takes advantage of the type information provided by {@link InferableFunction},
 * meaning that a call to {@link #exceptionsInto(TypeDescriptor)} may not be necessary.
 *
 * <p>See {@link WithFailures} documentation for usage patterns of the returned {@link
 * WithFailures.Result}.
 *
 * <p>Example usage:
 *
 * <pre>{@code
 * Result<PCollection<String>, String>> result = words.apply(
 *     FlatMapElements
 *         .into(TypeDescriptors.strings())
 *         // Could throw ArrayIndexOutOfBoundsException
 *         .via((String line) -> Arrays.asList(Arrays.copyOfRange(line.split(" "), 1, 5)))
 *         .exceptionsVia(new WithFailures.ExceptionAsMapHandler<String>() {}));
 * PCollection<String> output = result.output();
 * PCollection<String> failures = result.failures();
 * }</pre>
 */
@Experimental(Kind.WITH_EXCEPTIONS)
public <FailureT> FlatMapWithFailures<InputT, OutputT, FailureT> exceptionsVia(
    InferableFunction<ExceptionElement<InputT>, FailureT> exceptionHandler) {
  return new FlatMapWithFailures<>(
      fn,
      originalFnForDisplayData,
      inputType,
      outputType,
      exceptionHandler,
      exceptionHandler.getOutputTypeDescriptor());
}
 
Example 6
Source File: MapElements.java    From beam with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a new {@link MapWithFailures} transform that catches exceptions raised while mapping
 * elements, with the given type descriptor used for the failure collection but the exception
 * handler yet to be specified using {@link MapWithFailures#exceptionsVia(ProcessFunction)}.
 *
 * <p>See {@link WithFailures} documentation for usage patterns of the returned {@link
 * WithFailures.Result}.
 */
@Experimental(Kind.WITH_EXCEPTIONS)
public <NewFailureT> MapWithFailures<InputT, OutputT, NewFailureT> exceptionsInto(
    TypeDescriptor<NewFailureT> failureTypeDescriptor) {
  return new MapWithFailures<>(
      fn, originalFnForDisplayData, inputType, outputType, null, failureTypeDescriptor);
}
 
Example 7
Source File: MapElements.java    From beam with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a new {@link MapWithFailures} transform that catches exceptions raised while mapping
 * elements, passing the raised exception instance and the input element being processed through
 * the given {@code exceptionHandler} and emitting the result to a failure collection.
 *
 * <p>This method takes advantage of the type information provided by {@link InferableFunction},
 * meaning that a call to {@link #exceptionsInto(TypeDescriptor)} may not be necessary.
 *
 * <p>See {@link WithFailures} documentation for usage patterns of the returned {@link
 * WithFailures.Result}.
 *
 * <p>Example usage:
 *
 * <pre>{@code
 * Result<PCollection<String>, String>> result = words.apply(
 *     MapElements
 *         .into(TypeDescriptors.integers())
 *         .via((String word) -> 1 / word.length)  // Could throw ArithmeticException
 *         .exceptionsVia(new WithFailures.ExceptionAsMapHandler<String>() {}));
 * PCollection<Integer> output = result.output();
 * PCollection<String> failures = result.failures();
 * }</pre>
 */
@Experimental(Kind.WITH_EXCEPTIONS)
public <FailureT> MapWithFailures<InputT, OutputT, FailureT> exceptionsVia(
    InferableFunction<ExceptionElement<InputT>, FailureT> exceptionHandler) {
  return new MapWithFailures<>(
      fn,
      originalFnForDisplayData,
      inputType,
      outputType,
      exceptionHandler,
      exceptionHandler.getOutputTypeDescriptor());
}
 
Example 8
Source File: ParseJsons.java    From beam with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a new {@link ParseJsonsWithFailures} transform 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 using {@link
 * ParseJsonsWithFailures#exceptionsVia(ProcessFunction)}.
 *
 * <p>See {@link WithFailures} documentation for usage patterns of the returned {@link
 * WithFailures.Result}.
 */
@Experimental(Kind.WITH_EXCEPTIONS)
public <NewFailureT> ParseJsonsWithFailures<NewFailureT> exceptionsInto(
    TypeDescriptor<NewFailureT> failureTypeDescriptor) {
  return new ParseJsonsWithFailures<>(null, failureTypeDescriptor);
}
 
Example 9
Source File: AsJsons.java    From beam with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a new {@link AsJsonsWithFailures} transform that catches exceptions raised while
 * writing JSON elements, with the given type descriptor used for the failure collection but the
 * exception handler yet to be specified using {@link
 * AsJsonsWithFailures#exceptionsVia(ProcessFunction)}.
 *
 * <p>See {@link WithFailures} documentation for usage patterns of the returned {@link
 * WithFailures.Result}.
 */
@Experimental(Kind.WITH_EXCEPTIONS)
public <NewFailureT> AsJsonsWithFailures<NewFailureT> exceptionsInto(
    TypeDescriptor<NewFailureT> failureTypeDescriptor) {
  return new AsJsonsWithFailures<>(null, failureTypeDescriptor);
}
 
Example 10
Source File: AsJsons.java    From beam with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a new {@link AsJsonsWithFailures} transform that catches exceptions raised while
 * writing JSON elements, passing the raised exception instance and the input element being
 * processed through the given {@code exceptionHandler} and emitting the result to a failure
 * collection.
 *
 * <p>See {@link WithFailures} documentation for usage patterns of the returned {@link
 * WithFailures.Result}.
 *
 * <p>Example usage:
 *
 * <pre>{@code
 * WithFailures.Result<PCollection<String>, KV<MyPojo, Map<String, String>>> result =
 *     pojos.apply(
 *         AsJsons.of(MyPojo.class)
 *             .exceptionsVia(new WithFailures.ExceptionAsMapHandler<MyPojo>() {}));
 *
 * PCollection<String> output = result.output(); // valid json elements
 * PCollection<KV<MyPojo, Map<String, String>>> failures = result.failures();
 * }</pre>
 */
@Experimental(Kind.WITH_EXCEPTIONS)
public <FailureT> AsJsonsWithFailures<FailureT> exceptionsVia(
    InferableFunction<WithFailures.ExceptionElement<InputT>, FailureT> exceptionHandler) {
  return new AsJsonsWithFailures<>(exceptionHandler, exceptionHandler.getOutputTypeDescriptor());
}