如何在 Spark-java 数据框中添加具有常量的列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39649585/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add column with constant in Spark-java data frame
提问by user2895589
I have imported
我已经进口
import org.apache.spark.sql.Column;
import org.apache.spark.sql.functions;
in my Java-Spark driver
在我的 Java-Spark 驱动程序中
But
但
DataFrame inputDFTwo = hiveContext.sql("select * from sourcing_src_tbl");
inputDFTwo.withColumn("asofdate", lit("2016-10-2"));
here "lit" is still showing error in eclipse(windows).Which library should I include to make it work.
这里的“lit”仍然在 eclipse(windows) 中显示错误。我应该包含哪个库以使其工作。
回答by zero323
Either import object like you do know and use it to access method:
要么像您知道的那样导入对象并使用它来访问方法:
import org.apache.spark.sql.functions;
df.withColumn("foo", functions.lit(1));
or use import static
and call method directly:
或import static
直接使用和调用方法:
import static org.apache.spark.sql.functions.lit;
df.withColumn("foo", lit(1));