有人可以帮助我在我完全不了解此代码的地方吗?我无法将电话从String解析为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)
答案 0 :(得分:1)
由于上一个电话号码的大小大于int大小,因此出现错误。 转换数字太长。它应该工作。
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)