我有rdd:
JavaPairRDD<Long, ViewRecord> myRDD
它是通过 newAPIHadoopRDD
方法。我有一个已经存在的map函数,我想用spark的方式实现它:
LongWritable one = new LongWritable(1L);
protected void map(Long key, ViewRecord viewRecord, Context context)
throws IOException ,InterruptedException {
String url = viewRecord.getUrl();
long day = viewRecord.getDay();
tuple.getKey().set(url);
tuple.getValue().set(day);
context.write(tuple, one);
};
ps:元组派生自:
KeyValueWritable<Text, LongWritable>
可以在这里找到:textlong.java
1条答案
按热度按时间jvlzgdj91#
我不知道什么是元组,但如果你只是想用键把记录Map到元组
(url, day)
和价值1L
你可以这样做: