PostgreSQL dialect: unary minus binds more loosely than `^`, so `-1 ^ 0` returns -1
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 76/100
調査の方向性
apache/datafusion-sqlparser-rs#2819 の修正後の対応は DataFusion で行います。まず、どの sqlparser リリースにその修正が含まれるか、また DataFusion が sqlparser のバージョンをどのように固定または更新しているかを確認します。次に、PostgreSQL 方言の解析に関する既存の sqllogictest ケースを探します。依存関係に修正が含まれ、テストで -1 ^ 0 と -2 ^ 2 をカバーし、結果が PostgreSQL と一致すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
This issue tracks the parser fix in apache/datafusion-sqlparser-rs#2819. The cause is in sqlparser, and DataFusion needs follow-up work after the fix lands.
Describe the bug
With the PostgreSQL dialect, ^ is the power operator. Unary minus binds more loosely than ^, so -1 ^ 0 is planned as -(1 ^ 0) and returns -1.
In PostgreSQL, unary minus binds more tightly than ^ (operator precedence table). PostgreSQL computes (-1) ^ 0 and returns 1.
To Reproduce
SET datafusion.sql_parser.dialect = 'PostgreSQL';
SELECT -1 ^ 0;
SELECT -2 ^ 2;
EXPLAIN SELECT -2 ^ 2;
On main (c120619de), datafusion-cli returns:
+------------------------------+
| (- power(Int64(1),Int64(0))) |
+------------------------------+
| -1.0 |
+------------------------------+
+------------------------------+
| (- power(Int64(2),Int64(2))) |
+------------------------------+
| -4.0 |
+------------------------------+
The plan shows (- power(Int64(2),Int64(2))), so the minus is applied after the power.
Expected behavior
The same results as PostgreSQL 17:
postgres=# SELECT -1 ^ 0, -2 ^ 2;
?column? | ?column?
----------+----------
1 | 4
DuckDB gives the same results (1 and 4).
Additional context
The cause is in sqlparser: the operand of a unary - or + is parsed at Precedence::MulDivModOp, but PostgreSqlDialect puts ^ above that level. The details are in apache/datafusion-sqlparser-rs#2819.
Work in DataFusion after the parser fix:
- Upgrade to a
sqlparserrelease that has the fix. - Add a
sqllogictestcase for-1 ^ 0and-2 ^ 2with the PostgreSQL dialect.
Related: #22461 (binary operator precedence against PostgreSQL).
- 主要言語
- Rust
- スター
- 9.6k
- フォーク
- 2.6k
- 平均マージ
- 3日 21時間
- マージ済み PR(30日)
- 331
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apache/datafusion のほかの issue
-
Substrait consumer doesn't recognise `shift_left` / `shift_right` from functions_arithmetic.yaml対応中かも @jonasHanhan が 1 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
apache/datafusion#27059 ·
メンテナーはふだん 1 日以内に返信
-
`ProjectionExprs::project_statistics` computes approximate `Statistics::total_byte_size` ignoring column stats対応中かも @joseph-isaacs が 2 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
apache/datafusion#27050 ·
メンテナーはふだん 1 日以内に返信
-
physical-plan: decoding an Unnest or Explain node with an unset field panics対応中かも @geoHeil が 1 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
apache/datafusion#26999 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
datafusion-proto: decoding an AvroScan node without the avro feature panics対応中かも @geoHeil が 1 日前に担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
apache/datafusion#26998 ·
メンテナーはふだん 1 日以内に返信
-
`repeat` on `LargeUtf8` aborts the process on a result size no allocation can satisfy対応中かも @huong8373tt-beep が 3 日前に担当しました。 オープンbug good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
apache/datafusion#26948 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
apache/datafusion の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
nervosnetwork/fiber#1723 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 69/100
メンテナーはふだん 1 日以内に返信
-
needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 71/100
pbakaus/impeccable#1314 ·
メンテナーはふだん 1 日以内に返信
-
marmite skill: `curl ... | sh` is the first install method, bypassing review and integrity checksオープン
難易度 1/5 1〜3時間 初心者へのやさしさ 78/100
rochacbruno/marmite#565 ·