title: Spark : Writing data frame to s3 bucket
body: <p>I am trying to write DF data to S3 bucket. It is working fine as expected. Now i want to write to s3 bucket based on condition.</p>
  
  <p>In data frame i am having one column as Flag and in that column values are T and F . Now the condition is If Flag is F then it should write the data to S3 bucket otherwise No. Please find the details below.</p>
  
  <p>DF Data : </p>
  
  <pre><code>1015,2017/08,新潟,101,SW,39,1015,2017/08,山形,101,SW,10,29,74.35897435897436,11.0,F
  1015,2017/08,新潟,101,SW,39,1015,2017/08,大分,101,SW,14,25,64.1025641025641,15.4,F
  1015,2017/08,新潟,101,SW,39,1015,2017/08,山口,101,SW,6,33,84.61538461538461,6.6,T
  1015,2017/08,新潟,101,SW,39,1015,2017/08,愛媛,101,SW,5,34,87.17948717948718,5.5,T
  1015,2017/08,新潟,101,SW,39,1015,2017/08,神奈川,101,SW,114,75,192.30769230769232,125.4,F
  1015,2017/08,新潟,101,SW,39,1015,2017/08,富山,101,SW,12,27,69.23076923076923,13.2,F
  1015,2017/08,新潟,101,SW,39,1015,2017/08,高知,101,SW,3,36,92.3076923076923,3.3,T
  1015,2017/08,新潟,101,SW,39,1015,2017/08,岩手,101,SW,11,28,71.7948717948718,12.1,F
  1015,2017/08,新潟,101,SW,39,1015,2017/08,三重,101,SW,45,6,15.384615384615385,49.5,F
  1015,2017/08,新潟,101,SW,39,1015,2017/08,京都,101,SW,23,16,41.02564102564102,25.3,F
  1015,2017/08,新潟,101,SW,39,1015,2017/08,静岡,101,SW,32,7,17.94871794871795,35.2,F
  1015,2017/08,新潟,101,SW,39,1015,2017/08,鹿児島,101,SW,18,21,53.84615384615385,19.8,F
  1015,2017/08,新潟,101,SW,39,1015,2017/08,福島,101,SW,17,22,56.41025641025641,18.7,F
  </code></pre>
  
  <p>Code :</p>
  
  <pre><code>val df = spark.read.format("csv").option("header","true").option("inferSchema","true").load("s3a://test_system/transcation.csv")
      df.createOrReplaceTempView("data")
      val res = spark.sql("select count(*) from data")
      res.show(10)
      res.coalesce(1).write.format("csv").option("header","true").mode("Overwrite")
       .save("s3a://test_system/Output/Test_Result")
       res.createOrReplaceTempView("res1")
       val res2 = spark.sql("select distinct flag from res1 where flag = 'F'")
       if (res2 ==='F')
       {
       //writing to s3 bucket as raw data .Here transcation.csv file.
       df.write.format("csv").option("header","true").mode("Overwrite")
       .save("s3a://test_system/Output/Test_Result/rawdata")
       }
  </code></pre>
  
  <p>I am trying this approach but it is not exporting df data to s3 bucket.
  How can i export/write data to S3 bucket by using condition?</p>
  
  <p>Many thanks for your help.</p>