美文网首页
190、Spark 2.0之Dataset开发详解-typed操

190、Spark 2.0之Dataset开发详解-typed操

作者: ZFH__ZJ | 来源:发表于2019-02-11 21:46 被阅读0次

    distinct和dropDuplicates,都是用来进行去重的
    区别在于,distinct,是根据每一条数据,进行完整内容的比对和去重
    dropDuplicates,可以根据指定的字段进行去重

    代码

    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 employeeDF = sparkSession.read.json(employeePath)
    
        val employeeDS = employeeDF.as[Employee]
    
        employeeDS.distinct().show()
    
        employeeDS.dropDuplicates(Seq("name")).show()
    
      }
    }
    

    相关文章

      网友评论

          本文标题:190、Spark 2.0之Dataset开发详解-typed操

          本文链接:https://www.haomeiwen.com/subject/uikqeqtx.html