199 、 Spark 2.0 의 Dataset 개발 상세 - 기타 상용 함수

날짜 함수: currentdate、current_timestamp 수학 함수: round 랜 덤 함수: rand 문자열 함수: concat, concatws 사용자 정의 udf 와 udaf 함수
문서 주소:http://spark.apache.org/docs/latest/api/scala/index.html#org.apache.spark.sql.functions$
코드
object OtherFunction {
  def main(args: Array[String]) {
    val sparkSession = SparkSession
      .builder()
      .appName("OtherFunction")
      .master("local")
      .getOrCreate()

    import sparkSession.implicits._
    import org.apache.spark.sql.functions._

    val employeePath = this.getClass.getClassLoader.getResource("employee.json").getPath
    val departmentPath = this.getClass.getClassLoader.getResource("department.json").getPath

    val employeeDF = sparkSession.read.json(employeePath)
    val departmentDF = sparkSession.read.json(departmentPath)

    val employeeDS = employeeDF.as[Employee]
    val departmentDS = departmentDF.as[Department]

    employeeDS
      .select(employeeDS("name"), current_date(), current_timestamp(), rand(), round(employeeDS("salary"), 2), concat(employeeDS("gender"), employeeDS("age")), concat_ws("|", employeeDS("gender"), employeeDS("age")))
      .show()
  }
}

좋은 웹페이지 즐겨찾기