lte*_*e__ 4 java apache-spark apache-spark-sql spark-dataframe
我注意到如果我使用SQLContext和.sql()函数,我可以使用CASE-THEN和Spark .有没有办法在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");
Run Code Online (Sandbox Code Playgroud)
我正在寻找类似的东西
df.select(case("this").then("that"));
Run Code Online (Sandbox Code Playgroud)
只需导入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"));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2399 次 |
| 最近记录: |