-
-
Save yaseminn/522a75b863ad78934bc3 to your computer and use it in GitHub Desktop.
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
package vngrsWeatherReportSpark; | |
import org.apache.spark.SparkConf; | |
import org.apache.spark.api.java.JavaPairRDD; | |
import org.apache.spark.api.java.JavaSparkContext; | |
import org.apache.spark.api.java.function.PairFunction; | |
import scala.Serializable; | |
import scala.Tuple2; | |
public class MonthlyAverage implements Serializable { | |
public static void main(String[] args) { | |
SparkConf sparkConf = new SparkConf().setAppName("MonthlyAverage").set( | |
"spark.driver.allowMultipleContexts", "true"); | |
String path = "weather.csv"; | |
JavaSparkContext ctx = new JavaSparkContext(sparkConf); | |
JavaPairRDD<String, String> weatherPair = readCsv(ctx, path); | |
} | |
public static JavaPairRDD<String, String> readCsv(JavaSparkContext ctx, | |
String filePath) { | |
JavaPairRDD<String, String> weatherLogs = ctx.textFile(filePath) | |
.mapToPair(new PairFunction<String, String, String>() { | |
public Tuple2<String, String> call(String s) { | |
String[] splitted = s.split("\t", -1); | |
Tuple2<String, String> t = new Tuple2<String, String>( | |
splitted[0], splitted[1] + "," + splitted[2] | |
+ "," + splitted[3]); | |
return t; | |
} | |
}); | |
weatherLogs.saveAsTextFile("ResultVNGRS"); | |
return weatherLogs; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment