From a1023bebff727d449af26b60c668e1676a7a793d Mon Sep 17 00:00:00 2001 From: Nikolai Kochetov Date: Fri, 9 Aug 2019 16:37:42 +0300 Subject: [PATCH] Fix tests. --- dbms/src/Interpreters/Context.cpp | 2 +- dbms/src/Interpreters/Context.h | 4 ++-- .../Interpreters/InterpreterSelectQuery.cpp | 21 +++---------------- .../InterpreterSelectWithUnionQuery.h | 1 - .../src/Interpreters/MutationsInterpreter.cpp | 3 ++- dbms/src/Storages/StorageDistributed.cpp | 8 +++++-- 6 files changed, 14 insertions(+), 25 deletions(-) diff --git a/dbms/src/Interpreters/Context.cpp b/dbms/src/Interpreters/Context.cpp index fef7b067624..992593d852c 100644 --- a/dbms/src/Interpreters/Context.cpp +++ b/dbms/src/Interpreters/Context.cpp @@ -967,7 +967,7 @@ StoragePtr Context::tryRemoveExternalTable(const String & table_name) } -StoragePtr Context::executeTableFunction(const ASTPtr & table_expression) const +StoragePtr Context::executeTableFunction(const ASTPtr & table_expression) { /// Slightly suboptimal. auto hash = table_expression->getTreeHash(); diff --git a/dbms/src/Interpreters/Context.h b/dbms/src/Interpreters/Context.h index a44ae210c64..50b7ab3eba2 100644 --- a/dbms/src/Interpreters/Context.h +++ b/dbms/src/Interpreters/Context.h @@ -135,7 +135,7 @@ private: /// Thus, used in HTTP interface. If not specified - then some globally default format is used. TableAndCreateASTs external_tables; /// Temporary tables. StoragePtr view_source; /// Temporary StorageValues used to generate alias columns for materialized views - mutable Tables table_function_results; /// Temporary tables obtained by execution of table functions. Keyed by AST tree id. + Tables table_function_results; /// Temporary tables obtained by execution of table functions. Keyed by AST tree id. Context * query_context = nullptr; Context * session_context = nullptr; /// Session context or nullptr. Could be equal to this. Context * global_context = nullptr; /// Global context. Could be equal to this. @@ -245,7 +245,7 @@ public: void addExternalTable(const String & table_name, const StoragePtr & storage, const ASTPtr & ast = {}); StoragePtr tryRemoveExternalTable(const String & table_name); - StoragePtr executeTableFunction(const ASTPtr & table_expression) const; + StoragePtr executeTableFunction(const ASTPtr & table_expression); void addViewSource(const StoragePtr & storage); StoragePtr getViewSource(); diff --git a/dbms/src/Interpreters/InterpreterSelectQuery.cpp b/dbms/src/Interpreters/InterpreterSelectQuery.cpp index 9c10c317d28..941b3d44bb7 100644 --- a/dbms/src/Interpreters/InterpreterSelectQuery.cpp +++ b/dbms/src/Interpreters/InterpreterSelectQuery.cpp @@ -406,6 +406,9 @@ Block InterpreterSelectQuery::getSampleBlockImpl() { FilterInfoPtr filter_info; + /// Need to create sets before analyzeExpressions(). Otherwise some sets for index won't be created. + query_analyzer->makeSetsForIndex(); + auto analysis_result = analyzeExpressions( getSelectQuery(), *query_analyzer, @@ -498,24 +501,6 @@ InterpreterSelectQuery::analyzeExpressions( { chain.finalize(); - /// Check that actions on current step are valid. - /// Now this in needed for mutations to check in mutation is valid before execute it in background. - /// Because some functions only checking correctness of constant arguments during execution, - /// but not in getReturnType method (e.g. compare date with constant string). - if (dry_run) - { - for (auto & step : chain.steps) - { - auto step_required_columns = step.actions->getRequiredColumnsWithTypes(); - - Block sample; - for (auto & col : step_required_columns) - sample.insert({col.type->createColumn(), col.type, col.name}); - - step.actions->execute(sample); - } - } - if (has_prewhere) { const ExpressionActionsChain::Step & step = chain.steps.at(0); diff --git a/dbms/src/Interpreters/InterpreterSelectWithUnionQuery.h b/dbms/src/Interpreters/InterpreterSelectWithUnionQuery.h index aa5a763feaa..9f2a4a96494 100644 --- a/dbms/src/Interpreters/InterpreterSelectWithUnionQuery.h +++ b/dbms/src/Interpreters/InterpreterSelectWithUnionQuery.h @@ -50,7 +50,6 @@ private: Context context; std::vector> nested_interpreters; - Blocks nested_headers; Block result_header; diff --git a/dbms/src/Interpreters/MutationsInterpreter.cpp b/dbms/src/Interpreters/MutationsInterpreter.cpp index 69339f66712..27200249e1c 100644 --- a/dbms/src/Interpreters/MutationsInterpreter.cpp +++ b/dbms/src/Interpreters/MutationsInterpreter.cpp @@ -397,7 +397,8 @@ BlockInputStreamPtr MutationsInterpreter::addStreamsForLaterStages(BlockInputStr void MutationsInterpreter::validate() { prepare(/* dry_run = */ true); - Block first_stage_header = interpreter_select->getSampleBlock(); + /// Do not use getSampleBlock in order to check the whole pipeline. + Block first_stage_header = interpreter_select->execute().in->getHeader(); BlockInputStreamPtr in = std::make_shared(first_stage_header); addStreamsForLaterStages(in)->getHeader(); } diff --git a/dbms/src/Storages/StorageDistributed.cpp b/dbms/src/Storages/StorageDistributed.cpp index 2ecae5789dc..68e09c319d8 100644 --- a/dbms/src/Storages/StorageDistributed.cpp +++ b/dbms/src/Storages/StorageDistributed.cpp @@ -301,8 +301,12 @@ BlockInputStreams StorageDistributed::read( const auto & modified_query_ast = rewriteSelectQuery( query_info.query, remote_database, remote_table, remote_table_function_ptr); - Block header = materializeBlock( - InterpreterSelectQuery(query_info.query, context, SelectQueryOptions(processed_stage)).getSampleBlock()); + Block header = + InterpreterSelectQuery(query_info.query, context, SelectQueryOptions(processed_stage)).getSampleBlock(); + + for (auto & col : header) + if (isColumnConst(*col.column)) + col.column = col.type->createColumn(); ClusterProxy::SelectStreamFactory select_stream_factory = remote_table_function_ptr ? ClusterProxy::SelectStreamFactory(