import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.Function;
import java.util.Arrays;
import java.util.List;
/**
* saveastextfile 算子:
*
* 将RDD的数据进行保存
* 会生成一个textSaveAsTextFile文件夹,如果文件存在则抛出异常
*
*/
public class SaveAsTextFileOperator {
public static void main(String[] args) {
SparkConf conf = new SparkConf().setMaster("local").setAppName("saveAsTextFile");
JavaSparkContext sc = new JavaSparkContext(conf);
List<String> names = Arrays.asList("w1","w2","w3");
JavaRDD<String> namerdd = sc.parallelize(names);
JavaRDD<String> result = namerdd.map(new Function<String, String>() {
@Override
public String call(String v1) throws Exception {
return "RDD:"+v1;
}
});
result.saveAsTextFile("./saveAsTextRdd");
}
}
微信扫描下图二维码加入博主知识星球,获取更多大数据、人工智能、算法等免费学习资料哦!