I map a data taken from a text file. The text file is supposed to have 5 columns. e.g.
29000000 1 0 2013 1 single-sex
29000000 1 0 2013 1 education
29000000 1 0 2013 1 and
29000000 1 0 2013 1 the
29000000 1 0 2013 1 brain
In my process I need only those values appearing on the 0th and 5th columns. So to get those I wrote the following:
val emp =
sc.textFile("\\.txt")
.map{line => val s = line.split("\t"); (s(5),s(0))}
However, it is possible that sometimes 5th column does not exist for some rows and I get
15/10/12 17:19:33 INFO TaskSetManager: Lost task 27.0 in stage 0.0 (TID 27) on executor localhost: java.lang.ArrayIndexOutOfBoundsException (5)
So on my mapping how should I write a if condition if s(5) exists or not?
0, 1, 2, 3, 4. 5 means the sixth row.