apache / apache/datafusion-sqlparser-rs
Inconsistent spans for function calls
- 主要语言
- Rust
- 星标
- 3.5k
- 派生
- 772
- 平均合并
- 4 天 9 小时
- 30 天内合并 PR
- 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
贡献指南
这个仓库没有索引到贡献指南
调研方向
先使用 Parser::parse_sql 和 MySqlDialect 从提供的 test_function_span 用例开始,然后跟踪 database() 和 left(...) 的函数 span 是如何生成的。比较带参数和不带参数调用的 span 边界。当两个 assertion 都一致地包含右括号且测试通过时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- rust
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100