Explain keys() operation in Apache spark.

Viewing 2 reply threads
  • Author
    Posts
    • #5214
      DataFlair Team
      Moderator

      Explain keys() operation in Apache spark.

    • #5220
      DataFlair Team
      Moderator
      val rdd1 = sc.parallelize(Seq((2,4),(3,6),(4,8),(5,10),(6,12),(7,14),(8,16),(9,18),(10,20)))
      val rdd2 = rdd1.keys
      rdd2.collect

      Output:

      Array[Int] = Array(2, 3, 4, 5, 6, 7, 8, 9,
    • #5223
      DataFlair Team
      Moderator

      Example 2 : (Keys are repeated – duplicate keys are present in data set)

      val rdd1 = sc.parallelize(Seq((2,4),(3,6),(4,8),(2,6),(4,12),(5,10),(5,40),(10,40)))
      val rdd2 = rdd1.keys
      rdd2.collect

      Output:
      Array[Int] = Array(2, 3, 4, 2, 4, 5, 5, 10)

Viewing 2 reply threads
  • You must be logged in to reply to this topic.