V1
- the type of the values in the input PCollection
V2
- the type of the elements in the output PCollection
public class MapValues<K,V1,V2> extends PTransform<PCollection<KV<K,V1>>,PCollection<KV<K,V2>>>
MapValues
maps a SerializableFunction<V1,V2>
over values of a PCollection<KV<K,V1>>
and returns a PCollection<KV<K, V2>>
.
Example of use:
PCollection<KV<String, Integer>> input = ...;
PCollection<KV<String, Double> output =
input.apply(MapValues.into(TypeDescriptors.doubles()).via(Integer::doubleValue));
See also MapKeys
.
name, resourceHints
Modifier and Type | Method and Description |
---|---|
<FailureT> org.apache.beam.sdk.transforms.SimpleMapWithFailures<KV<K,V1>,KV<K,V2>,FailureT> |
exceptionsInto(TypeDescriptor<FailureT> failureTypeDescriptor)
Returns a new
SimpleMapWithFailures 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 SimpleMapWithFailures.exceptionsVia(ProcessFunction) . |
<FailureT> org.apache.beam.sdk.transforms.SimpleMapWithFailures<KV<K,V1>,KV<K,V2>,FailureT> |
exceptionsVia(InferableFunction<WithFailures.ExceptionElement<KV<K,V1>>,FailureT> exceptionHandler)
Returns a new
SimpleMapWithFailures transform that catches exceptions raised while
mapping elements, passing the raised exception instance and the input element being processed
through the given exceptionHandler and emitting the result to a failure collection. |
PCollection<KV<K,V2>> |
expand(PCollection<KV<K,V1>> input)
Override this method to specify how this
PTransform should be expanded on the given
InputT . |
static <V2> MapValues<?,?,V2> |
into(TypeDescriptor<V2> outputType)
Returns a new
MapValues transform with the given type descriptor for the output type,
but the mapping function yet to be specified using via(SerializableFunction) . |
<NewKeyT,NewValueT> |
via(SerializableFunction<NewValueT,V2> fn)
|
compose, compose, getAdditionalInputs, getDefaultOutputCoder, getDefaultOutputCoder, getDefaultOutputCoder, getKindString, getName, getResourceHints, populateDisplayData, setResourceHints, toString, validate
public <NewKeyT,NewValueT> MapValues<NewKeyT,NewValueT,V2> via(SerializableFunction<NewValueT,V2> fn)
NewKeyT
- the type of the keys in the input and output PCollection
sNewValueT
- the type of the values in the input PCollection
public static <V2> MapValues<?,?,V2> into(TypeDescriptor<V2> outputType)
MapValues
transform with the given type descriptor for the output type,
but the mapping function yet to be specified using via(SerializableFunction)
.@RequiresNonNull(value="fn") public <FailureT> org.apache.beam.sdk.transforms.SimpleMapWithFailures<KV<K,V1>,KV<K,V2>,FailureT> exceptionsInto(TypeDescriptor<FailureT> failureTypeDescriptor)
SimpleMapWithFailures
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 SimpleMapWithFailures.exceptionsVia(ProcessFunction)
.
See WithFailures
documentation for usage patterns of the returned WithFailures.Result
.
Example usage:
Result<PCollection<KV<String, Integer>>, String> result =
input.apply(
MapValues.into(TypeDescriptors.integers())
.<String, String>via(word -> 1 / word.length) // Could throw ArithmeticException
.exceptionsInto(TypeDescriptors.strings())
.exceptionsVia(ee -> ee.exception().getMessage()));
PCollection<KV<String, Integer>> output = result.output();
PCollection<String> failures = result.failures();
@RequiresNonNull(value="fn") public <FailureT> org.apache.beam.sdk.transforms.SimpleMapWithFailures<KV<K,V1>,KV<K,V2>,FailureT> exceptionsVia(InferableFunction<WithFailures.ExceptionElement<KV<K,V1>>,FailureT> exceptionHandler)
SimpleMapWithFailures
transform that catches exceptions raised while
mapping elements, passing the raised exception instance and the input element being processed
through the given exceptionHandler
and emitting the result to a failure collection.
This method takes advantage of the type information provided by InferableFunction
,
meaning that a call to exceptionsInto(TypeDescriptor)
may not be necessary.
See WithFailures
documentation for usage patterns of the returned WithFailures.Result
.
Example usage:
{@code Result>, String> result = input.apply( MapValues.into(TypeDescriptors.integers()) . via(word -> 1 / word.length) // Could throw ArithmeticException .exceptionsVia( new InferableFunction >, String>() {
public PCollection<KV<K,V2>> expand(PCollection<KV<K,V1>> input)
PTransform
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).
expand
in class PTransform<PCollection<KV<K,V1>>,PCollection<KV<K,V2>>>