I am trying to read a csv file in a lawsuit and I want to split comma separated lines so that I have an RDD with a two dimensional array. I am very new to Spark.
I tried to do this:
public class SimpleApp
{
public static void main(String[] args) throws Exception
{
String master = "local[2]";
String csvInput = "/home/userName/Downloads/countrylist.csv";
String csvOutput = "/home/userName/Downloads/countrylist";
JavaSparkContext sc = new JavaSparkContext(master, "loadwholecsv", System.getenv("SPARK_HOME"), System.getenv("JARS"));
JavaRDD<String> csvData = sc.textFile(csvInput, 1);
JavaRDD<String> words = csvData.map(new Function <List<String>>() {
@Override
public List<String> call(String s) {
return Arrays.asList(s.split("\\s*,\\s*"));
}
});
words.saveAsTextFile(csvOutput);
}
}
This should split the lines and return an ArrayList. But I'm not so sure about that. I get this error:
SimpleApp.java:[43,58] wrong number of type arguments; required 2
source
share