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

Syntax error while parsing ALTER TABLE with multiple commands #39948

Open
save-my-heart opened this issue Aug 7, 2022 · 1 comment
Open

Syntax error while parsing ALTER TABLE with multiple commands #39948

save-my-heart opened this issue Aug 7, 2022 · 1 comment

Comments

@save-my-heart
Copy link
Contributor

Describe what's wrong

Parser throw syntax error while parsing ALTER TABLE query with MODIFY TTL and other commands.

Does it reproduce on recent release?

Yes, almost all releases have this problem.

How to reproduce

When we type such a sql, it causes syntax error.

> ALTER TABLE t MODIFY TTL d + toIntervalDay(1), ADD COLUMN c Date

Syntax error: failed at position 50 ('column'):

alter table t modify ttl d + interval 1 day, add column c Date;

Expected one of: token, Comma, Arrow, Dot, UUID, DoubleColon, MOD, DIV, NOT, BETWEEN, LIKE, ILIKE, NOT LIKE, NOT ILIKE, IN, NOT IN, GLOBAL IN, GLOBAL NOT IN, IS, AND, OR, QuestionMark, INTO OUTFILE, FORMAT, SETTINGS, end of query

But, if we put the MOFITY TTL element to the last, everything is ok.

> ALTER TABLE t ADD COLUMN c Date, MODIFY TTL d + toIntervalDay(1)

ALTER TABLE t
    ADD COLUMN `c` Date,
    MODIFY TTL d + toIntervalDay(1)

Query id: 7124ca11-3e98-4324-b3e7-399cc99ee010


0 rows in set. Elapsed: 0.004 sec.

Both AlterCommandList and TTLExpressionList are separate by COMMA , which may cause ambiguous behavior.

@save-my-heart save-my-heart added the potential bug To be reviewed by developers and confirmed/rejected. label Aug 7, 2022
@save-my-heart
Copy link
Contributor Author

Related code:

bool ParserAlterCommandList::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
{
auto command_list = std::make_shared<ASTExpressionList>();
node = command_list;
ParserToken s_comma(TokenType::Comma);
ParserAlterCommand p_command(alter_object);
do
{
ASTPtr command;
if (!p_command.parse(pos, command, expected))
return false;
command_list->children.push_back(command);
}
while (s_comma.ignore(pos, expected));
return true;
}

bool ParserTTLExpressionList::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
{
return ParserList(std::make_unique<ParserTTLElement>(), std::make_unique<ParserToken>(TokenType::Comma), false)
.parse(pos, node, expected);
}

@den-crane den-crane added unfinished code and removed potential bug To be reviewed by developers and confirmed/rejected. labels Aug 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants