用于添加新列的 spark 中的 withcolumn() 未显示结果

withcolumn() in spark for adding new column is not showing result

我正在尝试使用 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 它没有显示任何错误,也没有显示任何输出。

这个怎么样:

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

我刚刚测试了上面的代码并且它有效,我不知道为什么它不适用于 Mobpath