Github user fhueske commented on a diff in the pull request:
https://github.com/apache/flink/pull/2049#discussion_r66638155
--- Diff:
flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/runtime/aggregate/AvgAggregate.scala
---
@@ -66,51 +66,63 @@ abstract class IntegralAvgAggregate[T] extends
AvgAggregate[T] {
def doPrepare(value: Any, partial: Row): Unit
}
-class ByteAvgAggregate extends IntegralAvgAggregate[Byte] {
+class ByteAvgAggregate[T] extends IntegralAvgAggregate[T] {
--- End diff --
I think it would be cleaner to keep the `Byte` type parameter.
How about we add an abstract method `def doEvaluate(buffer: Row): Any` to
`IntegralAvgAggregate`.
The subclasses of `IntegralAvgAggregate` implement `doEvaluate` like
`ByteAvgAggregate`:
```
override def doEvaluate(buffer: Row): Any = {
val bufferSum = buffer.productElement(partialSumIndex).asInstanceOf[Long]
val bufferCount =
buffer.productElement(partialCountIndex).asInstanceOf[Long]
if (bufferCount == 0L) {
null
} else {
(bufferSum / bufferCount).toByte
}
}
```
and return an `Any` which is casted to `T` by
`IntegralAvgAggregate.evaluate()` as follows:
```
override def evaluate(buffer: Row): T = {
doEvaluate(buffer).asInstanceOf[T]
}
```
Same for the `FloatingAvgAggregate` and its subclasses.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---