Comparing two dataframe from history checking in Apache Saprk using scala : I have adataframe with following structure

EmployeeDF

        id name  date       code
        1 John   2015-4-14  C11
        2 Roy    2011-5-20  C11
        3 John   2010-5-20  C11
        4 John   2012-5-20  C10

No i want to check history that if same code is apply to same employee two year ago. How can i do that. It is only sample data i have million of data in the dataframe and i want to achieve performance. Joining the dataframe slow down the performance because row are repeated so i make Cartesian and duplicate the rows during self join. I want to achieve with something like map.    