title: How to save spark dataframe that is not empty
body: <p>We are saving a dataframe but we need to check that the dataframe should not be empty.</p>
  
  <p>To achieve this we are using <code>df.isEmpty()</code>  which is a very common practice while saving a DF.</p>
  
  <p>My concern is that df.isEmpty, head(1), limit(1) all of these performs an <strong>Action</strong> which will execute the whole plan for the 1st time &amp; then when we <strong>save</strong> it will trigger(execute) the plan again <strong>the 2nd time</strong>. Isn't it very bad, is there a better way of doing this?</p>
  
  <p>In most of the code examples, blogs I came across this is the common way of saving non-empty dataframes  Check of empty (which triggers action &amp; executes plan), then save(which triggers action &amp; executes whole plan again)</p>