apache / apache/datafusion-sqlparser-rs
Fails to parse FORCE INDEX(idx_test)
- Dominant language
- Rust
- Stars
- 3.5k
- Forks
- 772
- Avg merge
- 4d 9h
- Merged PRs (30d)
- 17
Description
```
fn main() -> Result<()> {
use sqlparser::dialect::GenericDialect;
use sqlparser::parser::Parser;
let dialect = GenericDialect {}; // or AnsiDialect, or MySqlDialect
let sql = "SELECT a, b, 123, myfunc(b) \
FROM table_1 FORCE INDEX (idx_name)\
WHERE a > b AND b < 100 \
ORDER BY a DESC, b";
let ast = Parser::parse_sql(&dialect, sql).unwrap();
println!("AST: {:?}", ast);
Ok(())
}
```
throws
```
DEBUG sqlparser::dialect: get_next_precedence_full() TokenWithSpan { token: Word(Word { value: "FROM", quote_style: None, keyword: FROM }), span: Span(Location(1,29)..Location(1,33)) }
2025-02-10T19:22:33.781308Z DEBUG sqlparser::parser: next precedence: 0
thread 'main' panicked at standalone/src/main.rs:19:48:
called `Result::unwrap()` on an `Err` value: ParserError("Expected: end of statement, found: INDEX at Line: 1, Column: 48")
stack backtrace:
0: rust_begin_unwind
at /rustc/9fc6b43126469e3858e2fe86cafb4f0fd5068869/library/std/src/panicking.rs:665:5
1: core::panicking::panic_fmt
at /rustc/9fc6b43126469e3858e2fe86cafb4f0fd5068869/library/core/src/panicking.rs:76:14
2: core::result::unwrap_failed
at /rustc/9fc6b43126469e3858e2fe86cafb4f0fd5068869/library/core/src/result.rs:1699:5
3: core::result::Result::unwrap
at /Users/jasonhansen/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/result.rs:1104:23
4: standalone::main
at ./src/main.rs:19:15
5: core::ops::function::FnOnce::call_once
at /Users/jasonhansen/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by running the reproduction in standalone/src/main.rs with GenericDialect, AnsiDialect, and MySqlDialect, then trace the parser entry point handling the FROM clause and FORCE INDEX. Done means the supplied SELECT parses without the reported INDEX error and the resulting AST is produced successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100