Merge pull request #28955 from anneji-dev/alterTable

Add default database for alter table
This commit is contained in:
Nikolay Degterinsky 2021-09-30 11:28:47 +03:00 committed by GitHub
commit 485e19ff84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 1 deletions

View File

@ -11,6 +11,7 @@
#include <Parsers/ASTTablesInSelectQuery.h>
#include <Parsers/ASTFunction.h>
#include <Parsers/DumpASTNode.h>
#include <Parsers/ASTAlterQuery.h>
#include <Interpreters/DatabaseAndTableWithAlias.h>
#include <Interpreters/IdentifierSemantic.h>
@ -36,7 +37,8 @@ public:
{
visitDDLChildren(ast);
if (!tryVisitDynamicCast<ASTQueryWithTableAndOutput>(ast) &&
if (!tryVisitDynamicCast<ASTAlterQuery>(ast) &&
!tryVisitDynamicCast<ASTQueryWithTableAndOutput>(ast) &&
!tryVisitDynamicCast<ASTRenameQuery>(ast) &&
!tryVisitDynamicCast<ASTFunction>(ast))
{}
@ -194,6 +196,24 @@ private:
}
}
void visitDDL(ASTAlterQuery & node, ASTPtr &) const
{
if (only_replace_current_database_function)
return;
if (node.database.empty())
node.database = database_name;
for (const auto & child : node.command_list->children)
{
auto * command_ast = child->as<ASTAlterCommand>();
if (command_ast->from_database.empty())
command_ast->from_database = database_name;
if (command_ast->to_database.empty())
command_ast->to_database = database_name;
}
}
void visitDDL(ASTFunction & function, ASTPtr & node) const
{
if (function.name == "currentDatabase")

View File

@ -0,0 +1,7 @@
localhost 9000 0 0 0
localhost 9000 0 0 0
localhost 9000 0 0 0
localhost 9000 0 0 0
localhost 9000 0 0 0
localhost 9000 0 0 0
localhost 9000 0 0 0

View File

@ -0,0 +1,19 @@
-- Tags: distributed, no-parallel, no-replicated-database
-- Tag no-replicated-database: ON CLUSTER is not allowed
DROP DATABASE IF EXISTS 02028_db ON CLUSTER test_shard_localhost;
CREATE DATABASE 02028_db ON CLUSTER test_shard_localhost;
USE 02028_db;
CREATE TABLE t1_local ON CLUSTER test_shard_localhost(partition_col_1 String, tc1 int,tc2 int)ENGINE=MergeTree() PARTITION BY partition_col_1 ORDER BY tc1;
CREATE TABLE t2_local ON CLUSTER test_shard_localhost(partition_col_1 String, tc1 int,tc2 int)ENGINE=MergeTree() PARTITION BY partition_col_1 ORDER BY tc1;
INSERT INTO t1_local VALUES('partition1', 1,1);
INSERT INTO t1_local VALUES('partition2', 1,1);
INSERT INTO t2_local VALUES('partition1', 3,3);
INSERT INTO t2_local VALUES('partition2', 6,6);
ALTER TABLE t1_local ON CLUSTER test_shard_localhost REPLACE PARTITION 'partition1' FROM t2_local;
ALTER TABLE t1_local ON CLUSTER test_shard_localhost MOVE PARTITION 'partition2' TO TABLE t2_local;
DROP DATABASE 02028_db ON CLUSTER test_shard_localhost;