except:獲取在當(dāng)前dataset中有,但是在另外一個dataset中沒有的元素
filter:根據(jù)我們自己的邏輯蒸其,如果返回true敏释,那么就保留該元素,否則就過濾掉該元素
intersect:獲取兩個數(shù)據(jù)集的交集
代碼
object TypedOperation {
case class Employee(name: String, age: Long, depId: Long, gender: String, salary: Long)
def main(args: Array[String]): Unit = {
val sparkSession = SparkSession
.builder()
.appName("BasicOperation")
.master("local")
.getOrCreate()
import sparkSession.implicits._
import org.apache.spark.sql.functions._
val employeePath = this.getClass.getClassLoader.getResource("employee.json").getPath
val employee2Path = this.getClass.getClassLoader.getResource("employee2.json").getPath
val employeeDF = sparkSession.read.json(employeePath)
val employee2DF = sparkSession.read.json(employee2Path)
val employeeDS = employeeDF.as[Employee]
val employee2DS = employee2DF.as[Employee]
employeeDS.except(employee2DS).show()
employeeDS.filter(employee => employee.age > 30).show()
employeeDS.intersect(employee2DS).show()
}
}