apache / apache/datafusion-sqlparser-rs
Inconsistent spans for function calls
- Vorherrschende Sprache
- Rust
- Sterne
- 3.5k
- Forks
- 772
- Ø Merge
- 4 T. 9 Std.
- Gemergte PRs (30 T.)
- 17
Beschreibung
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
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Rechercherichtung
Beginne mit dem bereitgestellten Fall test_function_span unter Verwendung von Parser::parse_sql und MySqlDialect; verfolge dann, wie Funktionsspans für database() und left(...) erzeugt werden. Vergleiche die Span-Grenzen für Aufrufe mit und ohne Argumente. Erledigt ist die Aufgabe, wenn beide Assertions konsistent die schließende Klammer enthalten und der Test erfolgreich ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- rust
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100