apache / apache/datafusion-sqlparser-rs

Outdated operation precedence.

オープン
#814 コメント 6 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Rust
スター
3.5k
フォーク
772
平均マージ
4日 9時間
マージ済み PR(30日)
17

説明

Here's an expression: `SELECT ~1 + 2`. If you plug it into `PostgreSQL` interpreter, here's what the output looks like:
```
postgres=# select ~1 + 2;
?column?
----------
-4
(1 row)

postgres=# select ~(1 + 2);
?column?
----------
-4
(1 row)

postgres=# select (~1) + 2;
?column?
----------
0
(1 row)
```
As you can see here, and according to [operation precedence](https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-PRECEDENCE) listed in documentation, the `+` operation is more powerful than the `~` operation, and thus we have PGBitwiseNot(1 + 2). However, if we plug this into the parser, we get the following AST:
```
...
projection: [
UnnamedExpr(
BinaryOp {
left: UnaryOp {
op: PGBitwiseNot,
expr: Value(
Number(
"1",
false,
),
),
},
op: Plus,
right: Value(
Number(
"2",
false,
),
),
},
),
],
...
```
Which is implying `(~1) + 2` instead of `~(1 + 2)`. This should be fixed.

**UPDATE:**
In code, I found a reference to an old [PostgreSQL precedence table](https://www.postgresql.org/docs/7.0/operators.htm#AEN2026), using which the parser is built. However, this table is for a very old (`7.0`, released `May 8, 2000`) version of PostgreSQL. There latest version is `15.1`. Shouldn't this be updated?

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

まず、parser が参照している PostgreSQL 7.0 の優先順位表と、issue にリンクされている現在の PostgreSQL の優先順位に関するドキュメントを読んでください。`SELECT ~1 + 2` に対する parser の AST を、ドキュメントに記載された動作および 3 つの例のクエリと比較してください。parser が意図した優先順位を適用し、対応する AST を生成すれば完了です。

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

評価

技術スタック
postgresql, rust, sql
領域
compilers, databases
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

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

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