title: Alternative to count in Spark sql to check if a query return empty result
body: <p>I know <code>count</code> action can be expensive in Spark, so to improve performance I'd like to have a different way just to check if a query can return any results</p>
  
  <p>Here is what I did</p>
  
  <pre><code>var df = spark.sql("select * from table_name where condition = 'blah' limit 1");
  var dfEmpty = df.head(1).isEmpty;
  </code></pre>
  
  <p>Is it a valid solution or is there any potential uncaught error if I use above solution to check query result? It is a lot faster though.</p>