java.lang.NumberFormatException: empty String


#1

I am doing a practice on one of the scenarios and came across this error:
By following my code below you should be able to reproduce the error:

Step1: import data
sqoop import -m 1
–connect jdbc:mysql://ms.itversity.com/retail_db
–username=retail_user
–password=itversity
–table=products
–target-dir=p93_products

Step 2: RDD
//read data into RDD
val productsRDD = sc.textFile(“p93_products”)
//filter out empty price
val filteredRDD = productsRDD.filter(rec=>rec.split(",")(4).toFloat>0)
//create map
val productsRDDMap = filteredRDD.map(rec=>(rec.split(",")(0).toInt, rec.split(",")(1), rec.split(",")(2), rec.split(",")(3), rec.split(",")(4).toFloat, rec.split(",")(5)))
//transform to DF
val productsDF = productsRDDMap.toDF(“product_id”, “product_category_id”,“product_name”,“product_description”,“product_price”,“product_image”)

Step 3: SparkSQL
productsDF.registerTempTable(“products”)
val result1 = sqlContext.sql(“select * from products where product_price > 0 order by product_price limit 10”)

//get the result
result1.show

Error:

java.lang.NumberFormatException: empty String

Thank you very much.