Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/18113#discussion_r153021722
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/typedaggregators.scala
---
@@ -99,3 +94,91 @@ class TypedAverage[IN](val f: IN => Double) extends
Aggregator[IN, (Double, Long
toColumn.asInstanceOf[TypedColumn[IN, java.lang.Double]]
}
}
+
+class TypedMinDouble[IN](val f: IN => Double) extends Aggregator[IN,
Double, Double] {
+ override def zero: Double = Double.PositiveInfinity
+ override def reduce(b: Double, a: IN): Double = math.min(b, f(a))
+ override def merge(b1: Double, b2: Double): Double = math.min(b1, b2)
+ override def finish(reduction: Double): Double = {
+ if (Double.PositiveInfinity == reduction) {
--- End diff --
Since it's hard to tell if it's empty input or inputs of all
`Double.PositiveInfinity`, my new proposal
```
class MutableLong(var value: Long) extend Serializable
class TypedMinLong[IN](val f: IN => Long) extends Aggregator[IN,
MutableLong, java.lang.Long] {
override def zero: MutableLong = null
override def reduce(b: MutableLong, a: IN): MutableLong = {
if (b == null) {
new MutableLong(f(a))
} else {
b.value = math.max(b.value, f(a))
b
}
}
override def finish(reduction: MutableLong): java.lang.Long = {
if (reduction == null) {
null
} else {
reduction.value
}
}
}
```
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]