diff options
| author | vitalyisaev <[email protected]> | 2023-11-14 09:58:56 +0300 |
|---|---|---|
| committer | vitalyisaev <[email protected]> | 2023-11-14 10:20:20 +0300 |
| commit | c2b2dfd9827a400a8495e172a56343462e3ceb82 (patch) | |
| tree | cd4e4f597d01bede4c82dffeb2d780d0a9046bd0 /contrib/clickhouse/src/Interpreters/MySQL/InterpretersMySQLDDLQuery.h | |
| parent | d4ae8f119e67808cb0cf776ba6e0cf95296f2df7 (diff) | |
YQ Connector: move tests from yql to ydb (OSS)
Перенос папки с тестами на Коннектор из папки yql в папку ydb (синхронизируется с github).
Diffstat (limited to 'contrib/clickhouse/src/Interpreters/MySQL/InterpretersMySQLDDLQuery.h')
| -rw-r--r-- | contrib/clickhouse/src/Interpreters/MySQL/InterpretersMySQLDDLQuery.h | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/contrib/clickhouse/src/Interpreters/MySQL/InterpretersMySQLDDLQuery.h b/contrib/clickhouse/src/Interpreters/MySQL/InterpretersMySQLDDLQuery.h new file mode 100644 index 00000000000..27f467a12ae --- /dev/null +++ b/contrib/clickhouse/src/Interpreters/MySQL/InterpretersMySQLDDLQuery.h @@ -0,0 +1,98 @@ +#pragma once + +#include <Interpreters/IInterpreter.h> +#include <Interpreters/executeQuery.h> +#include <Parsers/ASTRenameQuery.h> +#include <Parsers/IAST_fwd.h> +#include <Parsers/MySQL/ASTAlterQuery.h> +#include <Parsers/MySQL/ASTCreateQuery.h> +#include <Parsers/MySQL/ASTDropQuery.h> +#include <Parsers/queryToString.h> +#include <Parsers/ASTExpressionList.h> + +namespace DB +{ + +class NamesAndTypesList; + +namespace MySQLInterpreter +{ + struct InterpreterDropImpl + { + using TQuery = MySQLParser::ASTDropQuery; + + static void validate(const TQuery & query, ContextPtr context); + + static ASTs getRewrittenQueries( + const TQuery & drop_query, ContextPtr context, const String & mapped_to_database, const String & mysql_database); + }; + + struct InterpreterAlterImpl + { + using TQuery = MySQLParser::ASTAlterQuery; + + static void validate(const TQuery & query, ContextPtr context); + + static ASTs getRewrittenQueries( + const TQuery & alter_query, ContextPtr context, const String & mapped_to_database, const String & mysql_database); + }; + + struct InterpreterRenameImpl + { + using TQuery = ASTRenameQuery; + + static void validate(const TQuery & query, ContextPtr context); + + static ASTs getRewrittenQueries( + const TQuery & rename_query, ContextPtr context, const String & mapped_to_database, const String & mysql_database); + }; + + struct InterpreterCreateImpl + { + using TQuery = MySQLParser::ASTCreateQuery; + + static void validate(const TQuery & query, ContextPtr context); + + static ASTs getRewrittenQueries( + const TQuery & create_query, ContextPtr context, const String & mapped_to_database, const String & mysql_database); + }; + +template <typename InterpreterImpl> +class InterpreterMySQLDDLQuery : public IInterpreter, WithMutableContext +{ +public: + InterpreterMySQLDDLQuery( + const ASTPtr & query_ptr_, ContextMutablePtr context_, const String & mapped_to_database_, const String & mysql_database_) + : WithMutableContext(context_), query_ptr(query_ptr_), mapped_to_database(mapped_to_database_), mysql_database(mysql_database_) + { + } + + BlockIO execute() override + { + const typename InterpreterImpl::TQuery & query = query_ptr->as<typename InterpreterImpl::TQuery &>(); + + InterpreterImpl::validate(query, getContext()); + ASTs rewritten_queries = InterpreterImpl::getRewrittenQueries(query, getContext(), mapped_to_database, mysql_database); + + for (const auto & rewritten_query : rewritten_queries) + executeQuery("/* Rewritten MySQL DDL Query */ " + queryToString(rewritten_query), getContext(), true); + + return BlockIO{}; + } + +private: + ASTPtr query_ptr; + const String mapped_to_database; + const String mysql_database; +}; + +using InterpreterMySQLDropQuery = InterpreterMySQLDDLQuery<InterpreterDropImpl>; +using InterpreterMySQLAlterQuery = InterpreterMySQLDDLQuery<InterpreterAlterImpl>; +using InterpreterMySQLRenameQuery = InterpreterMySQLDDLQuery<InterpreterRenameImpl>; +using InterpreterMySQLCreateQuery = InterpreterMySQLDDLQuery<InterpreterCreateImpl>; + +NamesAndTypesList getColumnsList(const ASTExpressionList * columns_definition); + +} + +} |
