import org.apache.spark.SparkConf
import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.functions._
object Dataframe_demo_01 {
case class student11(name: String, course: String, score: String)
def main(args: Array[String]): Unit = {
val sparkconf = new SparkConf().setAppName("Dataframe_dem_01").setMaster("local[*]")
val spark = SparkSession.builder().config(sparkconf).getOrCreate()
import spark.implicits._
val df = spark.read.option("header","true").csv("D://readfile.csv").as[student11]
df.show(false)
df.filter($"score" > 90).select($"name",$"course",$"score").show(false)
df.select(max($"score").cast("Double") as ("highestscore"), min(($"score").cast("Double") as ("highestscore"))).show(false)
df.select($"name",$"course",$"score").sort($"score".desc).show(false)
df.groupBy($"course").agg(max($"score".cast("Double")),max($"score").cast("Double").as("highestscore")).show()
df.groupBy("score").count.filter($"count" > 1).show(false)
}
}