Explain values() operation in Apache Spark.

Free Online Certification Courses – Learn Today. Lead Tomorrow. Forums Apache Spark Explain values() operation in Apache Spark.

Viewing 2 reply threads
  • Author
    Posts
    • #5233
      DataFlair TeamDataFlair Team
      Spectator

      Explain values() operation in Apache Spark.

    • #5236
      DataFlair TeamDataFlair Team
      Spectator
      • values() is a transformation.
      • It returns an RDD of values only.
      <br />
      val rdd1 = sc.parallelize(Seq((2,4),(3,6),(4,8),(5,10),(6,12),(7,14),(8,16),(9,18),(10,20)))<br />
      val rdd2 = rdd1.values<br />
      rdd2.collect<br />

      Output:
      Array[Int] = Array(4, 6, 8, 10, 12, 14, 16, 18, 20)

    • #5239
      DataFlair TeamDataFlair Team
      Spectator

      > Example2 : Values are duplicate in data set

      <br />
      val rdd1 = sc.parallelize(Seq((2,4),(3,6),(4,8),(2,6),(4,12),(5,10),(5,40),(10,40)))<br />
      val rdd2 = rdd1.keys<br />
      rdd2.collect<br />
      val rdd3 = rdd1.values<br />
      rdd3.collect<br />

      Output:

      Array[Int] = Array(2, 3, 4, 2, 4, 5, 5, 10)
      Array[Int] = Array(4, 6, 8, 6, 12, 10, 40, 40
Viewing 2 reply threads
  • You must be logged in to reply to this topic.