Find out total visit,most visited floor and resorces via spark scala
Input table:
Output table required:
Solution:
val spark = SparkSession.builder.getOrCreate()
val df = spark.read.format("csv")
.option("inferschema","true")
.option("header","true")
.load("file:///D:/task1.txt")
df.show()
df.printSchema()
val dfg = df.groupBy("name")
.agg(
count("name").alias("total_visits"),
first("floor").alias("most_visited_floor"),
collect_list("resources").alias("resources_used")
)
dfg.show()
dfg.printSchema()
Comments
Post a Comment