first()

作用:返回RDD中的第一个元素

package com.atguigu

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

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

    val sc = new SparkContext(conf)

    val rdd: RDD[Int] = sc.makeRDD(List(1,4,3,2))

    val i: Int = rdd.first()
    println(i)
  }
}

1

你可能感兴趣的:(first())