SQL API: aggregates don't skip NULL values (COUNT(col) counts them, SUM and AVG throw NPE)

オープン
#891 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

@AarushShetty346 がすでに取り組んでいます。

2026年11月18日 から。

  • #893 @AarushShetty346 による — オープン

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
20/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
java, spark, sql
領域
backend, databases

調査の方向性

Start with AggregateAddCols.java, AggregateFunction.java, and AggregateGetResult.java at the linked lines; trace how NULL values are handled through aggregation and how AVG gets its count. Reproduce the listed queries on the Java platform, including a GROUP BY case, and check the behavior on Spark. Done means COUNT(col), SUM, and AVG match the expected results while COUNT(*) still counts every row.

索引モデルが issue の本文から書いたものです。

説明

Aggregates in the SQL API treat NULL as a value. COUNT(col) counts NULL rows, and SUM / AVG throw a NullPointerException when a column has a NULL.

In SQL, every aggregate except COUNT(*) ignores NULL values. There are three spots where this goes wrong:

  1. AggregateAddCols.java:53 sets every COUNT column to 1, so COUNT(col) is always the same as COUNT(*).
  2. AggregateFunction.java:118-124 picks the type from whichever side isn't null, then still passes the null to the function. For example, Integer::sum is applied to (1, null) and fails on unboxing.
  3. AggregateGetResult.java:55-56 divides the AVG sum by the row count, not by the number of non-null values. AVG would therefore be wrong even without the NPE.
To reproduce
col1:int,col2:string
1;a
;b
3;c

On the Java platform:

query result expected
SELECT COUNT(*) FROM fs.exampleNull 3 3
SELECT COUNT(col1) FROM fs.exampleNull 3 2
SELECT SUM(col1) FROM fs.exampleNull NPE 4
SELECT AVG(col1) FROM fs.exampleNull NPE 2.0
java.lang.NullPointerException
    at org.apache.wayang.api.sql.calcite.converter.functions.AggregateFunction.castAndMap(AggregateFunction.java:127)
    at org.apache.wayang.api.sql.calcite.converter.functions.AggregateFunction.apply(AggregateFunction.java:58)

The same thing happens with GROUP BY when a group has both NULL and non-NULL values. It fails in JavaReduceBy, and in Spark too.

Tested on main at 713faa7. I have a fix with tests and will open a PR for it.

主要言語
Java
スター
284
フォーク
147
平均マージ
2日 13時間
マージ済み PR(30日)
13

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

apache/wayang のほかの issue

apache/wayang の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。