提交 b5e4d069 编写于 作者: A Alexey Milovidov

Disallow PREWHERE, SAMPLE, FINAL in MATERIALIZED VIEWs [#CLICKHOUSE-2].

上级 a16dd1ce
......@@ -372,6 +372,7 @@ namespace ErrorCodes
extern const int QUERY_WAS_CANCELLED = 394;
extern const int FUNCTION_THROW_IF_VALUE_IS_NON_ZERO = 395;
extern const int TOO_MANY_ROWS_OR_BYTES = 396;
extern const int QUERY_IS_NOT_SUPPORTED_IN_MATERIALIZED_VIEW = 397;
extern const int KEEPER_EXCEPTION = 999;
......
#include <Parsers/ASTSelectQuery.h>
#include <Parsers/ASTSelectWithUnionQuery.h>
#include <Parsers/ASTCreateQuery.h>
#include <Parsers/ASTDropQuery.h>
#include <Parsers/ASTIdentifier.h>
......@@ -22,6 +23,7 @@ namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
extern const int INCORRECT_QUERY;
extern const int QUERY_IS_NOT_SUPPORTED_IN_MATERIALIZED_VIEW;
}
......@@ -46,7 +48,7 @@ static void extractDependentTable(ASTSelectQuery & query, String & select_databa
else if (auto ast_select = typeid_cast<ASTSelectWithUnionQuery *>(query_table.get()))
{
if (ast_select->list_of_selects->children.size() != 1)
throw Exception("UNION is not supported for MATERIALIZED VIEW", ErrorCodes::INCORRECT_QUERY);
throw Exception("UNION is not supported for MATERIALIZED VIEW", ErrorCodes::QUERY_IS_NOT_SUPPORTED_IN_MATERIALIZED_VIEW);
auto & inner_query = ast_select->list_of_selects->children.at(0);
......@@ -59,6 +61,28 @@ static void extractDependentTable(ASTSelectQuery & query, String & select_databa
}
static void checkAllowedQueries(const ASTSelectQuery & query)
{
if (query.prewhere_expression || query.final() || query.sample_size())
throw Exception("MATERIALIZED VIEW cannot have PREWHERE, SAMPLE or FINAL.", DB::ErrorCodes::QUERY_IS_NOT_SUPPORTED_IN_MATERIALIZED_VIEW);
auto query_table = query.table();
if (!query_table)
return;
if (auto ast_select = typeid_cast<const ASTSelectWithUnionQuery *>(query_table.get()))
{
if (ast_select->list_of_selects->children.size() != 1)
throw Exception("UNION is not supported for MATERIALIZED VIEW", ErrorCodes::QUERY_IS_NOT_SUPPORTED_IN_MATERIALIZED_VIEW);
const auto & inner_query = ast_select->list_of_selects->children.at(0);
checkAllowedQueries(typeid_cast<const ASTSelectQuery &>(*inner_query));
}
}
StorageMaterializedView::StorageMaterializedView(
const String & table_name_,
const String & database_name_,
......@@ -80,11 +104,13 @@ StorageMaterializedView::StorageMaterializedView(
/// Default value, if only table name exist in the query
select_database_name = local_context.getCurrentDatabase();
if (query.select->list_of_selects->children.size() != 1)
throw Exception("UNION is not supported for MATERIALIZED VIEW", ErrorCodes::INCORRECT_QUERY);
throw Exception("UNION is not supported for MATERIALIZED VIEW", ErrorCodes::QUERY_IS_NOT_SUPPORTED_IN_MATERIALIZED_VIEW);
inner_query = query.select->list_of_selects->children.at(0);
extractDependentTable(typeid_cast<ASTSelectQuery &>(*inner_query), select_database_name, select_table_name);
ASTSelectQuery & select_query = typeid_cast<ASTSelectQuery &>(*inner_query);
extractDependentTable(select_query, select_database_name, select_table_name);
checkAllowedQueries(select_query);
if (!select_table_name.empty())
global_context.addDependency(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册