I think this is lot more readable for me.
import org.apache.spark.sql.types._df.withColumn("year", df("year").cast(IntegerType))
This will convert your year column to IntegerType
with creating any temporary columns and dropping those columns.If you want to convert to any other datatype, you can check the types inside org.apache.spark.sql.types
package.