spark flatMapToPair to create keys of different type

狂风中的少年 提交于 2019-12-11 11:25:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!