ClickHouse/src/Parsers/ParserAlterQuery.cpp

907 lines
33 KiB
C++
Raw Normal View History

#include <Common/typeid_cast.h>
#include <Parsers/ParserAlterQuery.h>
#include <Parsers/CommonParsers.h>
#include <Parsers/ExpressionElementParsers.h>
#include <Parsers/ExpressionListParsers.h>
#include <Parsers/ParserCreateQuery.h>
#include <Parsers/ParserPartition.h>
#include <Parsers/ParserSelectWithUnionQuery.h>
2019-07-24 15:22:16 +00:00
#include <Parsers/ParserSetQuery.h>
#include <Parsers/ASTIdentifier.h>
Data Skipping Indices (#4143) * made index parser * added index parsing * some fixes * added index interface and factory * fixed compilation * ptrs * added indexParts * indextypes * index condition * IndexCondition * added indexes in selectexecutor * fix * changed comment * fix * added granularity * comments * fix * fix * added writing indexes * removed indexpart class * fix * added setSkipIndexes * add rw for MergeTreeIndexes * fixes * upd error * fix * fix * reading * test index * fixed nullptr error * fixed * fix * unique names * asts -> exprlist * minmax index * fix * fixed select * fixed merging * fixed mutation * working minmax * removed test index * fixed style * added indexes to checkDataPart * added tests for minmax index * fixed constructor * fix style * fixed includes * fixed setSkipIndexes * added indexes meta to zookeeper * added parsing * removed throw * alter cmds parse * fix * added alter * fix * alters fix * fix alters * fix "after" * fixed alter * alter fix + test * fixes * upd setSkipIndexes * fixed alter bug with drop all indices * fix metadata editing * new test and repl fix * rm test files * fixed repl alter * fix * fix * indices * MTReadStream * upd test for bug * fix * added useful parsers and ast classes * fix * fix comments * replaced columns * fix * fixed parsing * fixed printing * fix err * basic IndicesDescription * go to IndicesDescr * moved indices * go to indicesDescr * fix test minmax_index* * fixed MT alter * fixed bug with replMT indices storing in zk * rename * refactoring * docs ru * docs ru * docs en * refactor * rename tests * fix docs * refactoring * fix * fix * fix * fixed style * unique idx * unique * fix * better minmax calculation * upd * added getBlock * unique_condition * added termForAST * unique * fixed not * uniqueCondition::mayBeTrueOnGranule * fix * fixed bug with double column * is always true * fix * key set * spaces * test * tests * fix * unique * fix * fix * fixed bug with duplicate column * removed unused data * fix * fixes * __bitSwapLastTwo * fix
2019-02-05 14:50:25 +00:00
#include <Parsers/ASTIndexDeclaration.h>
#include <Parsers/ASTAlterQuery.h>
#include <Parsers/ASTLiteral.h>
#include <Parsers/parseDatabaseAndTableName.h>
2013-08-07 13:07:42 +00:00
namespace DB
{
2016-01-28 01:00:27 +00:00
bool ParserAlterCommand::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
2013-08-07 13:07:42 +00:00
{
auto command = std::make_shared<ASTAlterCommand>();
node = command;
ParserKeyword s_add_column("ADD COLUMN");
ParserKeyword s_drop_column("DROP COLUMN");
ParserKeyword s_clear_column("CLEAR COLUMN");
ParserKeyword s_modify_column("MODIFY COLUMN");
ParserKeyword s_alter_column("ALTER COLUMN");
2020-03-25 18:44:08 +00:00
ParserKeyword s_rename_column("RENAME COLUMN");
ParserKeyword s_comment_column("COMMENT COLUMN");
2021-07-31 18:17:06 +00:00
ParserKeyword s_materialize_column("MATERIALIZE COLUMN");
ParserKeyword s_modify_order_by("MODIFY ORDER BY");
2020-08-27 13:10:10 +00:00
ParserKeyword s_modify_sample_by("MODIFY SAMPLE BY");
ParserKeyword s_modify_ttl("MODIFY TTL");
2020-01-22 13:24:20 +00:00
ParserKeyword s_materialize_ttl("MATERIALIZE TTL");
2019-07-24 15:22:16 +00:00
ParserKeyword s_modify_setting("MODIFY SETTING");
ParserKeyword s_reset_setting("RESET SETTING");
ParserKeyword s_modify_query("MODIFY QUERY");
Data Skipping Indices (#4143) * made index parser * added index parsing * some fixes * added index interface and factory * fixed compilation * ptrs * added indexParts * indextypes * index condition * IndexCondition * added indexes in selectexecutor * fix * changed comment * fix * added granularity * comments * fix * fix * added writing indexes * removed indexpart class * fix * added setSkipIndexes * add rw for MergeTreeIndexes * fixes * upd error * fix * fix * reading * test index * fixed nullptr error * fixed * fix * unique names * asts -> exprlist * minmax index * fix * fixed select * fixed merging * fixed mutation * working minmax * removed test index * fixed style * added indexes to checkDataPart * added tests for minmax index * fixed constructor * fix style * fixed includes * fixed setSkipIndexes * added indexes meta to zookeeper * added parsing * removed throw * alter cmds parse * fix * added alter * fix * alters fix * fix alters * fix "after" * fixed alter * alter fix + test * fixes * upd setSkipIndexes * fixed alter bug with drop all indices * fix metadata editing * new test and repl fix * rm test files * fixed repl alter * fix * fix * indices * MTReadStream * upd test for bug * fix * added useful parsers and ast classes * fix * fix comments * replaced columns * fix * fixed parsing * fixed printing * fix err * basic IndicesDescription * go to IndicesDescr * moved indices * go to indicesDescr * fix test minmax_index* * fixed MT alter * fixed bug with replMT indices storing in zk * rename * refactoring * docs ru * docs ru * docs en * refactor * rename tests * fix docs * refactoring * fix * fix * fix * fixed style * unique idx * unique * fix * better minmax calculation * upd * added getBlock * unique_condition * added termForAST * unique * fixed not * uniqueCondition::mayBeTrueOnGranule * fix * fixed bug with double column * is always true * fix * key set * spaces * test * tests * fix * unique * fix * fix * fixed bug with duplicate column * removed unused data * fix * fixes * __bitSwapLastTwo * fix
2019-02-05 14:50:25 +00:00
ParserKeyword s_add_index("ADD INDEX");
ParserKeyword s_drop_index("DROP INDEX");
2019-05-09 14:25:18 +00:00
ParserKeyword s_clear_index("CLEAR INDEX");
2019-04-09 15:36:33 +00:00
ParserKeyword s_materialize_index("MATERIALIZE INDEX");
Data Skipping Indices (#4143) * made index parser * added index parsing * some fixes * added index interface and factory * fixed compilation * ptrs * added indexParts * indextypes * index condition * IndexCondition * added indexes in selectexecutor * fix * changed comment * fix * added granularity * comments * fix * fix * added writing indexes * removed indexpart class * fix * added setSkipIndexes * add rw for MergeTreeIndexes * fixes * upd error * fix * fix * reading * test index * fixed nullptr error * fixed * fix * unique names * asts -> exprlist * minmax index * fix * fixed select * fixed merging * fixed mutation * working minmax * removed test index * fixed style * added indexes to checkDataPart * added tests for minmax index * fixed constructor * fix style * fixed includes * fixed setSkipIndexes * added indexes meta to zookeeper * added parsing * removed throw * alter cmds parse * fix * added alter * fix * alters fix * fix alters * fix "after" * fixed alter * alter fix + test * fixes * upd setSkipIndexes * fixed alter bug with drop all indices * fix metadata editing * new test and repl fix * rm test files * fixed repl alter * fix * fix * indices * MTReadStream * upd test for bug * fix * added useful parsers and ast classes * fix * fix comments * replaced columns * fix * fixed parsing * fixed printing * fix err * basic IndicesDescription * go to IndicesDescr * moved indices * go to indicesDescr * fix test minmax_index* * fixed MT alter * fixed bug with replMT indices storing in zk * rename * refactoring * docs ru * docs ru * docs en * refactor * rename tests * fix docs * refactoring * fix * fix * fix * fixed style * unique idx * unique * fix * better minmax calculation * upd * added getBlock * unique_condition * added termForAST * unique * fixed not * uniqueCondition::mayBeTrueOnGranule * fix * fixed bug with double column * is always true * fix * key set * spaces * test * tests * fix * unique * fix * fix * fixed bug with duplicate column * removed unused data * fix * fixes * __bitSwapLastTwo * fix
2019-02-05 14:50:25 +00:00
ParserKeyword s_add_constraint("ADD CONSTRAINT");
ParserKeyword s_drop_constraint("DROP CONSTRAINT");
ParserKeyword s_add_projection("ADD PROJECTION");
ParserKeyword s_drop_projection("DROP PROJECTION");
ParserKeyword s_clear_projection("CLEAR PROJECTION");
ParserKeyword s_materialize_projection("MATERIALIZE PROJECTION");
ParserKeyword s_modify_comment("MODIFY COMMENT");
ParserKeyword s_add("ADD");
ParserKeyword s_drop("DROP");
ParserKeyword s_suspend("SUSPEND");
ParserKeyword s_resume("RESUME");
ParserKeyword s_refresh("REFRESH");
ParserKeyword s_modify("MODIFY");
Data Skipping Indices (#4143) * made index parser * added index parsing * some fixes * added index interface and factory * fixed compilation * ptrs * added indexParts * indextypes * index condition * IndexCondition * added indexes in selectexecutor * fix * changed comment * fix * added granularity * comments * fix * fix * added writing indexes * removed indexpart class * fix * added setSkipIndexes * add rw for MergeTreeIndexes * fixes * upd error * fix * fix * reading * test index * fixed nullptr error * fixed * fix * unique names * asts -> exprlist * minmax index * fix * fixed select * fixed merging * fixed mutation * working minmax * removed test index * fixed style * added indexes to checkDataPart * added tests for minmax index * fixed constructor * fix style * fixed includes * fixed setSkipIndexes * added indexes meta to zookeeper * added parsing * removed throw * alter cmds parse * fix * added alter * fix * alters fix * fix alters * fix "after" * fixed alter * alter fix + test * fixes * upd setSkipIndexes * fixed alter bug with drop all indices * fix metadata editing * new test and repl fix * rm test files * fixed repl alter * fix * fix * indices * MTReadStream * upd test for bug * fix * added useful parsers and ast classes * fix * fix comments * replaced columns * fix * fixed parsing * fixed printing * fix err * basic IndicesDescription * go to IndicesDescr * moved indices * go to indicesDescr * fix test minmax_index* * fixed MT alter * fixed bug with replMT indices storing in zk * rename * refactoring * docs ru * docs ru * docs en * refactor * rename tests * fix docs * refactoring * fix * fix * fix * fixed style * unique idx * unique * fix * better minmax calculation * upd * added getBlock * unique_condition * added termForAST * unique * fixed not * uniqueCondition::mayBeTrueOnGranule * fix * fixed bug with double column * is always true * fix * key set * spaces * test * tests * fix * unique * fix * fix * fixed bug with duplicate column * removed unused data * fix * fixes * __bitSwapLastTwo * fix
2019-02-05 14:50:25 +00:00
ParserKeyword s_attach_partition("ATTACH PARTITION");
ParserKeyword s_attach_part("ATTACH PART");
ParserKeyword s_detach_partition("DETACH PARTITION");
ParserKeyword s_detach_part("DETACH PART");
ParserKeyword s_drop_partition("DROP PARTITION");
ParserKeyword s_drop_part("DROP PART");
2019-08-20 09:59:19 +00:00
ParserKeyword s_move_partition("MOVE PARTITION");
ParserKeyword s_move_part("MOVE PART");
2019-07-22 11:23:11 +00:00
ParserKeyword s_drop_detached_partition("DROP DETACHED PARTITION");
ParserKeyword s_drop_detached_part("DROP DETACHED PART");
ParserKeyword s_fetch_partition("FETCH PARTITION");
ParserKeyword s_fetch_part("FETCH PART");
ParserKeyword s_replace_partition("REPLACE PARTITION");
ParserKeyword s_freeze("FREEZE");
2021-02-24 14:26:46 +00:00
ParserKeyword s_unfreeze("UNFREEZE");
ParserKeyword s_partition("PARTITION");
ParserKeyword s_first("FIRST");
ParserKeyword s_after("AFTER");
ParserKeyword s_if_not_exists("IF NOT EXISTS");
ParserKeyword s_if_exists("IF EXISTS");
ParserKeyword s_from("FROM");
ParserKeyword s_in_partition("IN PARTITION");
ParserKeyword s_with("WITH");
ParserKeyword s_name("NAME");
2019-07-18 15:19:03 +00:00
ParserKeyword s_to_disk("TO DISK");
ParserKeyword s_to_volume("TO VOLUME");
ParserKeyword s_to_table("TO TABLE");
ParserKeyword s_to_shard("TO SHARD");
2019-07-18 15:19:03 +00:00
ParserKeyword s_delete("DELETE");
ParserKeyword s_update("UPDATE");
ParserKeyword s_where("WHERE");
2020-03-25 18:44:08 +00:00
ParserKeyword s_to("TO");
ParserKeyword s_remove("REMOVE");
ParserKeyword s_default("DEFAULT");
ParserKeyword s_materialized("MATERIALIZED");
ParserKeyword s_alias("ALIAS");
ParserKeyword s_comment("COMMENT");
ParserKeyword s_codec("CODEC");
ParserKeyword s_ttl("TTL");
ParserKeyword s_remove_ttl("REMOVE TTL");
2021-10-14 13:44:28 +00:00
ParserKeyword s_remove_sample_by("REMOVE SAMPLE BY");
ParserCompoundIdentifier parser_name;
ParserStringLiteral parser_string_literal;
ParserIdentifier parser_remove_property;
ParserCompoundColumnDeclaration parser_col_decl;
Data Skipping Indices (#4143) * made index parser * added index parsing * some fixes * added index interface and factory * fixed compilation * ptrs * added indexParts * indextypes * index condition * IndexCondition * added indexes in selectexecutor * fix * changed comment * fix * added granularity * comments * fix * fix * added writing indexes * removed indexpart class * fix * added setSkipIndexes * add rw for MergeTreeIndexes * fixes * upd error * fix * fix * reading * test index * fixed nullptr error * fixed * fix * unique names * asts -> exprlist * minmax index * fix * fixed select * fixed merging * fixed mutation * working minmax * removed test index * fixed style * added indexes to checkDataPart * added tests for minmax index * fixed constructor * fix style * fixed includes * fixed setSkipIndexes * added indexes meta to zookeeper * added parsing * removed throw * alter cmds parse * fix * added alter * fix * alters fix * fix alters * fix "after" * fixed alter * alter fix + test * fixes * upd setSkipIndexes * fixed alter bug with drop all indices * fix metadata editing * new test and repl fix * rm test files * fixed repl alter * fix * fix * indices * MTReadStream * upd test for bug * fix * added useful parsers and ast classes * fix * fix comments * replaced columns * fix * fixed parsing * fixed printing * fix err * basic IndicesDescription * go to IndicesDescr * moved indices * go to indicesDescr * fix test minmax_index* * fixed MT alter * fixed bug with replMT indices storing in zk * rename * refactoring * docs ru * docs ru * docs en * refactor * rename tests * fix docs * refactoring * fix * fix * fix * fixed style * unique idx * unique * fix * better minmax calculation * upd * added getBlock * unique_condition * added termForAST * unique * fixed not * uniqueCondition::mayBeTrueOnGranule * fix * fixed bug with double column * is always true * fix * key set * spaces * test * tests * fix * unique * fix * fix * fixed bug with duplicate column * removed unused data * fix * fixes * __bitSwapLastTwo * fix
2019-02-05 14:50:25 +00:00
ParserIndexDeclaration parser_idx_decl;
ParserConstraintDeclaration parser_constraint_decl;
ParserProjectionDeclaration parser_projection_decl;
ParserCompoundColumnDeclaration parser_modify_col_decl(false, false, true);
ParserPartition parser_partition;
ParserExpression parser_exp_elem;
ParserList parser_assignment_list(
std::make_unique<ParserAssignment>(), std::make_unique<ParserToken>(TokenType::Comma),
/* allow_empty = */ false);
2019-07-24 15:22:16 +00:00
ParserSetQuery parser_settings(true);
ParserList parser_reset_setting(
std::make_unique<ParserIdentifier>(), std::make_unique<ParserToken>(TokenType::Comma),
/* allow_empty = */ false);
ParserNameList values_p;
ParserSelectWithUnionQuery select_p;
2019-10-09 13:02:05 +00:00
ParserTTLExpressionList parser_ttl_list;
2021-08-20 17:59:57 +00:00
switch (alter_object)
{
2021-08-20 17:59:57 +00:00
case ASTAlterQuery::AlterObjectType::LIVE_VIEW:
{
2021-08-20 17:59:57 +00:00
if (s_refresh.ignore(pos, expected))
{
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::LIVE_VIEW_REFRESH;
}
2021-08-20 17:59:57 +00:00
else
2020-03-25 18:44:08 +00:00
return false;
2021-08-20 17:59:57 +00:00
break;
2020-03-25 18:44:08 +00:00
}
2021-08-20 17:59:57 +00:00
case ASTAlterQuery::AlterObjectType::DATABASE:
2021-07-31 18:17:06 +00:00
{
2021-08-20 17:59:57 +00:00
if (s_modify_setting.ignore(pos, expected))
2021-07-31 18:17:06 +00:00
{
2021-08-20 17:59:57 +00:00
if (!parser_settings.parse(pos, command->settings_changes, expected))
2021-07-31 18:17:06 +00:00
return false;
2021-08-27 06:30:21 +00:00
command->type = ASTAlterCommand::MODIFY_DATABASE_SETTING;
2021-07-31 18:17:06 +00:00
}
2021-08-20 17:59:57 +00:00
else
2019-05-09 14:25:18 +00:00
return false;
2021-08-20 17:59:57 +00:00
break;
2019-05-09 14:25:18 +00:00
}
2021-08-27 06:30:21 +00:00
default:
break;
2021-08-20 17:59:57 +00:00
case ASTAlterQuery::AlterObjectType::TABLE:
{
2021-08-20 17:59:57 +00:00
if (s_add_column.ignore(pos, expected))
{
if (s_if_not_exists.ignore(pos, expected))
command->if_not_exists = true;
2021-08-20 17:59:57 +00:00
if (!parser_col_decl.parse(pos, command->col_decl, expected))
return false;
2021-08-20 17:59:57 +00:00
if (s_first.ignore(pos, expected))
command->first = true;
else if (s_after.ignore(pos, expected))
{
if (!parser_name.parse(pos, command->column, expected))
return false;
}
Data Skipping Indices (#4143) * made index parser * added index parsing * some fixes * added index interface and factory * fixed compilation * ptrs * added indexParts * indextypes * index condition * IndexCondition * added indexes in selectexecutor * fix * changed comment * fix * added granularity * comments * fix * fix * added writing indexes * removed indexpart class * fix * added setSkipIndexes * add rw for MergeTreeIndexes * fixes * upd error * fix * fix * reading * test index * fixed nullptr error * fixed * fix * unique names * asts -> exprlist * minmax index * fix * fixed select * fixed merging * fixed mutation * working minmax * removed test index * fixed style * added indexes to checkDataPart * added tests for minmax index * fixed constructor * fix style * fixed includes * fixed setSkipIndexes * added indexes meta to zookeeper * added parsing * removed throw * alter cmds parse * fix * added alter * fix * alters fix * fix alters * fix "after" * fixed alter * alter fix + test * fixes * upd setSkipIndexes * fixed alter bug with drop all indices * fix metadata editing * new test and repl fix * rm test files * fixed repl alter * fix * fix * indices * MTReadStream * upd test for bug * fix * added useful parsers and ast classes * fix * fix comments * replaced columns * fix * fixed parsing * fixed printing * fix err * basic IndicesDescription * go to IndicesDescr * moved indices * go to indicesDescr * fix test minmax_index* * fixed MT alter * fixed bug with replMT indices storing in zk * rename * refactoring * docs ru * docs ru * docs en * refactor * rename tests * fix docs * refactoring * fix * fix * fix * fixed style * unique idx * unique * fix * better minmax calculation * upd * added getBlock * unique_condition * added termForAST * unique * fixed not * uniqueCondition::mayBeTrueOnGranule * fix * fixed bug with double column * is always true * fix * key set * spaces * test * tests * fix * unique * fix * fix * fixed bug with duplicate column * removed unused data * fix * fixes * __bitSwapLastTwo * fix
2019-02-05 14:50:25 +00:00
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::ADD_COLUMN;
}
else if (s_rename_column.ignore(pos, expected))
{
if (s_if_exists.ignore(pos, expected))
command->if_exists = true;
Data Skipping Indices (#4143) * made index parser * added index parsing * some fixes * added index interface and factory * fixed compilation * ptrs * added indexParts * indextypes * index condition * IndexCondition * added indexes in selectexecutor * fix * changed comment * fix * added granularity * comments * fix * fix * added writing indexes * removed indexpart class * fix * added setSkipIndexes * add rw for MergeTreeIndexes * fixes * upd error * fix * fix * reading * test index * fixed nullptr error * fixed * fix * unique names * asts -> exprlist * minmax index * fix * fixed select * fixed merging * fixed mutation * working minmax * removed test index * fixed style * added indexes to checkDataPart * added tests for minmax index * fixed constructor * fix style * fixed includes * fixed setSkipIndexes * added indexes meta to zookeeper * added parsing * removed throw * alter cmds parse * fix * added alter * fix * alters fix * fix alters * fix "after" * fixed alter * alter fix + test * fixes * upd setSkipIndexes * fixed alter bug with drop all indices * fix metadata editing * new test and repl fix * rm test files * fixed repl alter * fix * fix * indices * MTReadStream * upd test for bug * fix * added useful parsers and ast classes * fix * fix comments * replaced columns * fix * fixed parsing * fixed printing * fix err * basic IndicesDescription * go to IndicesDescr * moved indices * go to indicesDescr * fix test minmax_index* * fixed MT alter * fixed bug with replMT indices storing in zk * rename * refactoring * docs ru * docs ru * docs en * refactor * rename tests * fix docs * refactoring * fix * fix * fix * fixed style * unique idx * unique * fix * better minmax calculation * upd * added getBlock * unique_condition * added termForAST * unique * fixed not * uniqueCondition::mayBeTrueOnGranule * fix * fixed bug with double column * is always true * fix * key set * spaces * test * tests * fix * unique * fix * fix * fixed bug with duplicate column * removed unused data * fix * fixes * __bitSwapLastTwo * fix
2019-02-05 14:50:25 +00:00
2021-08-20 17:59:57 +00:00
if (!parser_name.parse(pos, command->column, expected))
return false;
Data Skipping Indices (#4143) * made index parser * added index parsing * some fixes * added index interface and factory * fixed compilation * ptrs * added indexParts * indextypes * index condition * IndexCondition * added indexes in selectexecutor * fix * changed comment * fix * added granularity * comments * fix * fix * added writing indexes * removed indexpart class * fix * added setSkipIndexes * add rw for MergeTreeIndexes * fixes * upd error * fix * fix * reading * test index * fixed nullptr error * fixed * fix * unique names * asts -> exprlist * minmax index * fix * fixed select * fixed merging * fixed mutation * working minmax * removed test index * fixed style * added indexes to checkDataPart * added tests for minmax index * fixed constructor * fix style * fixed includes * fixed setSkipIndexes * added indexes meta to zookeeper * added parsing * removed throw * alter cmds parse * fix * added alter * fix * alters fix * fix alters * fix "after" * fixed alter * alter fix + test * fixes * upd setSkipIndexes * fixed alter bug with drop all indices * fix metadata editing * new test and repl fix * rm test files * fixed repl alter * fix * fix * indices * MTReadStream * upd test for bug * fix * added useful parsers and ast classes * fix * fix comments * replaced columns * fix * fixed parsing * fixed printing * fix err * basic IndicesDescription * go to IndicesDescr * moved indices * go to indicesDescr * fix test minmax_index* * fixed MT alter * fixed bug with replMT indices storing in zk * rename * refactoring * docs ru * docs ru * docs en * refactor * rename tests * fix docs * refactoring * fix * fix * fix * fixed style * unique idx * unique * fix * better minmax calculation * upd * added getBlock * unique_condition * added termForAST * unique * fixed not * uniqueCondition::mayBeTrueOnGranule * fix * fixed bug with double column * is always true * fix * key set * spaces * test * tests * fix * unique * fix * fix * fixed bug with duplicate column * removed unused data * fix * fixes * __bitSwapLastTwo * fix
2019-02-05 14:50:25 +00:00
2021-08-20 17:59:57 +00:00
if (!s_to.ignore(pos, expected))
return false;
2021-08-20 17:59:57 +00:00
if (!parser_name.parse(pos, command->rename_to, expected))
return false;
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::RENAME_COLUMN;
}
2021-09-04 22:59:44 +00:00
else if (s_materialize_column.ignore(pos, expected))
{
if (!parser_name.parse(pos, command->column, expected))
return false;
2021-09-04 22:59:44 +00:00
command->type = ASTAlterCommand::MATERIALIZE_COLUMN;
command->detach = false;
2021-09-04 22:59:44 +00:00
if (s_in_partition.ignore(pos, expected))
{
if (!parser_partition.parse(pos, command->partition, expected))
return false;
}
}
2021-08-20 17:59:57 +00:00
else if (s_drop_partition.ignore(pos, expected))
2019-08-16 10:55:40 +00:00
{
if (!parser_partition.parse(pos, command->partition, expected))
return false;
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::DROP_PARTITION;
2019-08-16 10:55:40 +00:00
}
2021-08-20 17:59:57 +00:00
else if (s_drop_part.ignore(pos, expected))
{
if (!parser_string_literal.parse(pos, command->partition, expected))
return false;
Data Skipping Indices (#4143) * made index parser * added index parsing * some fixes * added index interface and factory * fixed compilation * ptrs * added indexParts * indextypes * index condition * IndexCondition * added indexes in selectexecutor * fix * changed comment * fix * added granularity * comments * fix * fix * added writing indexes * removed indexpart class * fix * added setSkipIndexes * add rw for MergeTreeIndexes * fixes * upd error * fix * fix * reading * test index * fixed nullptr error * fixed * fix * unique names * asts -> exprlist * minmax index * fix * fixed select * fixed merging * fixed mutation * working minmax * removed test index * fixed style * added indexes to checkDataPart * added tests for minmax index * fixed constructor * fix style * fixed includes * fixed setSkipIndexes * added indexes meta to zookeeper * added parsing * removed throw * alter cmds parse * fix * added alter * fix * alters fix * fix alters * fix "after" * fixed alter * alter fix + test * fixes * upd setSkipIndexes * fixed alter bug with drop all indices * fix metadata editing * new test and repl fix * rm test files * fixed repl alter * fix * fix * indices * MTReadStream * upd test for bug * fix * added useful parsers and ast classes * fix * fix comments * replaced columns * fix * fixed parsing * fixed printing * fix err * basic IndicesDescription * go to IndicesDescr * moved indices * go to indicesDescr * fix test minmax_index* * fixed MT alter * fixed bug with replMT indices storing in zk * rename * refactoring * docs ru * docs ru * docs en * refactor * rename tests * fix docs * refactoring * fix * fix * fix * fixed style * unique idx * unique * fix * better minmax calculation * upd * added getBlock * unique_condition * added termForAST * unique * fixed not * uniqueCondition::mayBeTrueOnGranule * fix * fixed bug with double column * is always true * fix * key set * spaces * test * tests * fix * unique * fix * fix * fixed bug with duplicate column * removed unused data * fix * fixes * __bitSwapLastTwo * fix
2019-02-05 14:50:25 +00:00
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::DROP_PARTITION;
command->part = true;
}
else if (s_drop_detached_partition.ignore(pos, expected))
2019-08-16 10:55:40 +00:00
{
if (!parser_partition.parse(pos, command->partition, expected))
return false;
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::DROP_DETACHED_PARTITION;
}
else if (s_drop_detached_part.ignore(pos, expected))
{
2021-08-20 17:59:57 +00:00
if (!parser_string_literal.parse(pos, command->partition, expected))
return false;
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::DROP_DETACHED_PARTITION;
command->part = true;
}
2021-08-20 17:59:57 +00:00
else if (s_drop_column.ignore(pos, expected))
{
2021-08-20 17:59:57 +00:00
if (s_if_exists.ignore(pos, expected))
command->if_exists = true;
2021-08-20 17:59:57 +00:00
if (!parser_name.parse(pos, command->column, expected))
return false;
2019-04-09 15:36:33 +00:00
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::DROP_COLUMN;
command->detach = false;
}
2021-08-20 17:59:57 +00:00
else if (s_clear_column.ignore(pos, expected))
{
if (s_if_exists.ignore(pos, expected))
command->if_exists = true;
2021-08-20 17:59:57 +00:00
if (!parser_name.parse(pos, command->column, expected))
return false;
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::DROP_COLUMN;
command->clear_column = true;
command->detach = false;
2021-08-20 17:59:57 +00:00
if (s_in_partition.ignore(pos, expected))
{
if (!parser_partition.parse(pos, command->partition, expected))
return false;
}
}
else if (s_add_index.ignore(pos, expected))
{
if (s_if_not_exists.ignore(pos, expected))
command->if_not_exists = true;
2021-08-20 17:59:57 +00:00
if (!parser_idx_decl.parse(pos, command->index_decl, expected))
return false;
2021-08-20 17:59:57 +00:00
if (s_first.ignore(pos, expected))
command->first = true;
else if (s_after.ignore(pos, expected))
{
if (!parser_name.parse(pos, command->index, expected))
return false;
}
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::ADD_INDEX;
}
else if (s_drop_index.ignore(pos, expected))
{
2021-08-20 17:59:57 +00:00
if (s_if_exists.ignore(pos, expected))
command->if_exists = true;
if (!parser_name.parse(pos, command->index, expected))
return false;
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::DROP_INDEX;
command->detach = false;
}
2021-08-20 17:59:57 +00:00
else if (s_clear_index.ignore(pos, expected))
{
if (s_if_exists.ignore(pos, expected))
command->if_exists = true;
2021-08-20 17:59:57 +00:00
if (!parser_name.parse(pos, command->index, expected))
return false;
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::DROP_INDEX;
command->clear_index = true;
command->detach = false;
2021-08-20 17:59:57 +00:00
if (s_in_partition.ignore(pos, expected))
{
if (!parser_partition.parse(pos, command->partition, expected))
return false;
}
}
else if (s_materialize_index.ignore(pos, expected))
{
2021-08-20 17:59:57 +00:00
if (s_if_exists.ignore(pos, expected))
command->if_exists = true;
if (!parser_name.parse(pos, command->index, expected))
return false;
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::MATERIALIZE_INDEX;
command->detach = false;
if (s_in_partition.ignore(pos, expected))
{
if (!parser_partition.parse(pos, command->partition, expected))
return false;
}
}
2021-08-20 17:59:57 +00:00
else if (s_add_projection.ignore(pos, expected))
{
if (s_if_not_exists.ignore(pos, expected))
command->if_not_exists = true;
2021-08-20 17:59:57 +00:00
if (!parser_projection_decl.parse(pos, command->projection_decl, expected))
return false;
2021-08-20 17:59:57 +00:00
if (s_first.ignore(pos, expected))
command->first = true;
else if (s_after.ignore(pos, expected))
{
if (!parser_name.parse(pos, command->projection, expected))
return false;
}
command->type = ASTAlterCommand::ADD_PROJECTION;
}
else if (s_drop_projection.ignore(pos, expected))
{
2021-08-20 17:59:57 +00:00
if (s_if_exists.ignore(pos, expected))
command->if_exists = true;
if (!parser_name.parse(pos, command->projection, expected))
return false;
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::DROP_PROJECTION;
command->detach = false;
}
2021-08-20 17:59:57 +00:00
else if (s_clear_projection.ignore(pos, expected))
{
if (s_if_exists.ignore(pos, expected))
command->if_exists = true;
2021-08-20 17:59:57 +00:00
if (!parser_name.parse(pos, command->projection, expected))
return false;
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::DROP_PROJECTION;
command->clear_projection = true;
command->detach = false;
2021-08-20 17:59:57 +00:00
if (s_in_partition.ignore(pos, expected))
{
if (!parser_partition.parse(pos, command->partition, expected))
return false;
}
}
else if (s_materialize_projection.ignore(pos, expected))
{
if (s_if_exists.ignore(pos, expected))
command->if_exists = true;
2021-08-20 17:59:57 +00:00
if (!parser_name.parse(pos, command->projection, expected))
return false;
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::MATERIALIZE_PROJECTION;
command->detach = false;
2021-08-20 17:59:57 +00:00
if (s_in_partition.ignore(pos, expected))
{
if (!parser_partition.parse(pos, command->partition, expected))
return false;
}
}
else if (s_move_part.ignore(pos, expected))
{
2021-08-20 17:59:57 +00:00
if (!parser_string_literal.parse(pos, command->partition, expected))
return false;
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::MOVE_PARTITION;
command->part = true;
2021-08-20 17:59:57 +00:00
if (s_to_disk.ignore(pos))
command->move_destination_type = DataDestinationType::DISK;
else if (s_to_volume.ignore(pos))
command->move_destination_type = DataDestinationType::VOLUME;
else if (s_to_table.ignore(pos))
{
if (!parseDatabaseAndTableName(pos, expected, command->to_database, command->to_table))
return false;
command->move_destination_type = DataDestinationType::TABLE;
}
else if (s_to_shard.ignore(pos))
{
command->move_destination_type = DataDestinationType::SHARD;
}
else
return false;
if (command->move_destination_type != DataDestinationType::TABLE)
{
ASTPtr ast_space_name;
if (!parser_string_literal.parse(pos, ast_space_name, expected))
return false;
2021-08-20 17:59:57 +00:00
command->move_destination_name = ast_space_name->as<ASTLiteral &>().value.get<const String &>();
}
}
else if (s_move_partition.ignore(pos, expected))
{
if (!parser_partition.parse(pos, command->partition, expected))
return false;
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::MOVE_PARTITION;
2019-08-20 09:59:19 +00:00
2021-08-20 17:59:57 +00:00
if (s_to_disk.ignore(pos))
command->move_destination_type = DataDestinationType::DISK;
else if (s_to_volume.ignore(pos))
command->move_destination_type = DataDestinationType::VOLUME;
else if (s_to_table.ignore(pos))
{
if (!parseDatabaseAndTableName(pos, expected, command->to_database, command->to_table))
return false;
command->move_destination_type = DataDestinationType::TABLE;
}
else
return false;
2021-08-20 17:59:57 +00:00
if (command->move_destination_type != DataDestinationType::TABLE)
{
ASTPtr ast_space_name;
if (!parser_string_literal.parse(pos, ast_space_name, expected))
return false;
command->move_destination_name = ast_space_name->as<ASTLiteral &>().value.get<const String &>();
}
}
2021-08-20 17:59:57 +00:00
else if (s_add_constraint.ignore(pos, expected))
{
2021-08-20 17:59:57 +00:00
if (s_if_not_exists.ignore(pos, expected))
command->if_not_exists = true;
2021-08-20 17:59:57 +00:00
if (!parser_constraint_decl.parse(pos, command->constraint_decl, expected))
2019-09-16 07:27:38 +00:00
return false;
2019-07-18 15:19:03 +00:00
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::ADD_CONSTRAINT;
2019-09-16 07:27:38 +00:00
}
2021-08-20 17:59:57 +00:00
else if (s_drop_constraint.ignore(pos, expected))
{
if (s_if_exists.ignore(pos, expected))
command->if_exists = true;
2019-07-18 15:19:03 +00:00
2021-08-20 17:59:57 +00:00
if (!parser_name.parse(pos, command->constraint, expected))
return false;
2019-07-18 15:19:03 +00:00
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::DROP_CONSTRAINT;
command->detach = false;
}
else if (s_detach_partition.ignore(pos, expected))
2019-09-16 07:27:38 +00:00
{
2021-08-20 17:59:57 +00:00
if (!parser_partition.parse(pos, command->partition, expected))
return false;
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::DROP_PARTITION;
command->detach = true;
}
else if (s_detach_part.ignore(pos, expected))
2019-09-16 07:27:38 +00:00
{
2021-08-20 17:59:57 +00:00
if (!parser_string_literal.parse(pos, command->partition, expected))
2019-09-16 07:27:38 +00:00
return false;
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::DROP_PARTITION;
command->part = true;
command->detach = true;
2019-09-16 07:27:38 +00:00
}
2021-08-20 17:59:57 +00:00
else if (s_attach_partition.ignore(pos, expected))
{
if (!parser_partition.parse(pos, command->partition, expected))
return false;
2021-08-20 17:59:57 +00:00
if (s_from.ignore(pos))
{
if (!parseDatabaseAndTableName(pos, expected, command->from_database, command->from_table))
return false;
2021-08-20 17:59:57 +00:00
command->replace = false;
command->type = ASTAlterCommand::REPLACE_PARTITION;
}
else
{
command->type = ASTAlterCommand::ATTACH_PARTITION;
}
}
else if (s_replace_partition.ignore(pos, expected))
{
if (!parser_partition.parse(pos, command->partition, expected))
return false;
2021-08-20 17:59:57 +00:00
if (!s_from.ignore(pos, expected))
return false;
if (!parseDatabaseAndTableName(pos, expected, command->from_database, command->from_table))
return false;
2021-08-20 17:59:57 +00:00
command->replace = true;
command->type = ASTAlterCommand::REPLACE_PARTITION;
}
2021-08-20 17:59:57 +00:00
else if (s_attach_part.ignore(pos, expected))
{
2021-08-20 17:59:57 +00:00
if (!parser_string_literal.parse(pos, command->partition, expected))
return false;
command->part = true;
command->type = ASTAlterCommand::ATTACH_PARTITION;
}
2021-08-20 17:59:57 +00:00
else if (s_fetch_partition.ignore(pos, expected))
{
if (!parser_partition.parse(pos, command->partition, expected))
return false;
2014-08-07 11:46:01 +00:00
2021-08-20 17:59:57 +00:00
if (!s_from.ignore(pos, expected))
return false;
2021-08-20 17:59:57 +00:00
ASTPtr ast_from;
if (!parser_string_literal.parse(pos, ast_from, expected))
return false;
2021-08-20 17:59:57 +00:00
command->from = ast_from->as<ASTLiteral &>().value.get<const String &>();
command->type = ASTAlterCommand::FETCH_PARTITION;
}
else if (s_fetch_part.ignore(pos, expected))
{
if (!parser_string_literal.parse(pos, command->partition, expected))
return false;
2021-08-20 17:59:57 +00:00
if (!s_from.ignore(pos, expected))
return false;
2021-08-20 17:59:57 +00:00
ASTPtr ast_from;
if (!parser_string_literal.parse(pos, ast_from, expected))
return false;
command->from = ast_from->as<ASTLiteral &>().value.get<const String &>();
command->part = true;
command->type = ASTAlterCommand::FETCH_PARTITION;
}
else if (s_freeze.ignore(pos, expected))
{
if (s_partition.ignore(pos, expected))
{
if (!parser_partition.parse(pos, command->partition, expected))
return false;
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::FREEZE_PARTITION;
}
else
{
command->type = ASTAlterCommand::FREEZE_ALL;
}
2021-08-20 17:59:57 +00:00
/// WITH NAME 'name' - place local backup to directory with specified name
if (s_with.ignore(pos, expected))
{
if (!s_name.ignore(pos, expected))
return false;
2021-08-20 17:59:57 +00:00
ASTPtr ast_with_name;
if (!parser_string_literal.parse(pos, ast_with_name, expected))
return false;
2021-08-20 17:59:57 +00:00
command->with_name = ast_with_name->as<ASTLiteral &>().value.get<const String &>();
}
}
else if (s_unfreeze.ignore(pos, expected))
{
2021-08-20 17:59:57 +00:00
if (s_partition.ignore(pos, expected))
{
if (!parser_partition.parse(pos, command->partition, expected))
return false;
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::UNFREEZE_PARTITION;
}
else
{
command->type = ASTAlterCommand::UNFREEZE_ALL;
}
/// WITH NAME 'name' - remove local backup to directory with specified name
if (s_with.ignore(pos, expected))
{
if (!s_name.ignore(pos, expected))
return false;
ASTPtr ast_with_name;
if (!parser_string_literal.parse(pos, ast_with_name, expected))
return false;
command->with_name = ast_with_name->as<ASTLiteral &>().value.get<const String &>();
}
else
{
return false;
}
}
else if (bool is_modify = s_modify_column.ignore(pos, expected); is_modify || s_alter_column.ignore(pos, expected))
{
2021-08-20 17:59:57 +00:00
if (s_if_exists.ignore(pos, expected))
command->if_exists = true;
if (!is_modify)
parser_modify_col_decl.enableCheckTypeKeyword();
2021-08-20 17:59:57 +00:00
if (!parser_modify_col_decl.parse(pos, command->col_decl, expected))
return false;
2021-08-20 17:59:57 +00:00
if (s_remove.ignore(pos, expected))
{
if (s_default.ignore(pos, expected))
command->remove_property = "DEFAULT";
else if (s_materialized.ignore(pos, expected))
command->remove_property = "MATERIALIZED";
else if (s_alias.ignore(pos, expected))
command->remove_property = "ALIAS";
else if (s_comment.ignore(pos, expected))
command->remove_property = "COMMENT";
else if (s_codec.ignore(pos, expected))
command->remove_property = "CODEC";
else if (s_ttl.ignore(pos, expected))
command->remove_property = "TTL";
else
return false;
}
else
{
if (s_first.ignore(pos, expected))
command->first = true;
else if (s_after.ignore(pos, expected))
{
if (!parser_name.parse(pos, command->column, expected))
return false;
}
}
command->type = ASTAlterCommand::MODIFY_COLUMN;
}
else if (s_modify_order_by.ignore(pos, expected))
{
if (!parser_exp_elem.parse(pos, command->order_by, expected))
return false;
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::MODIFY_ORDER_BY;
}
2021-08-20 17:59:57 +00:00
else if (s_modify_sample_by.ignore(pos, expected))
2021-03-02 20:28:42 +00:00
{
2021-08-20 17:59:57 +00:00
if (!parser_exp_elem.parse(pos, command->sample_by, expected))
2021-03-02 20:28:42 +00:00
return false;
2021-02-24 14:26:46 +00:00
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::MODIFY_SAMPLE_BY;
2021-03-02 20:28:42 +00:00
}
2021-10-14 13:44:28 +00:00
else if (s_remove_sample_by.ignore(pos, expected))
{
command->type = ASTAlterCommand::REMOVE_SAMPLE_BY;
}
2021-08-20 17:59:57 +00:00
else if (s_delete.ignore(pos, expected))
2021-03-02 20:28:42 +00:00
{
2021-08-20 17:59:57 +00:00
if (s_in_partition.ignore(pos, expected))
{
if (!parser_partition.parse(pos, command->partition, expected))
return false;
}
2021-03-02 20:28:42 +00:00
2021-08-20 17:59:57 +00:00
if (!s_where.ignore(pos, expected))
2021-03-02 20:28:42 +00:00
return false;
2021-08-20 17:59:57 +00:00
if (!parser_exp_elem.parse(pos, command->predicate, expected))
2021-03-02 20:28:42 +00:00
return false;
2021-02-24 14:26:46 +00:00
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::DELETE;
2021-03-02 20:28:42 +00:00
}
2021-08-20 17:59:57 +00:00
else if (s_update.ignore(pos, expected))
2021-03-02 20:28:42 +00:00
{
2021-08-20 17:59:57 +00:00
if (!parser_assignment_list.parse(pos, command->update_assignments, expected))
return false;
if (s_in_partition.ignore(pos, expected))
{
if (!parser_partition.parse(pos, command->partition, expected))
return false;
}
if (!s_where.ignore(pos, expected))
return false;
if (!parser_exp_elem.parse(pos, command->predicate, expected))
return false;
command->type = ASTAlterCommand::UPDATE;
2021-03-02 20:28:42 +00:00
}
2021-08-20 17:59:57 +00:00
else if (s_comment_column.ignore(pos, expected))
{
if (s_if_exists.ignore(pos, expected))
command->if_exists = true;
2021-08-20 17:59:57 +00:00
if (!parser_name.parse(pos, command->column, expected))
return false;
2021-08-20 17:59:57 +00:00
if (!parser_string_literal.parse(pos, command->comment, expected))
return false;
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::COMMENT_COLUMN;
}
2021-08-20 17:59:57 +00:00
else if (s_modify_ttl.ignore(pos, expected))
{
2021-08-20 17:59:57 +00:00
if (!parser_ttl_list.parse(pos, command->ttl, expected))
return false;
command->type = ASTAlterCommand::MODIFY_TTL;
}
else if (s_remove_ttl.ignore(pos, expected))
{
command->type = ASTAlterCommand::REMOVE_TTL;
}
else if (s_materialize_ttl.ignore(pos, expected))
{
command->type = ASTAlterCommand::MATERIALIZE_TTL;
if (s_in_partition.ignore(pos, expected))
{
2021-08-20 17:59:57 +00:00
if (!parser_partition.parse(pos, command->partition, expected))
return false;
}
}
2021-08-20 17:59:57 +00:00
else if (s_modify_setting.ignore(pos, expected))
{
2021-08-20 17:59:57 +00:00
if (!parser_settings.parse(pos, command->settings_changes, expected))
return false;
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::MODIFY_SETTING;
}
2021-08-20 17:59:57 +00:00
else if (s_reset_setting.ignore(pos, expected))
{
2021-08-20 17:59:57 +00:00
if (!parser_reset_setting.parse(pos, command->settings_resets, expected))
return false;
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::RESET_SETTING;
}
2021-08-20 17:59:57 +00:00
else if (s_modify_query.ignore(pos, expected))
2020-03-10 11:17:26 +00:00
{
2021-08-20 17:59:57 +00:00
if (!select_p.parse(pos, command->select, expected))
2020-03-10 11:17:26 +00:00
return false;
2021-08-20 17:59:57 +00:00
command->type = ASTAlterCommand::MODIFY_QUERY;
2020-03-10 11:17:26 +00:00
}
else if (s_modify_comment.ignore(pos, expected))
{
if (!parser_string_literal.parse(pos, command->comment, expected))
return false;
command->type = ASTAlterCommand::MODIFY_COMMENT;
}
2021-08-20 17:59:57 +00:00
else
return false;
}
}
if (command->col_decl)
command->children.push_back(command->col_decl);
if (command->column)
command->children.push_back(command->column);
if (command->partition)
command->children.push_back(command->partition);
if (command->order_by)
command->children.push_back(command->order_by);
2020-08-27 13:10:10 +00:00
if (command->sample_by)
command->children.push_back(command->sample_by);
2020-11-29 13:30:16 +00:00
if (command->index_decl)
command->children.push_back(command->index_decl);
if (command->index)
command->children.push_back(command->index);
if (command->constraint_decl)
command->children.push_back(command->constraint_decl);
if (command->constraint)
command->children.push_back(command->constraint);
2021-11-05 04:21:52 +00:00
if (command->projection_decl)
command->children.push_back(command->projection_decl);
if (command->projection)
command->children.push_back(command->projection);
if (command->predicate)
command->children.push_back(command->predicate);
if (command->update_assignments)
command->children.push_back(command->update_assignments);
if (command->values)
command->children.push_back(command->values);
if (command->comment)
command->children.push_back(command->comment);
if (command->ttl)
command->children.push_back(command->ttl);
2019-08-21 08:57:19 +00:00
if (command->settings_changes)
command->children.push_back(command->settings_changes);
2020-11-29 13:30:16 +00:00
if (command->select)
command->children.push_back(command->select);
if (command->rename_to)
command->children.push_back(command->rename_to);
return true;
}
2013-08-07 13:07:42 +00:00
bool ParserAlterCommandList::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
{
auto command_list = std::make_shared<ASTExpressionList>();
node = command_list;
ParserToken s_comma(TokenType::Comma);
2021-08-20 17:59:57 +00:00
ParserAlterCommand p_command(alter_object);
do
{
ASTPtr command;
if (!p_command.parse(pos, command, expected))
return false;
2013-08-07 13:07:42 +00:00
command_list->children.push_back(command);
}
while (s_comma.ignore(pos, expected));
2013-08-07 13:07:42 +00:00
return true;
}
bool ParserAlterQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
{
auto query = std::make_shared<ASTAlterQuery>();
node = query;
2013-08-07 13:07:42 +00:00
ParserKeyword s_alter_table("ALTER TABLE");
ParserKeyword s_alter_live_view("ALTER LIVE VIEW");
2021-08-20 17:59:57 +00:00
ParserKeyword s_alter_database("ALTER DATABASE");
2021-08-20 17:59:57 +00:00
ASTAlterQuery::AlterObjectType alter_object_type;
2021-08-20 17:59:57 +00:00
if (s_alter_table.ignore(pos, expected))
{
2021-08-20 17:59:57 +00:00
alter_object_type = ASTAlterQuery::AlterObjectType::TABLE;
}
2021-08-20 17:59:57 +00:00
else if (s_alter_live_view.ignore(pos, expected))
{
alter_object_type = ASTAlterQuery::AlterObjectType::LIVE_VIEW;
}
else if (s_alter_database.ignore(pos, expected))
{
alter_object_type = ASTAlterQuery::AlterObjectType::DATABASE;
}
else
return false;
2021-08-27 06:30:21 +00:00
if (alter_object_type == ASTAlterQuery::AlterObjectType::DATABASE)
{
2021-11-16 08:58:28 +00:00
if (!parseDatabaseAsAST(pos, expected, query->database))
return false;
}
2021-08-27 06:30:21 +00:00
else
{
2021-11-16 08:58:28 +00:00
if (!parseDatabaseAndTableAsAST(pos, expected, query->database, query->table))
return false;
2021-08-27 06:30:21 +00:00
String cluster_str;
if (ParserKeyword{"ON"}.ignore(pos, expected))
{
if (!ASTQueryWithOnCluster::parse(pos, cluster_str, expected))
return false;
}
query->cluster = cluster_str;
}
2021-08-20 17:59:57 +00:00
ParserAlterCommandList p_command_list(alter_object_type);
ASTPtr command_list;
if (!p_command_list.parse(pos, command_list, expected))
return false;
query->set(query->command_list, command_list);
2021-08-27 06:30:21 +00:00
query->alter_object = alter_object_type;
if (query->database)
query->children.push_back(query->database);
if (query->table)
query->children.push_back(query->table);
return true;
2013-08-07 13:07:42 +00:00
}
2013-08-07 13:07:42 +00:00
}