Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/scala/com/amazon/deequ/analyzers/Histogram.scala
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ case class Histogram(

// sort in descending frequency
val topNRowsDF = theState.frequencies
.orderBy(col(countColumnName).desc)
.orderBy(col(countColumnName).desc, col(column).asc)
.limit(maxDetailBins)
.collect()

Expand Down
17 changes: 17 additions & 0 deletions src/test/scala/com/amazon/deequ/analyzers/HistogramTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,23 @@ class HistogramTest extends AnyWordSpec with Matchers with SparkContextSpec with
keys(1) shouldBe "Electronics" // second highest: 600
}

"sort tied frequencies alphabetically" in withSparkSession { spark =>
import spark.implicits._

val data = (Seq.fill(51)("Iris-setosa") ++
Seq.fill(50)("Iris-virginica") ++
Seq.fill(50)("Iris-versicolor") ++
Seq.fill(10)("Iris-xiphium")).toDF("class")

val histogram = Histogram("class", computeFrequenciesAsRatio = false)
val result = histogram.calculate(data)

result.value.isSuccess shouldBe true
val keys = result.value.get.values.keys.toSeq

keys shouldBe Seq("Iris-setosa", "Iris-versicolor", "Iris-virginica", "Iris-xiphium")
}

"handle all null data gracefully" in withSparkSession { spark =>
import spark.implicits._

Expand Down
Loading