Не могли бы вы попробовать ниже фрагмент
import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.types.DoubleType
import org.apache.spark.sql.types.StructType
import org.apache.spark.sql.types.StringType
import org.apache.spark.sql.types.StructField
val spark = SparkSession
.builder()
.config("spark.master", "local[1]")
.appName("Test Job")
.getOrCreate()
import spark.implicits._
val sparkContext = spark.sparkContext
sparkContext.setLogLevel("WARN")
//DEFINING INPUT
val inputDF = StructType(Array(StructField("district", StringType, false),
StructField("sum(aadhaar_generated)", DoubleType, false),
StructField("district_name", StringType, false),
StructField("sum(rejected)", DoubleType, false)))
//READING INPUT FILE
val dF = spark.read.format("csv").option("sep", ",")
.option("header", true)
.option("timestampFormat", "yyyy/MM/dd HH:mm:ss ZZ")
.schema(inputDF)
.load("path\\to\\file");
println("Input DF")
dF.show()
var aggDF = dF.withColumn("Sum_Value", $"sum(aadhaar_generated)" + $"sum(rejected)")
println("After Aggregation")
aggDF.show()
OUTPUT
Input DF
+---------------+----------------------+---------------+-------------+
| district|sum(aadhaar_generated)| district_name|sum(rejected)|
+---------------+----------------------+---------------+-------------+
| Namsai| 5.0| Namsai| 0.0|
| Champawat| 1584.0| Champawat| 131.0|
| Nagaur| 12601.0| Nagaur| 697.0|
| Umaria| 2485.0| Umaria| 106.0|
| Rajnandgaon| 785.0| Rajnandgaon| 57.0|
| Chikkamagaluru| 138.0| Chikkamagaluru| 26.0|
|Tiruchirappalli| 542.0|Tiruchirappalli| 527.0|
| Baleswar| 2963.0| Baleswar| 1703.0|
| Pilibhit| 1858.0| Pilibhit| 305.0|
+---------------+----------------------+---------------+-------------+
After Aggregation
+---------------+----------------------+---------------+-------------+---------+
| district|sum(aadhaar_generated)| district_name|sum(rejected)|Sum_Value|
+---------------+----------------------+---------------+-------------+---------+
| Namsai| 5.0| Namsai| 0.0| 5.0|
| Champawat| 1584.0| Champawat| 131.0| 1715.0|
| Nagaur| 12601.0| Nagaur| 697.0| 13298.0|
| Umaria| 2485.0| Umaria| 106.0| 2591.0|
| Rajnandgaon| 785.0| Rajnandgaon| 57.0| 842.0|
| Chikkamagaluru| 138.0| Chikkamagaluru| 26.0| 164.0|
|Tiruchirappalli| 542.0|Tiruchirappalli| 527.0| 1069.0|
| Baleswar| 2963.0| Baleswar| 1703.0| 4666.0|
| Pilibhit| 1858.0| Pilibhit| 305.0| 2163.0|
+---------------+----------------------+---------------+-------------+---------+
Пожалуйста, дайте мне знать, если это работает.