getting java.util.NoSuchElementException
val data3 = data2.filter(x => type1_dm_med.contains(x._2._1.last.medicine))
when I try to print data3.count I get below error - not sure how to fix it, please help
[Stage 50:=====> (20 + 1) / 200]16/02/26 01:37:11 ERROR Executor: Exception in task 22.0 in stage 50.0 (TID 1636)
java.util.NoSuchElementException
at scala.collection.LinearSeqOptimized$class.last(LinearSeqOptimized.scala:135)
at scala.collection.immutable.List.last(List.scala:84)
more context:
class Diagnostic(patientID:String, date: Date, code: String)
class Medication(patientID: String, date: Date, medicine: String)
loaded data from .csv into medication:RDD[Medication] and diagnostic:
RDD[Diagnostic]
val mpairs = medication.map(x=>(x.patientID,x))
val dpairs = diagnostic.map(x=>(x.patientID,x))
val data = mpairs.fullOuterJoin(dpairs)
'data' tuple example: (000496120-01,(Some(Medication(000496120-01,Fri Jul 01 15:15:00 EDT 2005,protamine sulfate)),Some(Diagnostic(000496120-01,Mon Jan 07 15:00:00 EST 2013,v70.0))))
type1_dm_dx et'al are list of code or medicines that want to filter on
val cond1 = data.filter(x => type1_dm_dx.contains(x._2._2.last.code))
val data1 = data.subtractByKey(cond1)
val data2 = data1.filter(x => type2_dm_dx.contains(x._2._2.last.code))
val data3 = data2.filter(x => type1_dm_med.contains(x._2._1.last.medicine))
hope this helps
x._2._1this looks suspicious and like unreadable code/bad practice. You may read aboutcase classes.x._2._1is an emptyListand as a result calling.laston it throws an error.