Reading CSV
Import Dependencies
import org.apache.spark.SparkConf
import org.apache.spark.SparkContext
import org.apache.spark.sql.SQLContext
import com.databricks.spark.csv._
Spark App in Scala
val conf = new SparkConf().setAppName("csvDataFrame").setMaster("local[2]")
val sc = new SparkContext(conf)
val sqlContext = new SQLContext(sc)
val students=sqlContext.csvFile(filePath="StudentData.csv", useHeader=true, delimiter='|')
students.printSchema
students.show(3)
Output
root
|-- id: string (nullable = true)
|-- studentName: string (nullable = true)
|-- phone: string (nullable = true)
|-- email: string (nullable = true)
+--+-----------+--------------+--------------------+
|id|studentName| phone| email|
+--+-----------+--------------+--------------------+
| 1| Burke|1-300-746-8446|ullamcorper.velit...|
| 2| Kamal|1-668-571-5046|pede.Suspendisse@...|
| 3| Olga|1-956-311-1686|Aenean.eget.metus...|
+--+-----------+--------------+--------------------+