1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#include "clickhouse_config.h"
#include <Interpreters/InterpreterExternalDDLQuery.h>
#include <Interpreters/Context.h>
#include <Parsers/IAST.h>
#include <Parsers/ASTDropQuery.h>
#include <Parsers/ASTRenameQuery.h>
#include <Parsers/ASTIdentifier.h>
#include <Parsers/ASTExternalDDLQuery.h>
#if USE_MYSQL
# include <Interpreters/MySQL/InterpretersMySQLDDLQuery.h>
# include <Parsers/MySQL/ASTAlterQuery.h>
# include <Parsers/MySQL/ASTCreateQuery.h>
# include <Parsers/MySQL/ASTDropQuery.h>
#endif
namespace DB
{
namespace ErrorCodes
{
extern const int SYNTAX_ERROR;
extern const int BAD_ARGUMENTS;
}
InterpreterExternalDDLQuery::InterpreterExternalDDLQuery(const ASTPtr & query_, ContextMutablePtr context_)
: WithMutableContext(context_), query(query_)
{
}
BlockIO InterpreterExternalDDLQuery::execute()
{
const ASTExternalDDLQuery & external_ddl_query = query->as<ASTExternalDDLQuery &>();
if (getContext()->getClientInfo().query_kind != ClientInfo::QueryKind::SECONDARY_QUERY)
throw Exception(ErrorCodes::SYNTAX_ERROR, "Cannot parse and execute EXTERNAL DDL FROM.");
if (external_ddl_query.from->name == "MySQL")
{
#if USE_MYSQL
const ASTs & arguments = external_ddl_query.from->arguments->children;
if (arguments.size() != 2 || !arguments[0]->as<ASTIdentifier>() || !arguments[1]->as<ASTIdentifier>())
throw Exception(ErrorCodes::BAD_ARGUMENTS, "MySQL External require two identifier arguments.");
if (external_ddl_query.external_ddl->as<MySQLParser::ASTDropQuery>())
return MySQLInterpreter::InterpreterMySQLDropQuery(
external_ddl_query.external_ddl, getContext(), getIdentifierName(arguments[0]),
getIdentifierName(arguments[1])).execute();
else if (external_ddl_query.external_ddl->as<ASTRenameQuery>())
return MySQLInterpreter::InterpreterMySQLRenameQuery(
external_ddl_query.external_ddl, getContext(), getIdentifierName(arguments[0]),
getIdentifierName(arguments[1])).execute();
else if (external_ddl_query.external_ddl->as<MySQLParser::ASTAlterQuery>())
return MySQLInterpreter::InterpreterMySQLAlterQuery(
external_ddl_query.external_ddl, getContext(), getIdentifierName(arguments[0]),
getIdentifierName(arguments[1])).execute();
else if (external_ddl_query.external_ddl->as<MySQLParser::ASTCreateQuery>())
return MySQLInterpreter::InterpreterMySQLCreateQuery(
external_ddl_query.external_ddl, getContext(), getIdentifierName(arguments[0]),
getIdentifierName(arguments[1])).execute();
#endif
}
return BlockIO();
}
}
|