How to add a constant column to the Spark-java framework

I have imported

import org.apache.spark.sql.Column; import org.apache.spark.sql.functions; 

in my java-spark driver

But

 DataFrame inputDFTwo = hiveContext.sql("select * from sourcing_src_tbl"); inputDFTwo.withColumn("asofdate", lit("2016-10-2")); 

here "on" error in eclipse (windows) is still displayed. Which library should I include in order to make it work.

+8
java apache-spark
source share
1 answer

Or import the object, as you know, and use it to access the method:

 import org.apache.spark.sql.functions; df.withColumn("foo", functions.lit(1)); 

or use import static and the call method directly:

 import static org.apache.spark.sql.functions.lit; df.withColumn("foo", lit(1)); 
+20
source share

All Articles