Skip to content

feat: add support for duckdb style "FROM <tbl>" statements - #1144

Closed
universalmind303 wants to merge 3 commits into
apache:mainfrom
universalmind303:universalmind303/from-syntax
Closed

universalmind303 wants to merge 3 commits into
apache:mainfrom
universalmind303:universalmind303/from-syntax

Conversation

@universalmind303

Copy link
Copy Markdown
Contributor

allows for parsing of duckdb's from queries

closes #1143

Comment thread src/parser/mod.rs
SetExpr::Values(self.parse_values(is_mysql)?)
} else if self.parse_keyword(Keyword::TABLE) {
SetExpr::Table(Box::new(self.parse_as_table()?))
} else if self.parse_keyword(Keyword::FROM) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea why, but adding this branch causes SO in the recursion tests such as parse_deeply_nested_parens_hits_recursion_limits

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

even if the branch is never met, the presence of it is causing SO.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe @alamb, @andygrove @nickolay knows why adding this condition causes a SO.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch probably makes the stack frame size increase in debug builds as it adds some new local variables. I think we could fix the test by decreasing the recursion limit

@alamb alamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this contribution @universalmind303 -- I left some comments that hopefully will help us get this PR good to go

Comment thread src/parser/mod.rs
SetExpr::Values(self.parse_values(is_mysql)?)
} else if self.parse_keyword(Keyword::TABLE) {
SetExpr::Table(Box::new(self.parse_as_table()?))
} else if self.parse_keyword(Keyword::FROM) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch probably makes the stack frame size increase in debug builds as it adds some new local variables. I think we could fix the test by decreasing the recursion limit

Comment thread tests/sqlparser_duckdb.rs
#[test]
fn test_duckdb_from_statement_with_filter_and_select() {
let stmt = duckdb().verified_only_select("FROM t1 SELECT b WHERE a = 1");
println!("{:?}", stmt);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left over?

Comment thread tests/sqlparser_duckdb.rs
#[test]
fn test_duckdb_from_statement_with_filter() {
let stmt = duckdb().verified_only_select("FROM t1 WHERE a = 1");
println!("{:?}", stmt);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left over?

Comment thread src/parser/mod.rs

/// Parse a duckdb style `FROM` statement without a select.
/// assuming the initial `FROM` was already consumed
pub fn parse_from_select(&mut self) -> Result<Select, ParserError> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems largely copied from the normal select parsing -- is there any way to refactor the code to reduce the duplication

@alamb

alamb commented Feb 29, 2024

Copy link
Copy Markdown
Contributor

Marking as Draft to signify this PR is no longer waiting on review. Please mark it as ready for review when it is ready for another look.

@alamb

alamb commented Apr 7, 2024

Copy link
Copy Markdown
Contributor

FWIW @Nikita-str has solved the stack overflow issues in #1171 if you wanted to revive this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

duckdb style FROM <tbl> [SELECT] ... syntax

2 participants