mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-21 01:00:48 +00:00
Merge pull request #28955 from anneji-dev/alterTable
Add default database for alter table
This commit is contained in:
commit
485e19ff84
@ -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")
|
||||
|
@ -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
|
@ -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;
|
Loading…
Reference in New Issue
Block a user