There are probably at least 10 question very similar to this, but I still have not found a clear answer.
How can I add a nullable string column to a DataFrame using scala? I was able to add a column with null values, but the DataType shows null
val testDF = myDF.withColumn("newcolumn", when(col("UID") =!= "not", null).otherwise(null))
However, the schema shows
root
|-- UID: string (nullable = true)
|-- IsPartnerInd: string (nullable = true)
|-- newcolumn: null (nullable = true)
I want the new column to be string |-- newcolumn: string (nullable = true)
Please don't mark as duplicate, unless it's really the same question and in scala.
myDF.withColumn("newcolumn", lit(null).cast("string")). - Leo C