apache / apache/datafusion-sqlparser-rs

Inconsistent spans for function calls

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

説明

When using functions spans, it appears that sometimes the closing parenthesis is included, sometimes not.

Consider the following test:

```rust
#[test]
fn test_function_span() {
let sql = "SELECT database(), left(user(),instr(concat(user(),'@'),'@')-1);";
let r = Parser::parse_sql(&crate::dialect::MySqlDialect {}, sql).unwrap();

let query = match &r[0] {
crate::ast::Statement::Query(q) => q,
_ => panic!("Expected query"),
};

let select = match query.body.as_ref() {
crate::ast::SetExpr::Select(s) => s,
_ => panic!("Expected select"),
};

let database_func = match &select.projection[0] {
crate::ast::SelectItem::UnnamedExpr(crate::ast::Expr::Function(func)) => func,
_ => panic!("Expected function expression"),
};
let span = database_func.span();
assert_eq!(span.start, (1, 8).into());
assert_eq!(span.end, (1, 17).into()); // fails here

let left_func = match &select.projection[1] {
crate::ast::SelectItem::UnnamedExpr(crate::ast::Expr::Function(func)) => func,
_ => panic!("Expected function expression"),
};
let span = left_func.span();
assert_eq!(span.start, (1, 20).into());
assert_eq!(span.end, (1, 63).into());
}
```

In both cases, we're testing if the closing parenthesis is included in the span. The first span test for `database_func` fails:

```diff
Diff < left / right > :
-Location(1,16)
+Location(1,17)
```

If I comment that part, the second pair of span assertions passes correctly.

In other words, it seems that we only include closing parentheses for function calls with arguments, but not if there's no argument.

Related: #1548 #1563 #1676

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

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

調査の方向性

提供されている test_function_span ケースから始め、Parser::parse_sql と MySqlDialect を使い、その後 database() と left(...) について関数 span がどのように生成されるかを追跡します。引数ありと引数なしの呼び出しで span の境界を比較します。両方の assertion に一貫して閉じ括弧が含まれ、テストが成功すれば完了です。

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

評価

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

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

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