1
我想出來的火花簡單NGRAM例如
這是我的POM依賴
<dependencies>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-mllib_2.10</artifactId>
<version>2.2.0</version>
</dependency>
</dependencies>
下面的示例代碼
public class App {
public static void main(String[] args) {
System.out.println("Hello World!");
System.setProperty("hadoop.home.dir", "D:\\del");
SparkSession spark = SparkSession
.builder()
.appName("JavaNGramExample").config("spark.master", "local")
.getOrCreate();
List<Row> data = Arrays.asList(RowFactory.create(0, Arrays.asList("car", "killed", "cat")),
RowFactory.create(1, Arrays.asList("train", "killed", "cat")),
RowFactory.create(2, Arrays.asList("john", "plays", "cricket")),
RowFactory.create(3, Arrays.asList("tom", "likes", "mangoes")));
StructType schema = new StructType(new StructField[] {
new StructField("id", DataTypes.IntegerType, false, Metadata.empty()),
new StructField("words", DataTypes.createArrayType(DataTypes.StringType), false, Metadata.empty()) });
Dataset<Row> wordDataFrame = spark.createDataFrame(data, schema);
NGram ngramTransformer = new NGram().setN(2).setInputCol("words").setOutputCol("ngrams");
Dataset<Row> ngramDataFrame = ngramTransformer.transform(wordDataFrame);
System.out.println(" DISPLAY NGRAMS ");
ngramDataFrame.select("ngrams").show(false);
}
}
我提示以下錯誤:當我運行這個代碼。
Exception in thread "main" java.lang.NoClassDefFoundError: scala/collection/GenTraversableOnce$class
at org.apache.spark.sql.types.StructType.<init>(StructType.scala:98)
at com.mypackage.spark.learnspark.App.main(App.java:61)
Caused by: java.lang.ClassNotFoundException: scala.collection.GenTraversableOnce$class
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 2 more
我查階的依賴,這是斯卡拉庫-2.11.8
是否有火花2.2.0和我的斯卡拉罐子有不一致之處?