Spark SQL - JAVA CASE-THEN 语法?
Spark SQL - JAVA syntax of CASE-THEN?
我注意到如果我使用 SQLContext
和 .sql()
函数,我可以在 Spark 中使用 CASE-THEN。有没有办法在 JAVA 语法中直接在数据帧上使用它?如何?
现在,我写:
SparkConf sparkConf = new SparkConf();
JavaSparkContext ctx = new JavaSparkContext(sparkConf);
SQLContext sqlContext = new SQLContext(ctx);
DataFrame df = //some imported data
df.registerTempTable("df");
sqlContext.sql("SELECT *use case-then in here* FROM df");
我正在寻找类似
的东西
df.select(case("this").then("that"));
只需导入 org.apache.spark.sql.functions
然后使用 when(Column col, Object obj)
.
import org.apache.spark.sql.functions;
df.select(functions.when(df.col("colName").equalTo("this"), "that").otherwise("something"));
我注意到如果我使用 SQLContext
和 .sql()
函数,我可以在 Spark 中使用 CASE-THEN。有没有办法在 JAVA 语法中直接在数据帧上使用它?如何?
现在,我写:
SparkConf sparkConf = new SparkConf();
JavaSparkContext ctx = new JavaSparkContext(sparkConf);
SQLContext sqlContext = new SQLContext(ctx);
DataFrame df = //some imported data
df.registerTempTable("df");
sqlContext.sql("SELECT *use case-then in here* FROM df");
我正在寻找类似
的东西df.select(case("this").then("that"));
只需导入 org.apache.spark.sql.functions
然后使用 when(Column col, Object obj)
.
import org.apache.spark.sql.functions;
df.select(functions.when(df.col("colName").equalTo("this"), "that").otherwise("something"));