Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ParserError if nested explain #781

Merged
merged 1 commit into from Dec 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 25 additions & 10 deletions src/parser.rs
Expand Up @@ -4693,21 +4693,24 @@ impl<'a> Parser<'a> {
format = Some(self.parse_analyze_format()?);
}

if let Some(statement) = self.maybe_parse(|parser| parser.parse_statement()) {
Ok(Statement::Explain {
match self.maybe_parse(|parser| parser.parse_statement()) {
Some(Statement::Explain { .. }) | Some(Statement::ExplainTable { .. }) => Err(
ParserError::ParserError("Explain must be root of the plan".to_string()),
),
Some(statement) => Ok(Statement::Explain {
describe_alias,
analyze,
verbose,
statement: Box::new(statement),
format,
})
} else {
let table_name = self.parse_object_name()?;

Ok(Statement::ExplainTable {
describe_alias,
table_name,
})
}),
_ => {
let table_name = self.parse_object_name()?;
Ok(Statement::ExplainTable {
describe_alias,
table_name,
})
}
}
}

Expand Down Expand Up @@ -7138,4 +7141,16 @@ mod tests {
))
);
}

#[test]
fn test_nested_explain_error() {
let sql = "EXPLAIN EXPLAIN SELECT 1";
let ast = Parser::parse_sql(&GenericDialect, sql);
assert_eq!(
ast,
Err(ParserError::ParserError(
"Explain must be root of the plan".to_string()
))
);
}
}