【问题标题】:withcolumn() in spark for adding new column is not showing result [duplicate]spark中用于添加新列的withcolumn()未显示结果[重复]
【发布时间】:2018-11-04 09:07:50
【问题描述】:

我正在尝试使用 withcolumn 添加一个新列,其值应该为 NULL 但它不起作用。

 val schema = StructType(
                    StructField("uid",StringType,true)::
                    StructField("sid",StringType,true)::
                    StructField("astid",StringType,true)::
                    StructField("timestamp",StringType,true)::
                    StructField("start",StringType,true)::
                    StructField("end",StringType,true)::
                    StructField("geo",StringType,true)::
                    StructField("stnid",StringType,true)::
                    StructField("end_type",LongType,true)::
                    StructField("like",LongType,true)::
                    StructField("dislike",LongType,true)::Nil
                      ) 

val Mobpath = spark.read.schema(schema).csv("/data/mob.txt")  
Mobpath.printSchema()

Mobpath.createOrReplaceTempView("Mobpathsql")

val showall =  spark.sql("select * from Mobpathsql")
showall.show()

val newcol = Mobpath.withColumn("new1",functions.lit("null"))
newcol.show()       

使用withcolumn 没有显示任何错误,也没有显示任何输出。

【问题讨论】:

  • 它对我有用,所以我认为其他评论可能是有效的,但我有一些数据。

标签: apache-spark apache-spark-sql apache-spark-dataset


【解决方案1】:

这个呢:

val newcol = showall.withColumn("new1",functions.lit("null"))
newcol.show()  

我只是测试了上面的代码,它可以工作,我不知道为什么它不能与 Mobpath 一起工作

【讨论】:

  • 不确定我是否得到了问题或答案。
  • 添加了更多细节
猜你喜欢
  • 1970-01-01
  • 2017-01-14
  • 2018-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多