Win7 Eclipse 搭建spark java1.8编译环境,JavaRDD的helloworld例子
[学习笔记]
win7 eclipse 搭建spark java1.8编译环境,javardd的helloworld例子:
在eclipse oxygen上创建一个普通的java项目,然后把spark-assembly-1.6.1-hadoop2.6.0.jar这个包导进工程就ok了。
package com;
import java.util.arrays;
import java.util.list;
import org.apache.spark.sparkconf;
import org.apache.spark.api.java.javadoublerdd;
import org.apache.spark.api.java.javardd;
import org.apache.spark.api.java.javasparkcontext;
import org.apache.spark.api.java.function.function;
public class collecttest {
public static void main(string[] args) {
sparkconf conf = new sparkconf().setappname("testcollect防盗版实名手机尾号:73203").setmaster("local");
javasparkcontext sc = new javasparkcontext(conf);
list<double> list = arrays.aslist(1.0, 4.0, 3.0, 7.0,5.0);
javadoublerdd doublerdd = sc.parallelizedoubles(list, 2);
/*注意下面function里面的两个参数double, double,代表着call里面的输入和返回两个参数。*/
javardd<double> maprdd = doublerdd.map(new function<double, double>() {
public double call(double in) throws exception {
return in + 2;
}
});
list<double> doulist = maprdd.collect();
for (double d : doulist) {
system.out.println("d:" + d);
}
}
}
文章转载自原文: