`avg` of decimals truncates the result instead of rounding it
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 62/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
調査の方向性
切り捨ては datafusion/functions-aggregate-common/src/utils.rs の DecimalAverager::avg で発生しており、スケール済みの合計を div_wrapping で件数で割っている箇所です。issue の SQL で再現し、期待値 1.666667 に対して 1.666666 となることを確認したうえで、除算を0から遠ざかる方向への半分切り上げ(round half away from zero)に変更してください。avg(1, 2, 2) を decimal(10,2) に対して実行すると 1.666667 が返り、既存の decimal 集計テストがすべて通れば完了です。
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
avg over a decimal column returns Decimal(p + 4, s + 4) (MySQL's convention), but it computes the value by truncating, not rounding. DecimalAverager::avg scales the sum and then divides by the count with div_wrapping, which is integer division and truncates toward zero:
So the last digit of an average is often one unit too small in magnitude.
To Reproduce
datafusion-cli 55.3.0:
select avg(x), arrow_typeof(avg(x))
from (values (cast(1 as decimal(10,2))), (cast(2 as decimal(10,2))), (cast(2 as decimal(10,2)))) as v(x);
-- 1.666666, Decimal128(14, 6)
The same average elsewhere:
| avg(1, 2, 2) | |
|---|---|
| DataFusion 55.3.0 | 1.666666 |
| MySQL 8.4.13 (same result scale, 6) | 1.666667 |
| PostgreSQL 16 | 1.6666666666666667 |
Expected behavior
The average is rounded to the result scale, half away from zero, as MySQL (whose s + 4 scale this follows) and PostgreSQL do: 1.666667 here.
Additional context
Decimal / has the same issue in the arrow-rs division kernel, reported at https://github.com/apache/arrow-rs/issues/12426. This one is separate: the average is computed here, not through that kernel.
- 主要言語
- Rust
- スター
- 9.6k
- フォーク
- 2.7k
- 平均マージ
- 3日 17時間
- マージ済み PR(30日)
- 318
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apache/datafusion のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
apache/datafusion#27687 ·
メンテナーはふだん 1 日以内に返信
-
`verify-release-candidate.sh` version check doesn't catch `-dev` versions and is skipped on macOS対応中かも @vinycalves が 5 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
apache/datafusion#27563 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
`MoveTowardsLeafNodes` placement implies speculative evaluation, but the docs don't say so対応中かも @Inf1mum が 6 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
apache/datafusion#27487 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
`lpad` and `rpad` with a literal length above `i32::MAX` error on a NULL string or fill対応中かも @TechWizard9999 が 6 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
apache/datafusion#27482 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Window constructors panic when the expression list is empty対応中かも @abp002 が 9 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
apache/datafusion#27315 · コメント 3 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
apache/datafusion の issue をすべて見る
似ている issue
-
ai_p1 comp-sql-syntax
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
ClickHouse/ClickHouse#133888 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
horizon-rust/horizon#20542 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
LadybirdBrowser/ladybird#15521 ·
メンテナーはふだん 1 日以内に返信
-
macOS: the Save Diagnostics panel goes behind the editor after an app switch and can't be reachedオープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
getopenscreen/openscreen#1667 ·
メンテナーはふだん 1 日以内に返信
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
erkamyaman/rust-anything#371 ·
メンテナーはふだん 1 日以内に返信