System memory 259522560 must be at least 4.718592

我不是女神ヾ 2021-10-29 08:10 240阅读 0赞

[学习笔记]

/*没有下面的话, 会报一个错误,java.lang.IllegalArgumentException: System memory 259522560 must be at least 4.718592E8(470M). Please use a larger heap size.这是memory不够,导致无法启动SparkContext*/
conf.set(“spark.testing.memory”, “2000000000”);
JavaSparkContext sc = new JavaSparkContext(conf);
/*下面的这种倒入的方法也行*/
// JavaRDD text = sc.textFile(“hdfs://localhost:9000/README.txt”);
/*原文件是:o1abc 45
o1abc 77
o1abc o1abc */
JavaRDD text = sc.textFile(“E://temp//input//friend.txt”);
List strList = text.collect();
/*输出str:o1abc 45
str:o1abc 77
str:o1abc o1abc*/
for (String str : strList) {
System.out.println(“str:” + str);
}
/*Interface FlatMapFunction, Iterable call(T t)(注意之后的版本,返回值有所变化。)*/
JavaRDD words = text.flatMap(new FlatMapFunction() {
/*List的super Interface 是java.lang.Iterable*/
public Iterable call(String line) throws Exception {
System.out.println(“flatMap once, line is “+line );
String[] wordsArray=line.split(“ “);
List wordsList=Arrays.asList(wordsArray);
return wordsList;
}
});
List wordsList = words.collect();
/*输出
flatMap once, line is o1abc 45
flatMap once, line is o1abc 77
flatMap once, line is o1abc o1abc

word:o1abc
word:45
word:o1abc
word:77
word:o1abc
word:o1abc*/
for (String word : wordsList) {
System.out.println(“word:” + word);
}
/* http://spark.apache.org/docs/latest/
Interface PairFunction
A function that returns key-value pairs (Tuple2), and can be used to construct PairRDDs.
scala.Tuple2 call(T t)
*/
/*
flatMap once, line is o1abc 45(这句说明前面语句再次被执行)
in tuple2 word: o1abc

文章转载原文:https://blog.csdn.net/qq_44596980/article/details/93385009

转载于:https://www.cnblogs.com/haima1949/p/11338429.html

发表评论

表情:
评论列表 (有 0 条评论,240人围观)

还没有评论,来说两句吧...

相关阅读