I'm trying to convert the following Scala line (which extracts the digits from a string and which I used in the Scala shell):
val df2 = df.withColumn("only digits", regexp_replace(col("original"), "[^\\d]", ""))
to its Java equivalent and I am having problems with the conversion from org.apache.spark.sql.Column returned by col("original") to the String type required by String.replaceAll().
I tried the following, but it doesn't compile (cast still returns a Column).
import org.apache.spark.sql.Column;
import static org.apache.spark.sql.functions.*;
Dataset<Row> df2 = df.withColumn("new", col("original").cast("string").replaceAll("[^\\d]", ""));
I also looked at the Column javadocs and in the static functions imported above but haven't seen anything to help. Thanks.