Reputation: 5051
I have a text file like this:
1,abc
34,bvc
98,def
43,mnl
12,xyz
54,hij
val rddtemp= sc.textFile("/tmp/tabletest.txt")
val maprdd = rddtemp.map(x=> (x.split(",")(0)+ 3, x.split(",")(1) )).foreach(println)
This give me :
(123,xyz)
(543,hij)
(13,abc)
(343,bvc)
(983,def)
(433,mnl)
Using +
concatenates to the first column but I want to add to the first column giving:
(15,xyz)
(57,hij)
(4,abc)
(37,bvc)
(101,def)
(46,mnl)
Upvotes: 0
Views: 60
Reputation: 9734
After split you've got Array[String], and + for string is concatenation. You need convert it to Int first
val maprdd = rddtemp.
map(_.split(",")).
map(arr => (arr(0).toInt + 3, arr(1))).
foreach(println)
Upvotes: 2