refactor code for step2.
Add duration to do ADE in spark.