Junit spark: what is the equivalent of assertDataFrameEquals in java to compare 2 dataframes

Viewed 376

I need to compare 2 dataframes in my unit test using java, i know that in scala we have assertDataFrameEquals but i didn't found the equivalent in java or how to compare 2 dataframes in junit. Thank you in advance

1 Answers

assertDataFrameDataEquals is also available in java from spark-testing-base You need to import JavaDataFrameSuiteBase (in Scala it is just DataFrameSuiteBase)

import com.holdenkarau.spark.testing.JavaDataFrameSuiteBase;

The main thing in java you need to create an object for JavaDataFrameSuiteBase to access the methods. So you can use assertDataFrameDataEquals as below. This is using junit and spark-testing-base.

@Test
public void personsComputeTransformTest() {

// read personsInputDf(input) and call your function to be tested to get personsResultDf(result)

JavaDataFrameSuiteBase javaDataFrameSuiteBase = new JavaDataFrameSuiteBase();
javaDataFrameSuiteBase.assertDataFrameDataEquals(personsInputDf, personsResultDf);

}
Related