lte__ lte__ - 1 year ago 150
Java Question

Spark SQL - JAVA syntax of CASE-THEN?

I noticed I can use CASE-THEN with Spark if I use an

and the
function. Is there a way to use this in a JAVA syntax, directly on dataframes, too? How?
Now, I write:

SparkConf sparkConf = new SparkConf();
JavaSparkContext ctx = new JavaSparkContext(sparkConf);
SQLContext sqlContext = new SQLContext(ctx);
DataFrame df = //some imported data
sqlContext.sql("SELECT *use case-then in here* FROM df");

I'm looking for something like"this").then("that"));

Answer Source

Just import org.apache.spark.sql.functions then use when(Column col, Object obj).

import org.apache.spark.sql.functions;"colName").equalTo("this"), "that").otherwise("something"));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download