change parser

This commit is contained in:
Han Fei 2024-09-17 19:12:58 +00:00
parent ec2446adfd
commit dcaa80c90d
5 changed files with 12 additions and 7 deletions

View File

@ -121,10 +121,7 @@ private:
{
if (select.recursive_with)
for (const auto & child : select.with()->children)
{
if (typeid_cast<ASTWithElement *>(child.get()))
with_aliases.insert(child->as<ASTWithElement>()->name);
}
with_aliases.insert(child->as<ASTWithElement>()->name);
if (select.tables())
tryVisit<ASTTablesInSelectQuery>(select.refTables());

View File

@ -106,7 +106,7 @@ bool ParserSelectQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
{
select_query->recursive_with = s_recursive.ignore(pos, expected);
if (!ParserList(std::make_unique<ParserWithElement>(), std::make_unique<ParserToken>(TokenType::Comma))
if (!ParserList(std::make_unique<ParserWithElement>(select_query->recursive_with), std::make_unique<ParserToken>(TokenType::Comma))
.parse(pos, with_expression_list, expected))
return false;
if (with_expression_list->children.empty())

View File

@ -26,6 +26,10 @@ bool ParserWithElement::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
with_element->children.push_back(with_element->subquery);
node = with_element;
}
else if (with_recursive)
{
return false;
}
else
{
pos = old_pos;

View File

@ -10,9 +10,14 @@ namespace DB
*/
class ParserWithElement : public IParserBase
{
public:
ParserWithElement(bool with_recursive_ = false) : with_recursive(with_recursive_) {}
protected:
const char * getName() const override { return "WITH element"; }
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
/// for `WITH RECURSIVE` CTE, we don't allow expression with alias.
bool with_recursive;
};
}

View File

@ -1,3 +1,2 @@
drop table if exists t;
create view t AS (WITH RECURSIVE 42 as ttt SELECT ttt);
drop table t;
create view t AS (WITH RECURSIVE 42 as ttt SELECT ttt) -- { clientError SYNTAX_ERROR };