问题
For the following codes using spark
java
API:
JavaPairRDD<TypeOne,Long> pairs = originalRows.flatMapToPair(new PairFlatMapFunction<OriginalType,TypeOne,Long>()
it takes the RDD
, named OriginalType
and maps it into pairs with key type of TypeOne
.
I am wondering that is it possible to takes OriginalType
and during the map step, maps it into two types of key? Like TypeOne
and TypeTwo
. Or I must use two map steps to realize this...
回答1:
You can create an Interface or Generic class that both types will implement/inherit and use this instead of the specific type.
public interface IType { }
public class TypeOne implements IType { }
public class TypeTwo implements IType { }
JavaPairRDD<IType,Long> pairs = originalRows.flatMapToPair(new PairFlatMapFunction<OriginalType,IType,Long>()
来源:https://stackoverflow.com/questions/29260756/spark-flatmaptopair-to-create-keys-of-different-type