Sample:抽样算子

package com.shujia.spark.core

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo5Sample {
  def main(args: Array[String]): Unit = {
    val conf: SparkConf = new SparkConf()
      .setAppName("map")
      .setMaster("local")

    //spark  上下文对象
    val sc = new SparkContext(conf)

    val students: RDD[String] = sc.textFile("data/students.txt")

    /**
      * Sample:抽样算子
      *
      */

    val sampleADD: RDD[String] = students.sample(false,0.1)

    sampleADD.foreach(println)
  }
}

 

posted @ 2021-07-16 22:12  坤坤无敌  阅读(87)  评论(0)    收藏  举报