我已根据spark website配置了所有内容,以启动一个简单的火花应用 ,它会读取并计算文件中的行并在另一个文件中显示数字 。但我无法运行该应用程序,因为 我收到了很多错误 而且我不明白什么是错的。
这是我的项目结构:
from x import
的pom.xml
sparkExamples
|-- pom.xml
`-- src
|-- main/java/org/sparkExamplex/App.java
`-- resources
|-- readLine
|-- outputReadLine
App.java
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sparkexamples</groupId>
<artifactId>sparkExamples</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>sparkExamples</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency> <!-- Spark dependency -->
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
<version>1.3.1</version>
</dependency>
</dependencies>
</project>
错误显示:
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.JavaPairRDD;
import org.apache.spark.api.java.function.FlatMapFunction;
import org.apache.spark.api.java.function.Function2;
import org.apache.spark.api.java.function.PairFunction;
import scala.Tuple2;
import java.util.Arrays;
import java.util.regex.Pattern;
public final class App {
private static final Pattern SPACE = Pattern.compile(" ");
public static void main(String[] args) throws Exception {
String inputFile = "resources/readLine";
String outputFile = "resources/outputReadLine";
// Create a Java Spark Context.
SparkConf conf = new SparkConf().setAppName("wordCount").setMaster("spark://127.0.0.1:7077");
JavaSparkContext sc = new JavaSparkContext(conf);
// Load our input data.
JavaRDD<String> input = sc.textFile(inputFile);
// Split up into words.
JavaRDD<String> words = input.flatMap(new FlatMapFunction<String, String>() {
public Iterable<String> call(String x) {
return Arrays.asList(x.split(" "));
}
});
// Transform into word and count.
JavaPairRDD<String, Integer> counts = words.mapToPair(new PairFunction<String, String, Integer>() {
public Tuple2<String, Integer> call(String x) {
return new Tuple2(x, 1);
}
}).reduceByKey(new Function2<Integer, Integer, Integer>() {
public Integer call(Integer x, Integer y) {
return x + y;
}
});
// Save the word count back out to a text file, causing evaluation.
counts.saveAsTextFile(outputFile);
}
}
}
有人可以让我知道如何做到这一点吗?
提前感谢。
答案 0 :(得分:1)
经过多次评论,我们可以总结出如下答案:
简而言之,这个问题是重复的。 我希望这个答案可以帮到你。