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

This line is the actual fix. Here we just try to import what is directly referenced and ignore everything else. This works for wildcard imports too.