Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Need to create a map of key value pairs

Need to create a map of key value pairs

New Contributor

Input file:

patients.csv
patientID,name,dateOfBirth,lastVisitDate
1001,Ah Teck,1991-12-31,2012-01-20
1002,Kumar,2011-10-29,2012-09-20
1003,Ali,2011-01-30,2012-10-21

Code:
val a=sc.textFile("/user/cloudera/data/patients.csv")
val b=a.first
val c=a.filter(x=>x!=b).map(_.split(","))
val d=c.map(x=>b.zip(x).toMap)
d.collect

Actual Output:
Array[scala.collection.immutable.Map[Char,String]] = Array(Map(p -> 1001, a -> Ah Teck, t -> 1991-12-31, i -> 2012-01-20), Map(p -> 1002, a -> Kumar, t -> 2011-10-29, i -> 2012-09-20), Map(p -> 1003, a -> Ali, t -> 2011-01-30, i -> 2012-10-21))

Expected Output:
Array[scala.collection.immutable.Map[Char,String]] = Array(Map(patientID -> 1001, name -> Ah Teck, dateOfBirth -> 1991-12-31, lastVisitDate -> 2012-01-20), Map(patientID -> 1002, name -> Kumar, dateOfBirth -> 2011-10-29, lastVisitDate -> 2012-09-20), Map(patientID -> 1003, name -> Ali, dateOfBirth -> 2011-01-30, lastVisitDate -> 2012-10-21))

Please let me know what am I missing?