Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 6B4B8200B21 for ; Fri, 10 Jun 2016 18:00:24 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 69EAE160A15; Fri, 10 Jun 2016 16:00:24 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 99DDA160A38 for ; Fri, 10 Jun 2016 18:00:23 +0200 (CEST) Received: (qmail 64296 invoked by uid 500); 10 Jun 2016 16:00:22 -0000 Mailing-List: contact issues-help@flink.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flink.apache.org Delivered-To: mailing list issues@flink.apache.org Received: (qmail 64264 invoked by uid 99); 10 Jun 2016 16:00:22 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Jun 2016 16:00:22 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 692352C1F64 for ; Fri, 10 Jun 2016 16:00:22 +0000 (UTC) Date: Fri, 10 Jun 2016 16:00:22 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: issues@flink.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (FLINK-3971) Aggregates handle null values incorrectly. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Fri, 10 Jun 2016 16:00:24 -0000 [ https://issues.apache.org/jira/browse/FLINK-3971?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15324684#comment-15324684 ] ASF GitHub Bot commented on FLINK-3971: --------------------------------------- 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. > Aggregates handle null values incorrectly. > ------------------------------------------ > > Key: FLINK-3971 > URL: https://issues.apache.org/jira/browse/FLINK-3971 > Project: Flink > Issue Type: Bug > Components: Table API > Affects Versions: 1.1.0 > Reporter: Fabian Hueske > Assignee: GaoLun > Priority: Critical > Fix For: 1.1.0 > > > Table API and SQL aggregates are supposed to ignore null values, e.g., {{sum(1,2,null,4)}} is supposed to return {{7}}. > There current implementation is correct if at least one valid value is present however, is incorrect if only null values are aggregated. {{sum(null, null, null)}} should return {{null}} instead of {{0}} > Currently only the Count aggregate handles the case of null-values-only correctly. -- This message was sent by Atlassian JIRA (v6.3.4#6332)