-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Demo CI Benchmark assertApproximateDataFrameEquality
- Loading branch information
Showing
2 changed files
with
28 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 26 additions & 44 deletions
70
benchmarks/src/main/scala/com/github/mrpowers/spark/fast/tests/MyBenchmark.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,41 @@ | ||
package com.github.mrpowers.spark.fast.tests | ||
|
||
import org.apache.spark.sql.Row | ||
import org.apache.spark.sql.SparkSession | ||
import org.openjdk.jmh.annotations._ | ||
import org.openjdk.jmh.infra.Blackhole | ||
|
||
import java.time.Instant | ||
import java.util.concurrent.TimeUnit | ||
import scala.util.Try | ||
|
||
// TODO: move this to separate benchmark project | ||
private class MyBenchmark { | ||
|
||
private class MyBenchmark extends DataFrameComparer { | ||
@Benchmark | ||
@BenchmarkMode(Array(Mode.AverageTime)) | ||
@BenchmarkMode(Array(Mode.AverageTime, Mode.SingleShotTime)) | ||
@Fork(value = 2) | ||
@Warmup(iterations = 10) | ||
@Measurement(iterations = 10) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
def testMethod(blackHole: Blackhole): Boolean = { | ||
val r1 = Row( | ||
"a", | ||
Row( | ||
1, | ||
Row( | ||
2.0, | ||
Row( | ||
null, | ||
Row( | ||
Seq(Row("c"), Row("d")), | ||
BigDecimal.decimal(1.0), | ||
Row(Instant.EPOCH) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
def assertApproximateDataFrameEqualityWithPrecision(blackHole: Blackhole): Boolean = { | ||
val spark = SparkSession | ||
.builder() | ||
.master("local") | ||
.appName("spark session") | ||
.config("spark.sql.shuffle.partitions", "1") | ||
.getOrCreate() | ||
spark.sparkContext.setLogLevel("ERROR") | ||
|
||
import spark.implicits._ | ||
val ds1 = Seq( | ||
("1", "10/01/2019", 26.762499999999996), | ||
("1", "11/01/2019", 26.762499999999996) | ||
).toDF("col_B", "col_C", "col_A") | ||
|
||
val ds2 = Seq( | ||
("1", "10/01/2019", 26.762499999999946), | ||
("1", "11/01/2019", 26.76249999999991) | ||
).toDF("col_B", "col_C", "col_A") | ||
val result = Try(assertApproximateDataFrameEquality(ds1, ds2, precision = 0.0000001, orderedComparison = false)) | ||
|
||
val r2 = Row( | ||
"a", | ||
Row( | ||
1, | ||
Row( | ||
2.0, | ||
Row( | ||
null, | ||
Row( | ||
Seq(Row("c"), Row("d")), | ||
BigDecimal.decimal(1.0), | ||
Row(Instant.EPOCH) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
val bool = RowComparer.areRowsEqual(r1, r2) | ||
blackHole.consume(bool) | ||
bool | ||
blackHole.consume(result) | ||
result.isSuccess | ||
} | ||
} |