ScalaBoy
ScalaBoy

Reputation: 3392

How to cast to Long in Spark Scala?

This seems to be a simple task, but I cannot figure out how to do it with Scala in Spark (not PySpark). I have a DataFrame df with different columns. One of the columns has a type String that should be changed to Long. How can I do it?

If I execute this code, I get the compilation error Cannot resolve symbol col:

df.withColumn("timestamp", col("timestamp").cast(LongType))

Upvotes: 5

Views: 15189

Answers (1)

himanshuIIITian
himanshuIIITian

Reputation: 6095

I think you need to import org.apache.spark.sql.functions.col to use col() function.

Upvotes: 5

Related Questions