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

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

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

    except:获取在当前dataset中有,但是在另外一个dataset中没有的元素
    filter:根据我们自己的逻辑,如果返回true,那么就保留该元素,否则就过滤掉该元素
    intersect:获取两个数据集的交集

    代码

    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()
    
      }
    }
    

    相关文章

      网友评论

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

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