Skip to content

Commit 10d0f10

Browse files
samuelcolvinayman-sigma
authored andcommitted
cleanup parse_statement (apache#1407)
1 parent 7406e12 commit 10d0f10

File tree

1 file changed

+51
-51
lines changed

1 file changed

+51
-51
lines changed

src/parser/mod.rs

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -478,88 +478,88 @@ impl<'a> Parser<'a> {
478478
let next_token = self.next_token();
479479
match &next_token.token {
480480
Token::Word(w) => match w.keyword {
481-
Keyword::KILL => Ok(self.parse_kill()?),
482-
Keyword::FLUSH => Ok(self.parse_flush()?),
483-
Keyword::DESC => Ok(self.parse_explain(DescribeAlias::Desc)?),
484-
Keyword::DESCRIBE => Ok(self.parse_explain(DescribeAlias::Describe)?),
485-
Keyword::EXPLAIN => Ok(self.parse_explain(DescribeAlias::Explain)?),
486-
Keyword::ANALYZE => Ok(self.parse_analyze()?),
481+
Keyword::KILL => self.parse_kill(),
482+
Keyword::FLUSH => self.parse_flush(),
483+
Keyword::DESC => self.parse_explain(DescribeAlias::Desc),
484+
Keyword::DESCRIBE => self.parse_explain(DescribeAlias::Describe),
485+
Keyword::EXPLAIN => self.parse_explain(DescribeAlias::Explain),
486+
Keyword::ANALYZE => self.parse_analyze(),
487487
Keyword::SELECT | Keyword::WITH | Keyword::VALUES => {
488488
self.prev_token();
489-
Ok(Statement::Query(self.parse_boxed_query()?))
489+
self.parse_boxed_query().map(Statement::Query)
490490
}
491-
Keyword::TRUNCATE => Ok(self.parse_truncate()?),
491+
Keyword::TRUNCATE => self.parse_truncate(),
492492
Keyword::ATTACH => {
493493
if dialect_of!(self is DuckDbDialect) {
494-
Ok(self.parse_attach_duckdb_database()?)
494+
self.parse_attach_duckdb_database()
495495
} else {
496-
Ok(self.parse_attach_database()?)
496+
self.parse_attach_database()
497497
}
498498
}
499499
Keyword::DETACH if dialect_of!(self is DuckDbDialect | GenericDialect) => {
500-
Ok(self.parse_detach_duckdb_database()?)
501-
}
502-
Keyword::MSCK => Ok(self.parse_msck()?),
503-
Keyword::CREATE => Ok(self.parse_create()?),
504-
Keyword::CACHE => Ok(self.parse_cache_table()?),
505-
Keyword::DROP => Ok(self.parse_drop()?),
506-
Keyword::DISCARD => Ok(self.parse_discard()?),
507-
Keyword::DECLARE => Ok(self.parse_declare()?),
508-
Keyword::FETCH => Ok(self.parse_fetch_statement()?),
509-
Keyword::DELETE => Ok(self.parse_delete()?),
510-
Keyword::INSERT => Ok(self.parse_insert()?),
511-
Keyword::REPLACE => Ok(self.parse_replace()?),
512-
Keyword::UNCACHE => Ok(self.parse_uncache_table()?),
513-
Keyword::UPDATE => Ok(self.parse_update()?),
514-
Keyword::ALTER => Ok(self.parse_alter()?),
515-
Keyword::CALL => Ok(self.parse_call()?),
516-
Keyword::COPY => Ok(self.parse_copy()?),
517-
Keyword::CLOSE => Ok(self.parse_close()?),
518-
Keyword::SET => Ok(self.parse_set()?),
519-
Keyword::SHOW => Ok(self.parse_show()?),
520-
Keyword::USE => Ok(self.parse_use()?),
521-
Keyword::GRANT => Ok(self.parse_grant()?),
522-
Keyword::REVOKE => Ok(self.parse_revoke()?),
523-
Keyword::START => Ok(self.parse_start_transaction()?),
500+
self.parse_detach_duckdb_database()
501+
}
502+
Keyword::MSCK => self.parse_msck(),
503+
Keyword::CREATE => self.parse_create(),
504+
Keyword::CACHE => self.parse_cache_table(),
505+
Keyword::DROP => self.parse_drop(),
506+
Keyword::DISCARD => self.parse_discard(),
507+
Keyword::DECLARE => self.parse_declare(),
508+
Keyword::FETCH => self.parse_fetch_statement(),
509+
Keyword::DELETE => self.parse_delete(),
510+
Keyword::INSERT => self.parse_insert(),
511+
Keyword::REPLACE => self.parse_replace(),
512+
Keyword::UNCACHE => self.parse_uncache_table(),
513+
Keyword::UPDATE => self.parse_update(),
514+
Keyword::ALTER => self.parse_alter(),
515+
Keyword::CALL => self.parse_call(),
516+
Keyword::COPY => self.parse_copy(),
517+
Keyword::CLOSE => self.parse_close(),
518+
Keyword::SET => self.parse_set(),
519+
Keyword::SHOW => self.parse_show(),
520+
Keyword::USE => self.parse_use(),
521+
Keyword::GRANT => self.parse_grant(),
522+
Keyword::REVOKE => self.parse_revoke(),
523+
Keyword::START => self.parse_start_transaction(),
524524
// `BEGIN` is a nonstandard but common alias for the
525525
// standard `START TRANSACTION` statement. It is supported
526526
// by at least PostgreSQL and MySQL.
527-
Keyword::BEGIN => Ok(self.parse_begin()?),
527+
Keyword::BEGIN => self.parse_begin(),
528528
// `END` is a nonstandard but common alias for the
529529
// standard `COMMIT TRANSACTION` statement. It is supported
530530
// by PostgreSQL.
531-
Keyword::END => Ok(self.parse_end()?),
532-
Keyword::SAVEPOINT => Ok(self.parse_savepoint()?),
533-
Keyword::RELEASE => Ok(self.parse_release()?),
534-
Keyword::COMMIT => Ok(self.parse_commit()?),
535-
Keyword::ROLLBACK => Ok(self.parse_rollback()?),
536-
Keyword::ASSERT => Ok(self.parse_assert()?),
531+
Keyword::END => self.parse_end(),
532+
Keyword::SAVEPOINT => self.parse_savepoint(),
533+
Keyword::RELEASE => self.parse_release(),
534+
Keyword::COMMIT => self.parse_commit(),
535+
Keyword::ROLLBACK => self.parse_rollback(),
536+
Keyword::ASSERT => self.parse_assert(),
537537
// `PREPARE`, `EXECUTE` and `DEALLOCATE` are Postgres-specific
538538
// syntaxes. They are used for Postgres prepared statement.
539-
Keyword::DEALLOCATE => Ok(self.parse_deallocate()?),
540-
Keyword::EXECUTE => Ok(self.parse_execute()?),
541-
Keyword::PREPARE => Ok(self.parse_prepare()?),
542-
Keyword::MERGE => Ok(self.parse_merge()?),
539+
Keyword::DEALLOCATE => self.parse_deallocate(),
540+
Keyword::EXECUTE => self.parse_execute(),
541+
Keyword::PREPARE => self.parse_prepare(),
542+
Keyword::MERGE => self.parse_merge(),
543543
// `PRAGMA` is sqlite specific https://www.sqlite.org/pragma.html
544-
Keyword::PRAGMA => Ok(self.parse_pragma()?),
545-
Keyword::UNLOAD => Ok(self.parse_unload()?),
544+
Keyword::PRAGMA => self.parse_pragma(),
545+
Keyword::UNLOAD => self.parse_unload(),
546546
// `INSTALL` is duckdb specific https://duckdb.org/docs/extensions/overview
547547
Keyword::INSTALL if dialect_of!(self is DuckDbDialect | GenericDialect) => {
548-
Ok(self.parse_install()?)
548+
self.parse_install()
549549
}
550550
// `LOAD` is duckdb specific https://duckdb.org/docs/extensions/overview
551551
Keyword::LOAD if dialect_of!(self is DuckDbDialect | GenericDialect) => {
552-
Ok(self.parse_load()?)
552+
self.parse_load()
553553
}
554554
// `OPTIMIZE` is clickhouse specific https://clickhouse.tech/docs/en/sql-reference/statements/optimize/
555555
Keyword::OPTIMIZE if dialect_of!(self is ClickHouseDialect | GenericDialect) => {
556-
Ok(self.parse_optimize_table()?)
556+
self.parse_optimize_table()
557557
}
558558
_ => self.expected("an SQL statement", next_token),
559559
},
560560
Token::LParen => {
561561
self.prev_token();
562-
Ok(Statement::Query(self.parse_boxed_query()?))
562+
self.parse_boxed_query().map(Statement::Query)
563563
}
564564
_ => self.expected("an SQL statement", next_token),
565565
}

0 commit comments

Comments
 (0)