Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
zeotuan committed Aug 24, 2024
1 parent 899eea3 commit f27d405
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ trait DataFrameComparer extends DatasetComparer {
/**
* Raises an error unless `actualDF` and `expectedDF` are equal
*/
def assertApproximateSmallDataFrameEquality(actualDF: DataFrame,
expectedDF: DataFrame,
precision: Double,
ignoreNullable: Boolean = false,
ignoreColumnNames: Boolean = false,
orderedComparison: Boolean = true,
ignoreColumnOrder: Boolean = false): Unit = {
def assertApproximateSmallDataFrameEquality(
actualDF: DataFrame,
expectedDF: DataFrame,
precision: Double,
ignoreNullable: Boolean = false,
ignoreColumnNames: Boolean = false,
orderedComparison: Boolean = true,
ignoreColumnOrder: Boolean = false
): Unit = {
assertSmallDatasetEquality[Row](
actualDF,
expectedDF,
Expand All @@ -72,13 +74,15 @@ trait DataFrameComparer extends DatasetComparer {
/**
* Raises an error unless `actualDF` and `expectedDF` are equal
*/
def assertApproximateLargeDataFrameEquality(actualDF: DataFrame,
expectedDF: DataFrame,
precision: Double,
ignoreNullable: Boolean = false,
ignoreColumnNames: Boolean = false,
orderedComparison: Boolean = true,
ignoreColumnOrder: Boolean = false): Unit = {
def assertApproximateLargeDataFrameEquality(
actualDF: DataFrame,
expectedDF: DataFrame,
precision: Double,
ignoreNullable: Boolean = false,
ignoreColumnNames: Boolean = false,
orderedComparison: Boolean = true,
ignoreColumnOrder: Boolean = false
): Unit = {
assertLargeDatasetEquality[Row](
actualDF,
expectedDF,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.github.mrpowers.spark.fast.tests
import org.apache.commons.math3.util.Precision
import org.apache.spark.sql.Row

import java.sql.Timestamp
import scala.math.abs

object RowComparer {
Expand Down Expand Up @@ -34,8 +33,8 @@ object RowComparer {
val bd1 = new java.math.BigDecimal(f1.toString)
val bd2 = new java.math.BigDecimal(o2.toString)
bd1.subtract(bd2).abs().compareTo(new java.math.BigDecimal(tol)) == -1
case t1: java.sql.Timestamp => abs(t1.getTime - o2.asInstanceOf[java.sql.Timestamp].getTime) > tol
case t1: java.time.Instant => abs(t1.toEpochMilli - o2.asInstanceOf[java.time.Instant].toEpochMilli) > tol
case t1: java.sql.Timestamp => abs(t1.getTime - o2.asInstanceOf[java.sql.Timestamp].getTime) > tol
case t1: java.time.Instant => abs(t1.toEpochMilli - o2.asInstanceOf[java.time.Instant].toEpochMilli) > tol
case rr1: Row if o2.isInstanceOf[Row] => areRowsEqual(rr1, o2.asInstanceOf[Row], tol)
case _ => o1 == o2
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ object SeqLikesExtensions {
}
val these = seq1.iterator
val those = seq2.iterator
while (these.hasNext && those.hasNext) if (!equals(these.next(), those.next()))
return false
while (these.hasNext && those.hasNext)
if (!equals(these.next(), those.next()))
return false
these.hasNext == those.hasNext
}

// scala2.13 optimization: check number of element if it can be cheaply computed
private def getKnownSize(s: Seq[T]): Int = Try(s.getClass.getMethod("knownSize").invoke(s).asInstanceOf[Int]).getOrElse(s.length)
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ class DataFrameComparerTest extends AnyFreeSpec with DataFrameComparer with Spar

val ds2 = Seq(
("1", "11/01/2019", 26.7624999999999961, Seq(26.7624999999999961, 26.7624999999999961)),
("1", "10/01/2019", 26.762499999999997, Seq(26.762499999999997, 26.762499999999997)),
("1", "10/01/2019", 26.762499999999997, Seq(26.762499999999997, 26.762499999999997))
).toDF("col_B", "col_C", "col_A", "col_D")

assertApproximateDataFrameEquality(ds1, ds2, precision = 0.0000001, orderedComparison = false)
Expand Down Expand Up @@ -560,7 +560,7 @@ class DataFrameComparerTest extends AnyFreeSpec with DataFrameComparer with Spar

val ds2 = Seq(
("2", "11/01/2019", 26.7624999999999961, Seq(26.7624999999999961, 26.7624999999999961)),
("1", "10/01/2019", 26.762499999999997, Seq(26.762499999999997, 26.762499999999997)),
("1", "10/01/2019", 26.762499999999997, Seq(26.762499999999997, 26.762499999999997))
).toDF("col_B", "col_C", "col_A", "col_D")

assertApproximateSmallDataFrameEquality(ds1, ds2, precision = 0.0000001, orderedComparison = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -719,10 +719,9 @@ class DatasetComparerTest extends AnyFreeSpec with DatasetComparer with SparkSes

val ds2 = Seq(
("1", "11/01/2019", 26.7624999999999961, Seq(26.7624999999999961, 26.7624999999999961)),
("1", "10/01/2019", 26.762499999999997, Seq(26.762499999999997, 26.762499999999997)),
("1", "10/01/2019", 26.762499999999997, Seq(26.762499999999997, 26.762499999999997))
).toDF("col_B", "col_C", "col_A", "col_D")


assertApproximateDataFrameEquality(ds1, ds2, precision = 0.0000001, orderedComparison = false)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,4 @@ class SeqLikesExtensionsTest extends AnyFreeSpec with SparkSessionTestWrapper {
assert(!source.approximateSameElements(expected, RowComparer.areRowsEqual(_, _, .00000000001)))
}
}
}
}

0 comments on commit f27d405

Please sign in to comment.