Moved QueryParameterVisitor to Parsers & EXPLAIN SYNTAX test fix - 40907 Parameterized views as table functions

This commit is contained in:
Smita Kulkarni 2022-10-03 16:42:44 +02:00
parent e5c0c6a1b6
commit 7033a56ff2
9 changed files with 25 additions and 5 deletions

View File

@ -54,7 +54,7 @@
#include <Interpreters/DatabaseAndTableWithAlias.h>
#include <Interpreters/IdentifierSemantic.h>
#include <Interpreters/UserDefinedExecutableFunctionFactory.h>
#include <Interpreters/QueryParameterVisitor.h>
#include <Parsers/QueryParameterVisitor.h>
namespace DB

View File

@ -1286,6 +1286,8 @@ bool SelectQueryExpressionAnalyzer::appendWhere(ExpressionActionsChain & chain,
getRootActions(select_query->where(), only_types, step.actions());
//For creating parameterized view, query parameters are allowed in select
//As select will be stored without substituting query parameters, we don't want to evaluate the where expression
if (select_query->allow_query_parameters && select_query->hasQueryParameters())
return true;
@ -1906,6 +1908,8 @@ ExpressionAnalysisResult::ExpressionAnalysisResult(
before_where,
ExpressionActionsSettings::fromSettings(context->getSettingsRef())).execute(before_where_sample);
//For creating parameterized view, query parameters are allowed in select
//As select will be stored without substituting query parameters, we don't want to evaluate the where expression
bool has_query_parameters = query.allow_query_parameters && query.hasQueryParameters();
if (!has_query_parameters)
{
@ -2075,6 +2079,8 @@ void ExpressionAnalysisResult::finalize(
ssize_t & having_step_num,
const ASTSelectQuery & query)
{
//For creating parameterized view, query parameters are allowed in select
//As select will be stored without substituting query parameters, we don't want to evaluate the expressions/steps
if (query.allow_query_parameters && query.hasQueryParameters())
return;

View File

@ -9,7 +9,7 @@
#include <IO/Operators.h>
#include <Parsers/ASTLiteral.h>
#include <Common/FieldVisitorToString.h>
#include <Interpreters/QueryParameterVisitor.h>
#include <Parsers/QueryParameterVisitor.h>
#include <queue>
@ -41,6 +41,9 @@ ASTPtr ASTSelectQuery::clone() const
for (const auto & child : children)
res->children.push_back(child->clone());
res->allow_query_parameters = allow_query_parameters;
res->has_query_parameters = has_query_parameters;
return res;
}

View File

@ -2,7 +2,6 @@
#include <Parsers/IAST.h>
#include <Core/Names.h>
#include <Interpreters/QueryParameterVisitor.h>
namespace DB
{

View File

@ -23,6 +23,8 @@ ASTPtr ASTSelectWithUnionQuery::clone() const
res->list_of_modes = list_of_modes;
res->set_of_modes = set_of_modes;
res->has_query_parameters = has_query_parameters;
cloneOutputOptions(*res);
return res;
}

View File

@ -3,6 +3,7 @@
#include <Parsers/ASTExpressionList.h>
#include <Common/SipHash.h>
#include <IO/Operators.h>
#include <Parsers/ASTFunction.h>
namespace DB
@ -112,6 +113,15 @@ void ASTTableExpression::formatImpl(const FormatSettings & settings, FormatState
settings.ostr << " ";
database_and_table_name->formatImpl(settings, state, frame);
}
//In case of table function view, table_function is preferred over subquery for EXPLAIN SYNTAX
else if (table_function && table_function->as<ASTFunction>() && table_function->as<ASTFunction>()->name=="view")
{
settings.ostr << " ";
table_function->formatImpl(settings, state, frame);
}
//For parameterized view, subquery is preferred over table_function for EXPLAIN SYNTAX
//we cannot remove the table function part, as its needed for query substitution
else if (subquery)
{
settings.ostr << settings.nl_or_ws << indent_str;

View File

@ -1,4 +1,4 @@
#include <Interpreters/QueryParameterVisitor.h>
#include <Parsers/QueryParameterVisitor.h>
#include <Parsers/ASTQueryParameter.h>
#include <Parsers/ParserQuery.h>
#include <Parsers/parseQuery.h>

View File

@ -15,7 +15,7 @@
#include <IO/WriteHelpers.h>
#include <IO/copyData.h>
#include <Interpreters/Context.h>
#include <Interpreters/QueryParameterVisitor.h>
#include <Parsers/QueryParameterVisitor.h>
#include <Interpreters/executeQuery.h>
#include <Interpreters/Session.h>
#include <Server/HTTPHandlerFactory.h>