Native TopK evaluates sort keys for a single-row input, raising false ANSI errors

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

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

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
43/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
scala, spark

調査の方向性

Start by reading the TopK implementation and its tests, then compare its handling of a single-row batch with Spark's TakeOrderedAndProjectExec behavior described in the issue. Reproduce the SQL example with ANSI mode enabled and adaptive execution disabled. Done means the query returns the row in Comet as it does in Spark, without raising ARITHMETIC_OVERFLOW.

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

説明

bug priority:medium
Describe the bug

With spark.sql.ansi.enabled=true, a TopK (ORDER BY ... LIMIT n) whose whole input is a single row fails in Comet with ARITHMETIC_OVERFLOW when its first sort key overflows on that row, while Spark returns the row.

Spark's TakeOrderedAndProjectExec goes through takeOrdered, which uses Guava's Ordering.leastOf (TopKSelector) per partition and a BoundedPriorityQueue to merge. Both store the first element without a comparison, and sorting a single element compares nothing, so Spark's lazily generated ordering never evaluates any sort key when the input has one row. Comet's native TopK evaluates every sort key over the whole batch.

With two or more rows Spark compares and evaluates the first key for every row, so both engines fail. This is pre-existing and independent of https://github.com/apache/datafusion-comet/pull/7457 , which falls back when a sort key after the first can fail; it was raised in review there.

Steps to reproduce
SET spark.sql.ansi.enabled=true;
SET spark.sql.adaptive.enabled=false;
CREATE TABLE one_row(a int, b int) USING parquet;
INSERT INTO one_row VALUES (1, 2147483647);

SELECT a, b FROM one_row ORDER BY b + 1 LIMIT 10;

Spark returns 1, 2147483647. Comet fails with [ARITHMETIC_OVERFLOW] integer overflow (checked on Spark 4.1 with a CometSqlFileTestSuite fixture, current main plus #7457).

Expected behavior

Same result as Spark. Since it only affects a single-row input, it may be enough to document it rather than fall back for every TopK with a fallible first key.

Additional context

Suggested labels: priority:low, correctness.

主要言語
Scala
スター
1.3k
フォーク
414
平均マージ
3日 5時間
マージ済み PR(30日)
210

環境構築

はじめの一歩

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

apache/datafusion-comet のほかの issue

apache/datafusion-comet の issue をすべて見る

似ている issue

Scala の issue をもっと見る

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

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