0

can some one help me where i am exactly missing with this code? I am unable to parse the phone from String to Integer

case class contactNew(id:Long,name:String,phone:Int,email:String)
val contactNewData = Array("1#Avinash#Mob-8885453419#avinashbasetty@gmail.com","2#rajsekhar#Mob-9848022338#raj@yahoo.com","3#kamal#Mob-98032446443#kamal@gmail.com")
val contactNewDataToRDD = spark.sparkContext.parallelize(contactNewData)
val contactNewRDD = contactNewDataToRDD.map(l=> {
  val contactArray=l.split("#")
  val MobRegex=contactArray(2).replaceAll("[a-zA-Z/-]","")
  val MobRegex_Int=MobRegex.toInt
  contactNew(contactArray(0).toLong,contactArray(1),MobRegex_Int,contactArray(3))
})
contactNewRDD.collect.foreach(println)
Learner
  • 1,170
  • 11
  • 21
Avinash
  • 393
  • 1
  • 4
  • 9

1 Answers1

1

you are getting error as the size of last phone number is greater than int size. convert the number too Long. it should work.

case class contactNew(id:Long,name:String,phone:Long,email:String)
val contactNewData = 
Array("1#Avinash#Mob8885453419#avinashbasetty@gmail.com",
"2#rajsekhar#Mob-9848022338#raj@yahoo.com",
"3#kamal#Mob-98032446443#kamal@gmail.com")
val contactNewDataToRDD = spark.sparkContext.parallelize(contactNewData)
val contactNewRDD = contactNewDataToRDD.map(l=>
{
val contactArray=l.split("#")
val MobRegex=contactArray(2).replaceAll("[a-zA-Z/-]","")
val MobRegex_Int=MobRegex.toLong
contactNew(contactArray(0).toLong,contactArray(1),MobRegex_Int,contactArray(3))
}                                          
)
contactNewRDD.collect.foreach(println)
Harjeet Kumar
  • 504
  • 2
  • 7