0

I am trying to add a new column using withcolumn whose value should be NULL but its not working.

 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()       

using withcolumn it is not showing any error and also not showing any output.

zero323
  • 322,348
  • 103
  • 959
  • 935

1 Answers1

-1

what about this:

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

I just test the above code and it worked, i don't know why it does not work with Mobpath

f.ald
  • 320
  • 1
  • 16