title: Check equality for two Spark DataFrames in Scala
body: <p>I'm new to Scala and am having problems writing unit tests.</p>
  
  <p>I'm trying to compare and check equality for two Spark DataFrames in Scala for unit testing, and realized that there is no easy way to check equality for two Spark DataFrames.</p>
  
  <p>The C++ equivalent code would be (assuming that the DataFrames are represented as double arrays in C++):</p>
  
  <pre><code>    int expected[10][2];
      int result[10][2];
      for (int row = 0; row &lt; 10; row++) {
          for (int col = 0; col &lt; 2; col++) {
              if (expected[row][col] != result[row][col]) return false;
          }
      }
  </code></pre>
  
  <p>The actual test would involve testing for equality based on the data types of the columns of the DataFrames (testing with precision tolerance for floats, etc).</p>
  
  <p>It seems like there's not an easy way to iteratively loop over all the elements in the DataFrames using Scala and the other solutions for checking equality of two DataFrames such as <code>df1.except(df2)</code> do not work in my case as I need to be able to provide support for testing equality with tolerance for floats and doubles.</p>
  
  <p>Of course, I could try to round all the elements beforehand and compare the results afterwards, but I would like to see if there are any other solutions that would allow me to iterate through the DataFrames to check for equality.</p>