ClickHouse/src/Interpreters/InterpreterFactory.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

335 lines
12 KiB
C++
Raw Normal View History

#include <Parsers/ASTAlterQuery.h>
2021-08-18 22:19:14 +00:00
#include <Parsers/ASTBackupQuery.h>
#include <Parsers/ASTCheckQuery.h>
#include <Parsers/ASTCreateQuery.h>
2021-08-23 14:31:58 +00:00
#include <Parsers/ASTCreateFunctionQuery.h>
#include <Parsers/ASTCreateIndexQuery.h>
#include <Parsers/ASTDeleteQuery.h>
2021-05-14 22:43:04 +00:00
#include <Parsers/ASTDropFunctionQuery.h>
#include <Parsers/ASTDropIndexQuery.h>
#include <Parsers/ASTDropQuery.h>
2021-04-16 20:18:39 +00:00
#include <Parsers/ASTExplainQuery.h>
#include <Parsers/ASTInsertQuery.h>
2021-08-12 11:42:51 +00:00
#include <Parsers/ASTSelectIntersectExceptQuery.h>
#include <Parsers/ASTKillQueryQuery.h>
#include <Parsers/ASTOptimizeQuery.h>
#include <Parsers/ASTRenameQuery.h>
#include <Parsers/ASTSelectQuery.h>
2018-02-25 06:34:20 +00:00
#include <Parsers/ASTSelectWithUnionQuery.h>
#include <Parsers/ASTSetQuery.h>
#include <Parsers/ASTShowProcesslistQuery.h>
#include <Parsers/ASTShowTablesQuery.h>
#include <Parsers/ASTUseQuery.h>
#include <Parsers/ASTWatchQuery.h>
#include <Parsers/MySQL/ASTCreateQuery.h>
2021-03-31 17:55:04 +00:00
#include <Parsers/ASTTransactionControl.h>
2021-04-16 20:18:39 +00:00
#include <Parsers/TablePropertiesQueriesASTs.h>
2015-06-18 02:11:05 +00:00
#include <Parsers/Access/ASTCreateQuotaQuery.h>
#include <Parsers/Access/ASTCreateRoleQuery.h>
#include <Parsers/Access/ASTCreateRowPolicyQuery.h>
#include <Parsers/Access/ASTCreateSettingsProfileQuery.h>
#include <Parsers/Access/ASTCreateUserQuery.h>
#include <Parsers/Access/ASTDropAccessEntityQuery.h>
#include <Parsers/Access/ASTGrantQuery.h>
#include <Parsers/Access/ASTSetRoleQuery.h>
#include <Parsers/Access/ASTShowAccessEntitiesQuery.h>
#include <Parsers/Access/ASTShowAccessQuery.h>
#include <Parsers/Access/ASTShowCreateAccessEntityQuery.h>
#include <Parsers/Access/ASTShowGrantsQuery.h>
#include <Parsers/Access/ASTShowPrivilegesQuery.h>
2022-06-21 13:42:36 +00:00
#include <Parsers/ASTDescribeCacheQuery.h>
2020-07-01 06:42:22 +00:00
#include <Interpreters/Context.h>
#include <Interpreters/InterpreterAlterQuery.h>
2021-08-18 22:19:14 +00:00
#include <Interpreters/InterpreterBackupQuery.h>
#include <Interpreters/InterpreterCheckQuery.h>
#include <Interpreters/InterpreterCreateFunctionQuery.h>
#include <Interpreters/InterpreterCreateIndexQuery.h>
#include <Interpreters/InterpreterCreateQuery.h>
#include <Interpreters/InterpreterDeleteQuery.h>
#include <Interpreters/InterpreterDescribeQuery.h>
2022-06-21 13:42:36 +00:00
#include <Interpreters/InterpreterDescribeCacheQuery.h>
2021-05-14 22:43:04 +00:00
#include <Interpreters/InterpreterDropFunctionQuery.h>
#include <Interpreters/InterpreterDropIndexQuery.h>
#include <Interpreters/InterpreterDropQuery.h>
#include <Interpreters/InterpreterExistsQuery.h>
2020-07-01 06:42:22 +00:00
#include <Interpreters/InterpreterExplainQuery.h>
2021-04-16 20:18:39 +00:00
#include <Interpreters/InterpreterExternalDDLQuery.h>
#include <Interpreters/InterpreterFactory.h>
#include <Interpreters/InterpreterInsertQuery.h>
2021-08-12 11:42:51 +00:00
#include <Interpreters/InterpreterSelectIntersectExceptQuery.h>
#include <Interpreters/InterpreterKillQueryQuery.h>
#include <Interpreters/InterpreterOptimizeQuery.h>
#include <Interpreters/InterpreterRenameQuery.h>
#include <Interpreters/InterpreterSelectQuery.h>
2022-07-14 11:20:16 +00:00
#include <Interpreters/InterpreterSelectQueryAnalyzer.h>
2018-02-25 06:34:20 +00:00
#include <Interpreters/InterpreterSelectWithUnionQuery.h>
#include <Interpreters/InterpreterSetQuery.h>
2020-07-01 06:42:22 +00:00
#include <Interpreters/InterpreterShowCreateQuery.h>
#include <Interpreters/InterpreterShowProcesslistQuery.h>
#include <Interpreters/InterpreterShowTablesQuery.h>
#include <Interpreters/InterpreterSystemQuery.h>
#include <Interpreters/InterpreterUseQuery.h>
#include <Interpreters/InterpreterWatchQuery.h>
2021-03-31 17:55:04 +00:00
#include <Interpreters/InterpreterTransactionControlQuery.h>
#include <Interpreters/OpenTelemetrySpanLog.h>
2015-06-18 02:11:05 +00:00
#include <Interpreters/Access/InterpreterCreateQuotaQuery.h>
#include <Interpreters/Access/InterpreterCreateRoleQuery.h>
#include <Interpreters/Access/InterpreterCreateRowPolicyQuery.h>
#include <Interpreters/Access/InterpreterCreateSettingsProfileQuery.h>
#include <Interpreters/Access/InterpreterCreateUserQuery.h>
#include <Interpreters/Access/InterpreterDropAccessEntityQuery.h>
#include <Interpreters/Access/InterpreterGrantQuery.h>
#include <Interpreters/Access/InterpreterSetRoleQuery.h>
#include <Interpreters/Access/InterpreterShowAccessEntitiesQuery.h>
#include <Interpreters/Access/InterpreterShowAccessQuery.h>
#include <Interpreters/Access/InterpreterShowCreateAccessEntityQuery.h>
#include <Interpreters/Access/InterpreterShowGrantsQuery.h>
#include <Interpreters/Access/InterpreterShowPrivilegesQuery.h>
#include <Parsers/ASTSystemQuery.h>
#include <Databases/MySQL/MaterializedMySQLSyncThread.h>
2020-07-06 13:57:45 +00:00
#include <Parsers/ASTExternalDDLQuery.h>
#include <Common/ProfileEvents.h>
#include <Common/typeid_cast.h>
namespace ProfileEvents
{
extern const Event Query;
extern const Event SelectQuery;
extern const Event InsertQuery;
}
2017-07-13 20:58:19 +00:00
2015-06-18 02:11:05 +00:00
namespace DB
{
namespace ErrorCodes
{
extern const int UNKNOWN_TYPE_OF_QUERY;
}
2015-06-18 02:11:05 +00:00
2021-05-31 14:49:02 +00:00
std::unique_ptr<IInterpreter> InterpreterFactory::get(ASTPtr & query, ContextMutablePtr context, const SelectQueryOptions & options)
2015-06-18 02:11:05 +00:00
{
ProfileEvents::increment(ProfileEvents::Query);
2019-03-11 13:22:51 +00:00
if (query->as<ASTSelectQuery>())
2015-06-18 02:11:05 +00:00
{
if (context->getSettingsRef().allow_experimental_analyzer)
2022-07-14 11:20:16 +00:00
return std::make_unique<InterpreterSelectQueryAnalyzer>(query, options, context);
/// This is internal part of ASTSelectWithUnionQuery.
/// Even if there is SELECT without union, it is represented by ASTSelectWithUnionQuery with single ASTSelectQuery as a child.
2020-12-18 06:54:38 +00:00
return std::make_unique<InterpreterSelectQuery>(query, context, options);
2015-06-18 02:11:05 +00:00
}
2019-03-11 13:22:51 +00:00
else if (query->as<ASTSelectWithUnionQuery>())
2018-02-25 06:34:20 +00:00
{
ProfileEvents::increment(ProfileEvents::SelectQuery);
2022-07-14 11:20:16 +00:00
if (context->getSettingsRef().allow_experimental_analyzer)
2022-07-14 11:20:16 +00:00
return std::make_unique<InterpreterSelectQueryAnalyzer>(query, options, context);
2020-12-18 06:54:38 +00:00
return std::make_unique<InterpreterSelectWithUnionQuery>(query, context, options);
2018-02-25 06:34:20 +00:00
}
2021-08-12 11:42:51 +00:00
else if (query->as<ASTSelectIntersectExceptQuery>())
2021-04-16 20:18:39 +00:00
{
2021-08-12 11:42:51 +00:00
return std::make_unique<InterpreterSelectIntersectExceptQuery>(query, context, options);
2021-04-16 20:18:39 +00:00
}
2019-03-11 13:22:51 +00:00
else if (query->as<ASTInsertQuery>())
2015-06-18 02:11:05 +00:00
{
ProfileEvents::increment(ProfileEvents::InsertQuery);
bool allow_materialized = static_cast<bool>(context->getSettingsRef().insert_allow_materialized_columns);
2018-01-12 13:03:19 +00:00
return std::make_unique<InterpreterInsertQuery>(query, context, allow_materialized);
2015-06-18 02:11:05 +00:00
}
2019-03-11 13:22:51 +00:00
else if (query->as<ASTCreateQuery>())
2015-06-18 02:11:05 +00:00
{
return std::make_unique<InterpreterCreateQuery>(query, context);
2015-06-18 02:11:05 +00:00
}
2019-03-11 13:22:51 +00:00
else if (query->as<ASTDropQuery>())
2015-06-18 02:11:05 +00:00
{
return std::make_unique<InterpreterDropQuery>(query, context);
2015-06-18 02:11:05 +00:00
}
2019-03-11 13:22:51 +00:00
else if (query->as<ASTRenameQuery>())
2015-06-18 02:11:05 +00:00
{
return std::make_unique<InterpreterRenameQuery>(query, context);
2015-06-18 02:11:05 +00:00
}
2019-03-11 13:22:51 +00:00
else if (query->as<ASTShowTablesQuery>())
2015-06-18 02:11:05 +00:00
{
return std::make_unique<InterpreterShowTablesQuery>(query, context);
2015-06-18 02:11:05 +00:00
}
2019-03-11 13:22:51 +00:00
else if (query->as<ASTUseQuery>())
2015-06-18 02:11:05 +00:00
{
return std::make_unique<InterpreterUseQuery>(query, context);
2015-06-18 02:11:05 +00:00
}
2019-03-11 13:22:51 +00:00
else if (query->as<ASTSetQuery>())
2015-06-18 02:11:05 +00:00
{
2017-04-02 17:37:49 +00:00
/// readonly is checked inside InterpreterSetQuery
return std::make_unique<InterpreterSetQuery>(query, context);
2015-06-18 02:11:05 +00:00
}
else if (query->as<ASTSetRoleQuery>())
{
return std::make_unique<InterpreterSetRoleQuery>(query, context);
}
2019-03-11 13:22:51 +00:00
else if (query->as<ASTOptimizeQuery>())
2015-06-18 02:11:05 +00:00
{
return std::make_unique<InterpreterOptimizeQuery>(query, context);
2015-06-18 02:11:05 +00:00
}
2020-12-24 09:16:47 +00:00
else if (query->as<ASTExistsDatabaseQuery>())
{
return std::make_unique<InterpreterExistsQuery>(query, context);
}
2019-10-08 12:34:04 +00:00
else if (query->as<ASTExistsTableQuery>())
2015-06-18 02:11:05 +00:00
{
return std::make_unique<InterpreterExistsQuery>(query, context);
2015-06-18 02:11:05 +00:00
}
2020-12-27 14:14:08 +00:00
else if (query->as<ASTExistsViewQuery>())
{
return std::make_unique<InterpreterExistsQuery>(query, context);
}
else if (query->as<ASTExistsDictionaryQuery>())
{
return std::make_unique<InterpreterExistsQuery>(query, context);
}
2019-03-11 13:22:51 +00:00
else if (query->as<ASTShowCreateTableQuery>())
{
return std::make_unique<InterpreterShowCreateQuery>(query, context);
}
2020-12-14 14:37:25 +00:00
else if (query->as<ASTShowCreateViewQuery>())
{
return std::make_unique<InterpreterShowCreateQuery>(query, context);
}
2019-03-11 13:22:51 +00:00
else if (query->as<ASTShowCreateDatabaseQuery>())
2015-06-18 02:11:05 +00:00
{
return std::make_unique<InterpreterShowCreateQuery>(query, context);
2015-06-18 02:11:05 +00:00
}
else if (query->as<ASTShowCreateDictionaryQuery>())
{
return std::make_unique<InterpreterShowCreateQuery>(query, context);
}
2019-03-11 13:22:51 +00:00
else if (query->as<ASTDescribeQuery>())
2015-06-18 02:11:05 +00:00
{
return std::make_unique<InterpreterDescribeQuery>(query, context);
2015-06-18 02:11:05 +00:00
}
2022-06-21 13:42:36 +00:00
else if (query->as<ASTDescribeCacheQuery>())
{
return std::make_unique<InterpreterDescribeCacheQuery>(query, context);
}
2019-03-11 13:22:51 +00:00
else if (query->as<ASTExplainQuery>())
2018-09-21 15:20:23 +00:00
{
return std::make_unique<InterpreterExplainQuery>(query, context);
}
2019-03-11 13:22:51 +00:00
else if (query->as<ASTShowProcesslistQuery>())
2015-06-18 02:11:05 +00:00
{
return std::make_unique<InterpreterShowProcesslistQuery>(query, context);
2015-06-18 02:11:05 +00:00
}
2019-03-11 13:22:51 +00:00
else if (query->as<ASTAlterQuery>())
2015-06-18 02:11:05 +00:00
{
return std::make_unique<InterpreterAlterQuery>(query, context);
2015-06-18 02:11:05 +00:00
}
2019-03-11 13:22:51 +00:00
else if (query->as<ASTCheckQuery>())
2015-06-18 02:11:05 +00:00
{
return std::make_unique<InterpreterCheckQuery>(query, context);
2015-06-18 02:11:05 +00:00
}
2019-03-11 13:22:51 +00:00
else if (query->as<ASTKillQueryQuery>())
2016-11-30 17:31:05 +00:00
{
return std::make_unique<InterpreterKillQueryQuery>(query, context);
}
2019-03-11 13:22:51 +00:00
else if (query->as<ASTSystemQuery>())
{
return std::make_unique<InterpreterSystemQuery>(query, context);
}
else if (query->as<ASTWatchQuery>())
{
return std::make_unique<InterpreterWatchQuery>(query, context);
}
else if (query->as<ASTCreateUserQuery>())
{
return std::make_unique<InterpreterCreateUserQuery>(query, context);
}
else if (query->as<ASTCreateRoleQuery>())
{
return std::make_unique<InterpreterCreateRoleQuery>(query, context);
}
2019-12-01 22:01:05 +00:00
else if (query->as<ASTCreateQuotaQuery>())
{
return std::make_unique<InterpreterCreateQuotaQuery>(query, context);
}
2019-11-29 17:22:56 +00:00
else if (query->as<ASTCreateRowPolicyQuery>())
{
return std::make_unique<InterpreterCreateRowPolicyQuery>(query, context);
}
else if (query->as<ASTCreateSettingsProfileQuery>())
{
return std::make_unique<InterpreterCreateSettingsProfileQuery>(query, context);
}
2019-12-01 22:01:05 +00:00
else if (query->as<ASTDropAccessEntityQuery>())
{
return std::make_unique<InterpreterDropAccessEntityQuery>(query, context);
}
else if (query->as<ASTGrantQuery>())
{
return std::make_unique<InterpreterGrantQuery>(query, context);
}
2019-12-01 22:01:05 +00:00
else if (query->as<ASTShowCreateAccessEntityQuery>())
{
return std::make_unique<InterpreterShowCreateAccessEntityQuery>(query, context);
}
else if (query->as<ASTShowGrantsQuery>())
{
return std::make_unique<InterpreterShowGrantsQuery>(query, context);
}
else if (query->as<ASTShowAccessEntitiesQuery>())
2019-11-29 17:22:56 +00:00
{
return std::make_unique<InterpreterShowAccessEntitiesQuery>(query, context);
2019-11-29 17:22:56 +00:00
}
2020-06-10 23:08:37 +00:00
else if (query->as<ASTShowAccessQuery>())
{
return std::make_unique<InterpreterShowAccessQuery>(query, context);
}
2020-05-12 21:46:14 +00:00
else if (query->as<ASTShowPrivilegesQuery>())
{
return std::make_unique<InterpreterShowPrivilegesQuery>(query, context);
}
2020-07-06 13:57:45 +00:00
else if (query->as<ASTExternalDDLQuery>())
{
return std::make_unique<InterpreterExternalDDLQuery>(query, context);
}
2021-03-31 17:55:04 +00:00
else if (query->as<ASTTransactionControl>())
{
return std::make_unique<InterpreterTransactionControlQuery>(query, context);
}
else if (query->as<ASTCreateFunctionQuery>())
{
return std::make_unique<InterpreterCreateFunctionQuery>(query, context);
}
2021-05-14 22:43:04 +00:00
else if (query->as<ASTDropFunctionQuery>())
{
return std::make_unique<InterpreterDropFunctionQuery>(query, context);
}
else if (query->as<ASTCreateIndexQuery>())
{
return std::make_unique<InterpreterCreateIndexQuery>(query, context);
}
else if (query->as<ASTDropIndexQuery>())
{
return std::make_unique<InterpreterDropIndexQuery>(query, context);
}
2021-08-18 22:19:14 +00:00
else if (query->as<ASTBackupQuery>())
{
return std::make_unique<InterpreterBackupQuery>(query, context);
}
else if (query->as<ASTDeleteQuery>())
{
return std::make_unique<InterpreterDeleteQuery>(query, context);
}
2015-06-18 02:11:05 +00:00
else
{
2015-06-18 02:11:05 +00:00
throw Exception("Unknown type of query: " + query->getID(), ErrorCodes::UNKNOWN_TYPE_OF_QUERY);
}
2015-06-18 02:11:05 +00:00
}
}