SPARK-2632, SPARK-2576. Fixed by only importing what is necessary during class definition.

Can we call `toSchemaRDD` here before the `collect()` to make sure the implicit is triggered?