Example usage for org.apache.spark.api.java.function PairFunction call

List of usage examples for org.apache.spark.api.java.function PairFunction call

Introduction

In this page you can find the example usage for org.apache.spark.api.java.function PairFunction call.

Prototype

Tuple2<K, V> call(T t) throws Exception;

Source Link

Usage

From source file:org.apache.beam.runners.spark.translation.TranslationUtils.java

License:Apache License

/**
 * A utility method that adapts {@link PairFunction} to a {@link PairFlatMapFunction} with an
 * {@link Iterator} input. This is particularly useful because it allows to use functions written
 * for mapToPair functions in flatmapToPair functions.
 *
 * @param pairFunction the {@link PairFunction} to adapt.
 * @param <T> the input type.//  w w  w .j a va2  s . c om
 * @param <K> the output key type.
 * @param <V> the output value type.
 * @return a {@link PairFlatMapFunction} that accepts an {@link Iterator} as an input and applies
 *     the {@link PairFunction} on every element.
 */
public static <T, K, V> PairFlatMapFunction<Iterator<T>, K, V> pairFunctionToPairFlatMapFunction(
        final PairFunction<T, K, V> pairFunction) {
    return itr -> Iterators.transform(itr, t -> {
        try {
            return pairFunction.call(t);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    });
}

From source file:org.apache.crunch.fn.SFunctions.java

License:Apache License

public static <T, K, V> SPairFunction<T, K, V> wrap(final PairFunction<T, K, V> f) {
    return new SPairFunction<T, K, V>() {
        @Override/*w  w  w . j  ava  2 s .  c  om*/
        public Tuple2<K, V> call(T t) throws Exception {
            return f.call(t);
        }
    };
}