generate a new column by adding a value to spark dtaframe column

时间:2018-07-25 04:26:30

标签: java apache-spark hadoop

i have column in spark dataframe which has integer. how to generate a new column by adding one to each value in column using Spark Java

1 个答案:

答案 0 :(得分:1)

You can use df.withColumn to add the new column to the Dataframe.

import static org.apache.spark.sql.functions.col;
DataFrame df2 = df1.withColumn("new_column", col("column_name").plus(1));