title: Spark "Split" dataframe
body: <p>I'm using Java Spark.</p>
  
  <p>I have <code>Dataset</code> that contains JSON strings that I'm reading as follow:</p>
  
  <pre><code>Dataset&lt;Row&gt; generalDS = spark.read().schema(jsonSchema).option("samplingRatio","0.1").json(jsonsDirPath);
  </code></pre>
  
  <p>Now, <code>generalDS</code> contains the following data:</p>
  
  <pre><code>code    data     load_date
  --------------------------
   1      data...  20180823
   1      data...  20180823
   2      data...  20180823
   1      data..   20180823
   2      data...  20180823
   2      data...  20180823
  </code></pre>
  
  <p>Currently I'm split the <code>Dataset</code> as follow:</p>
  
  <pre><code>Dataset&lt;Row&gt; ds1 = generalDS.where("code = 1").select(columns1);
  ds1.write().mode(mode1).format(format1).save(path1);
  Dataset&lt;Row&gt; ds2 = generalDS.where("code = 2").select(columns2);
  ds2.write().mode(mode2).format(format2).save(path2);
  </code></pre>
  
  <p>My question is if that is the best way to split the dataset or there is another <strong>fast</strong> way to do that?
  Because I think that <code>where</code> take a long time.</p>
  
  <p>I can't do <code>partitionBy</code> code and by load_date columns because I need to write different columns.</p>
  
  <p>Any suggestions?</p>
  
  <p>Thanks.</p>