title: How to generate multiple records based on column?
body: <p>I have records like below. I would like to convert a single record into two records with values <code>EXTERNAL</code> and <code>INTERNAL</code> each if the 3rd attribute is <code>All</code>.</p>
  
  <p>Input dataset:</p>
  
  <pre><code>Surender,cts,INTERNAL
  Raja,cts,EXTERNAL
  Ajay,tcs,All
  </code></pre>
  
  <p>Expected output:</p>
  
  <pre><code>Surender,cts,INTERNAL
  Raja,cts,EXTERNAL
  Ajay,tcs,INTERNAL
  Ajay,tcs,EXTERNAL
  </code></pre>
  
  <p><strong>My Spark Code :</strong></p>
  
  <pre><code>case class Customer(name:String,organisation:String,campaign_type:String)
  
  val custRDD = sc.textFile("/user/cloudera/input_files/customer.txt")
  
  val mapRDD = custRDD.map(record =&gt; record.split(","))
      .map(arr =&gt; (arr(0),arr(1),arr(2))
      .map(tuple =&gt; {
        val name            = tuple._1.trim
        val organisation    = tuple._2.trim
        val campaign_type   = tuple._3.trim.toUpperCase
        Customer(name, organisation, campaign_type)
      })
  
  mapRDD.toDF().registerTempTable("customer_processed")
  
  sqlContext.sql("SELECT * FROM customer_processed").show
  </code></pre>
  
  <p>Could Someone help me to fix this issue?</p>