score:-2

Hope below code snippet will help.

scala> val df = List(1,2,3).toDF("id")
df: org.apache.spark.sql.DataFrame = [id: int]

scala> df.show
+---+
| id|
+---+
|  1|
|  2|
|  3|
+---+


scala> :paste
// Entering paste mode (ctrl-D to finish)

def addCol1(df: DataFrame): DataFrame =
df.withColumn("col1", lit("a"))

// Exiting paste mode, now interpreting.

addCol1: (df: org.apache.spark.sql.DataFrame)org.apache.spark.sql.DataFrame

scala> df.transform(addCol1).show
+---+----+
| id|col1|
+---+----+
|  1|   a|
|  2|   a|
|  3|   a|
+---+----+

Related Query

More Query from same tag