xumingming commented on code in PR #52701:
URL: https://github.com/apache/spark/pull/52701#discussion_r2517374741
##########
sql/core/src/test/scala/org/apache/spark/sql/ApproximatePercentileQuerySuite.scala:
##########
@@ -318,7 +305,7 @@ class ApproximatePercentileQuerySuite extends QueryTest
with SharedSparkSession
| percentile_approx(col, 0.77, 100000),
| percentile_approx(col, 0.77, 1000000)
|FROM $table""".stripMargin),
- Row(18, 17, 17, 17))
+ Row(17, 17, 17, 17))
Review Comment:
> percentile_approx(col, 0.77, 1000)
The result changed in new implementation?
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/ApproximatePercentile.scala:
##########
@@ -267,35 +263,40 @@ object ApproximatePercentile {
// The default relative error can be deduced by defaultError = 1.0 /
DEFAULT_PERCENTILE_ACCURACY
val DEFAULT_PERCENTILE_ACCURACY: Int = 10000
+ def nextPowOf2(relativeError: Double): Int = {
Review Comment:
There is a `ByteArrayMethods.nextPowerOf2`, how about reusing it?
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/ApproximatePercentile.scala:
##########
@@ -267,35 +263,40 @@ object ApproximatePercentile {
// The default relative error can be deduced by defaultError = 1.0 /
DEFAULT_PERCENTILE_ACCURACY
val DEFAULT_PERCENTILE_ACCURACY: Int = 10000
+ def nextPowOf2(relativeError: Double): Int = {
+ val baseK = DoublesSketch.getKFromEpsilon(relativeError, true)
+ if (baseK == 1 || (baseK & (baseK - 1)) == 0) {
Review Comment:
datasketches's K seems has a low bound of 2:
https://github.com/apache/datasketches-java/blob/4d1b5b739d675e3a2abd2b52a2d39528c0c53052/src/main/java/org/apache/datasketches/quantiles/ClassicUtil.java#L51
##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/aggregate/ApproximatePercentileSuite.scala:
##########
@@ -426,12 +426,18 @@ class ApproximatePercentileSuite extends SparkFunSuite {
}
private def compareEquals(left: PercentileDigest, right: PercentileDigest):
Boolean = {
- val leftSummary = left.quantileSummaries
- val rightSummary = right.quantileSummaries
- leftSummary.compressThreshold == rightSummary.compressThreshold &&
- leftSummary.relativeError == rightSummary.relativeError &&
- leftSummary.count == rightSummary.count &&
- leftSummary.sampled.sameElements(rightSummary.sampled)
+ val leftSketch = left.sketchInfo
+ val rightSketch = right.sketchInfo
+ if (leftSketch.isEmpty && rightSketch.isEmpty) {
+ true
+ } else if (leftSketch.isEmpty || rightSketch.isEmpty) {
+ false
+ } else {
+ leftSketch.getK == rightSketch.getK &&
+ leftSketch.getMaxItem == rightSketch.getMaxItem &&
+ leftSketch.getMinItem == rightSketch.getMinItem &&
+ leftSketch.getN == rightSketch.getN
Review Comment:
Do we need to compare the actual content of the sketch?(like
leftSummary.sampled.sameElements(rightSummary.sampled) in previous
implementation)
##########
sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala:
##########
@@ -1182,8 +1182,8 @@ class DataFrameAggregateSuite extends QueryTest
approx_percentile(col("earnings"), lit(0.3), lit(1)),
approx_percentile(col("earnings"), array(lit(0.3), lit(0.6)), lit(1))
),
- Row("Java", 20000.0, Seq(20000.0, 30000.0), 20000.0, Seq(20000.0,
20000.0)) ::
- Row("dotNET", 5000.0, Seq(5000.0, 10000.0), 5000.0, Seq(5000.0,
5000.0)) :: Nil
+ Row("Java", 20000.0, Seq(20000.0, 30000.0), 20000.0, Seq(20000.0,
30000.0)) ::
Review Comment:
Is the result change expected?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]