cloud-fan commented on a change in pull request #23304: [SPARK-26353][SQL]Add
typed aggregate functions: max&&min
URL: https://github.com/apache/spark/pull/23304#discussion_r245674349
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/typedaggregators.scala
##########
@@ -99,3 +99,179 @@ class TypedAverage[IN](val f: IN => Double) extends
Aggregator[IN, (Double, Long
toColumn.asInstanceOf[TypedColumn[IN, java.lang.Double]]
}
}
+
+trait TypedMinDouble[IN, OUT] extends Aggregator[IN, MutableDouble, OUT] {
+ val f: IN => Double
+ override def zero: MutableDouble = null
+ override def reduce(b: MutableDouble, a: IN): MutableDouble = {
+ if (b == null) {
+ new MutableDouble(f(a))
+ } else {
+ b.value = math.min(b.value, f(a))
+ b
+ }
+ }
+ override def merge(b1: MutableDouble, b2: MutableDouble): MutableDouble = {
+ if (b1 == null) {
+ b2
+ } else if (b2 == null) {
+ b1
+ } else {
+ b1.value = math.min(b1.value, b2.value)
+ b1
+ }
+ }
+
+ override def bufferEncoder: Encoder[MutableDouble] =
Encoders.kryo[MutableDouble]
+}
+
+class JavaTypedMinDouble[IN](override val f: IN => Double)
+ extends TypedMinDouble[IN, java.lang.Double] {
+ override def outputEncoder: Encoder[java.lang.Double] =
ExpressionEncoder[java.lang.Double]()
+ override def finish(reduction: MutableDouble): java.lang.Double =
reduction.value
Review comment:
what if `reduction` is null?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]