forked from imtiazahmad007/sparkwithjava
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest-dev-env
28 lines (20 loc) · 1004 Bytes
/
test-dev-env
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package com.jobreadyprogrammer.spark;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SparkSession;
public class Application {
public static void main(String args[]) {
SparkSession spark = SparkSession.builder().appName("Name").master("local").getOrCreate();
Dataset<Row> df = spark.read().format("text").load("src/main/resources/wordsList.txt");
df.groupBy("value").count().show();
// SparkConf sparkConf = new SparkConf().setMaster("local").setAppName("Name");
// JavaSparkContext sc = new JavaSparkContext(sparkConf);
// JavaRDD<String> textFile = sc.textFile("src/main/resources/wordsList.txt");
// JavaPairRDD<String, Integer> counts = textFile
// .flatMap(s -> Arrays.asList(s.split(" ")).iterator())
// .mapToPair(word -> new Tuple2<>(word, 1))
// .reduceByKey((a, b) -> a + b);
// counts.take(10);
// System.out.println(counts.collect());
}
}