We have two dataframes (note Scala syntax for illustrating),
val df1 = sc.parallelize(1 to 4).map(i => (i,i*10)).toDF("id","x")
val df2 = sc.parallelize(2 to 4).map(i => (i,i*100)).toDF("id","y")
How to sum up one column from each frame so that we obtain this new dataframe,
+---+---------+
| id| x_plus_y|
+---+---------+
| 1| 10|
| 2| 220|
| 3| 330|
| 4| 440|
+---+---------+
Note Tried this, but it nullifies the first row,
sqlContext.sql("select df1.id, x+y as x_plus_y from df1 left join df2 on df1.id=df2.id").show
+---+--------+
| id|x_plus_y|
+---+--------+
| 1| null|
| 2| 220|
| 3| 330|
| 4| 440|
+---+--------+