Last active
January 19, 2021 15:03
-
-
Save nivdul/0b84c5184ae42278b02f to your computer and use it in GitHub Desktop.
wordcount
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create the Spark configuration and context | |
SparkConf conf = new SparkConf().setAppName("Wordcount").setMaster("local[*]"); | |
JavaSparkContext sc = new JavaSparkContext(conf); | |
// load data and create an RDD of string | |
JavaRDD<String> tweets = sc.textFile("path_To_File") | |
JavaPairRDD<String, Integer> wordcount = tweets.flatMap(line -> Arrays.asList(line.toString().split(" "))) | |
// mapper step | |
.mapToPair(word -> new Tuple2<>(word, 1)) | |
// reducer step | |
.reduceByKey((x, y) -> x + y); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment