ClickHouse/src/Parsers/MySQL/ASTDeclareConstraint.cpp
Ivan 1d170f5745
ASTTableIdentifier Part #1: improve internal representation of ASTIdentifier name (#16149)
* Use only |name_parts| as primary name source

* Restore legacy logic for table restoration

* Fix build

* Fix tests

* Add pytest server config

* Fix tests

* Fixes due to review
2020-10-24 21:46:10 +03:00

75 lines
1.8 KiB
C++

#include <Parsers/MySQL/ASTDeclareConstraint.h>
#include <Parsers/ASTIdentifier.h>
#include <Parsers/CommonParsers.h>
#include <Parsers/ExpressionElementParsers.h>
#include <Parsers/ExpressionListParsers.h>
namespace DB
{
namespace MySQLParser
{
ASTPtr ASTDeclareConstraint::clone() const
{
auto res = std::make_shared<ASTDeclareConstraint>(*this);
res->children.clear();
if (check_expression)
{
res->check_expression = check_expression->clone();
res->children.emplace_back(res->check_expression);
}
return res;
}
bool ParserDeclareConstraint::parseImpl(IParser::Pos & pos, ASTPtr & node, Expected & expected)
{
bool enforced = true;
ASTPtr constraint_symbol;
ASTPtr index_check_expression;
ParserExpression p_expression;
if (ParserKeyword("CONSTRAINT").ignore(pos, expected))
{
if (!ParserKeyword("CHECK").checkWithoutMoving(pos, expected))
ParserIdentifier().parse(pos, constraint_symbol, expected);
}
if (!ParserKeyword("CHECK").ignore(pos, expected))
return false;
if (!p_expression.parse(pos, index_check_expression, expected))
return false;
if (ParserKeyword("NOT").ignore(pos, expected))
{
if (!ParserKeyword("ENFORCED").ignore(pos, expected))
return false;
enforced = false;
}
else
{
enforced = true;
ParserKeyword("ENFORCED").ignore(pos, expected);
}
auto declare_constraint = std::make_shared<ASTDeclareConstraint>();
declare_constraint->enforced = enforced;
declare_constraint->check_expression = index_check_expression;
if (constraint_symbol)
declare_constraint->constraint_name = constraint_symbol->as<ASTIdentifier>()->name();
node = declare_constraint;
return true;
}
}
}