mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-24 16:04:04 +00:00
ParserError if nested explain (#781)
This commit is contained in:
parent
b93d82dfca
commit
cf3fe64af6
1 changed files with 25 additions and 10 deletions
|
@ -4686,23 +4686,26 @@ impl<'a> Parser<'a> {
|
||||||
format = Some(self.parse_analyze_format()?);
|
format = Some(self.parse_analyze_format()?);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(statement) = self.maybe_parse(|parser| parser.parse_statement()) {
|
match self.maybe_parse(|parser| parser.parse_statement()) {
|
||||||
Ok(Statement::Explain {
|
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,
|
describe_alias,
|
||||||
analyze,
|
analyze,
|
||||||
verbose,
|
verbose,
|
||||||
statement: Box::new(statement),
|
statement: Box::new(statement),
|
||||||
format,
|
format,
|
||||||
})
|
}),
|
||||||
} else {
|
_ => {
|
||||||
let table_name = self.parse_object_name()?;
|
let table_name = self.parse_object_name()?;
|
||||||
|
|
||||||
Ok(Statement::ExplainTable {
|
Ok(Statement::ExplainTable {
|
||||||
describe_alias,
|
describe_alias,
|
||||||
table_name,
|
table_name,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Parse a query expression, i.e. a `SELECT` statement optionally
|
/// Parse a query expression, i.e. a `SELECT` statement optionally
|
||||||
/// preceded with some `WITH` CTE declarations and optionally followed
|
/// preceded with some `WITH` CTE declarations and optionally followed
|
||||||
|
@ -7134,4 +7137,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()
|
||||||
|
))
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue