From 9ca08f8fdafbc002cc4639d97c0260b14c2bca97 Mon Sep 17 00:00:00 2001 From: Igor Nikonov Date: Wed, 6 Jul 2022 12:59:25 +0000 Subject: [PATCH] Continue: ContextPtr -> const ContextPtr & in parameters --- src/Interpreters/InterpreterSelectQuery.cpp | 20 +++++++++---------- src/Interpreters/InterpreterSelectQuery.h | 6 +++--- .../evaluateConstantExpression.cpp | 8 ++++---- src/Interpreters/evaluateConstantExpression.h | 8 ++++---- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Interpreters/InterpreterSelectQuery.cpp b/src/Interpreters/InterpreterSelectQuery.cpp index c8c0c44e21f..42a53fb7138 100644 --- a/src/Interpreters/InterpreterSelectQuery.cpp +++ b/src/Interpreters/InterpreterSelectQuery.cpp @@ -206,7 +206,7 @@ InterpreterSelectQuery::~InterpreterSelectQuery() = default; /** There are no limits on the maximum size of the result for the subquery. * Since the result of the query is not the result of the entire query. */ -static ContextPtr getSubqueryContext(ContextPtr context) +static ContextPtr getSubqueryContext(const ContextPtr & context) { auto subquery_context = Context::createCopy(context); Settings subquery_settings = context->getSettings(); @@ -239,7 +239,7 @@ static void rewriteMultipleJoins(ASTPtr & query, const TablesWithColumns & table /// Checks that the current user has the SELECT privilege. static void checkAccessRightsForSelect( - ContextPtr context, + const ContextPtr & context, const StorageID & table_id, const StorageMetadataPtr & table_metadata, const TreeRewriterResult & syntax_analyzer_result) @@ -816,7 +816,7 @@ Block InterpreterSelectQuery::getSampleBlockImpl() return analysis_result.final_projection->getResultColumns(); } -static Field getWithFillFieldValue(const ASTPtr & node, ContextPtr context) +static Field getWithFillFieldValue(const ASTPtr & node, const ContextPtr & context) { auto [field, type] = evaluateConstantExpression(node, context); @@ -826,7 +826,7 @@ static Field getWithFillFieldValue(const ASTPtr & node, ContextPtr context) return field; } -static std::pair> getWithFillStep(const ASTPtr & node, ContextPtr context) +static std::pair> getWithFillStep(const ASTPtr & node, const ContextPtr & context) { auto [field, type] = evaluateConstantExpression(node, context); @@ -839,7 +839,7 @@ static std::pair> getWithFillStep(const ASTPt throw Exception("Illegal type " + type->getName() + " of WITH FILL expression, must be numeric type", ErrorCodes::INVALID_WITH_FILL_EXPRESSION); } -static FillColumnDescription getWithFillDescription(const ASTOrderByElement & order_by_elem, ContextPtr context) +static FillColumnDescription getWithFillDescription(const ASTOrderByElement & order_by_elem, const ContextPtr & context) { FillColumnDescription descr; @@ -886,7 +886,7 @@ static FillColumnDescription getWithFillDescription(const ASTOrderByElement & or return descr; } -SortDescription InterpreterSelectQuery::getSortDescription(const ASTSelectQuery & query, ContextPtr context_) +SortDescription InterpreterSelectQuery::getSortDescription(const ASTSelectQuery & query, const ContextPtr & context_) { SortDescription order_descr; order_descr.reserve(query.orderBy()->children.size()); @@ -998,7 +998,7 @@ static SortDescription getSortDescriptionFromGroupBy(const ASTSelectQuery & quer return order_descr; } -static UInt64 getLimitUIntValue(const ASTPtr & node, ContextPtr context, const std::string & expr) +static UInt64 getLimitUIntValue(const ASTPtr & node, const ContextPtr & context, const std::string & expr) { const auto & [field, type] = evaluateConstantExpression(node, context); @@ -1016,7 +1016,7 @@ static UInt64 getLimitUIntValue(const ASTPtr & node, ContextPtr context, const s } -static std::pair getLimitLengthAndOffset(const ASTSelectQuery & query, ContextPtr context) +static std::pair getLimitLengthAndOffset(const ASTSelectQuery & query, const ContextPtr & context) { UInt64 length = 0; UInt64 offset = 0; @@ -1033,7 +1033,7 @@ static std::pair getLimitLengthAndOffset(const ASTSelectQuery & } -UInt64 InterpreterSelectQuery::getLimitForSorting(const ASTSelectQuery & query, ContextPtr context_) +UInt64 InterpreterSelectQuery::getLimitForSorting(const ASTSelectQuery & query, const ContextPtr & context_) { /// Partial sort can be done if there is LIMIT but no DISTINCT or LIMIT BY, neither ARRAY JOIN. if (!query.distinct && !query.limitBy() && !query.limit_with_ties && !query.arrayJoinExpressionList().first && query.limitLength()) @@ -1631,7 +1631,7 @@ static void executeMergeAggregatedImpl( } void InterpreterSelectQuery::addEmptySourceToQueryPlan( - QueryPlan & query_plan, const Block & source_header, const SelectQueryInfo & query_info, ContextPtr context_) + QueryPlan & query_plan, const Block & source_header, const SelectQueryInfo & query_info, const ContextPtr & context_) { Pipe pipe(std::make_shared(source_header)); diff --git a/src/Interpreters/InterpreterSelectQuery.h b/src/Interpreters/InterpreterSelectQuery.h index 703fb588080..a95ff00bc0d 100644 --- a/src/Interpreters/InterpreterSelectQuery.h +++ b/src/Interpreters/InterpreterSelectQuery.h @@ -112,7 +112,7 @@ public: bool hasAggregation() const { return query_analyzer->hasAggregation(); } static void addEmptySourceToQueryPlan( - QueryPlan & query_plan, const Block & source_header, const SelectQueryInfo & query_info, ContextPtr context_); + QueryPlan & query_plan, const Block & source_header, const SelectQueryInfo & query_info, const ContextPtr & context_); Names getRequiredColumns() { return required_columns; } @@ -128,8 +128,8 @@ public: /// It will set shard_num and shard_count to the client_info void setProperClientInfo(size_t replica_num, size_t replica_count); - static SortDescription getSortDescription(const ASTSelectQuery & query, ContextPtr context); - static UInt64 getLimitForSorting(const ASTSelectQuery & query, ContextPtr context); + static SortDescription getSortDescription(const ASTSelectQuery & query, const ContextPtr & context); + static UInt64 getLimitForSorting(const ASTSelectQuery & query, const ContextPtr & context); private: InterpreterSelectQuery( diff --git a/src/Interpreters/evaluateConstantExpression.cpp b/src/Interpreters/evaluateConstantExpression.cpp index 039d79ed445..a5cdbf78070 100644 --- a/src/Interpreters/evaluateConstantExpression.cpp +++ b/src/Interpreters/evaluateConstantExpression.cpp @@ -42,7 +42,7 @@ static std::pair> getFieldAndDataTypeFro return {res, type}; } -std::pair> evaluateConstantExpression(const ASTPtr & node, ContextPtr context) +std::pair> evaluateConstantExpression(const ASTPtr & node, const ContextPtr & context) { if (ASTLiteral * literal = node->as()) return getFieldAndDataTypeFromLiteral(literal); @@ -105,7 +105,7 @@ std::pair> evaluateConstantExpression(co } -ASTPtr evaluateConstantExpressionAsLiteral(const ASTPtr & node, ContextPtr context) +ASTPtr evaluateConstantExpressionAsLiteral(const ASTPtr & node, const ContextPtr & context) { /// If it's already a literal. if (node->as()) @@ -113,7 +113,7 @@ ASTPtr evaluateConstantExpressionAsLiteral(const ASTPtr & node, ContextPtr conte return std::make_shared(evaluateConstantExpression(node, context).first); } -ASTPtr evaluateConstantExpressionOrIdentifierAsLiteral(const ASTPtr & node, ContextPtr context) +ASTPtr evaluateConstantExpressionOrIdentifierAsLiteral(const ASTPtr & node, const ContextPtr & context) { if (const auto * id = node->as()) return std::make_shared(id->name()); @@ -121,7 +121,7 @@ ASTPtr evaluateConstantExpressionOrIdentifierAsLiteral(const ASTPtr & node, Cont return evaluateConstantExpressionAsLiteral(node, context); } -ASTPtr evaluateConstantExpressionForDatabaseName(const ASTPtr & node, ContextPtr context) +ASTPtr evaluateConstantExpressionForDatabaseName(const ASTPtr & node, const ContextPtr & context) { ASTPtr res = evaluateConstantExpressionOrIdentifierAsLiteral(node, context); auto & literal = res->as(); diff --git a/src/Interpreters/evaluateConstantExpression.h b/src/Interpreters/evaluateConstantExpression.h index cf01e834fcd..91f3ac5dffd 100644 --- a/src/Interpreters/evaluateConstantExpression.h +++ b/src/Interpreters/evaluateConstantExpression.h @@ -22,25 +22,25 @@ using ExpressionActionsPtr = std::shared_ptr; * Throws exception if it's not a constant expression. * Quite suboptimal. */ -std::pair> evaluateConstantExpression(const ASTPtr & node, ContextPtr context); +std::pair> evaluateConstantExpression(const ASTPtr & node, const ContextPtr & context); /** Evaluate constant expression and returns ASTLiteral with its value. */ -ASTPtr evaluateConstantExpressionAsLiteral(const ASTPtr & node, ContextPtr context); +ASTPtr evaluateConstantExpressionAsLiteral(const ASTPtr & node, const ContextPtr & context); /** Evaluate constant expression and returns ASTLiteral with its value. * Also, if AST is identifier, then return string literal with its name. * Useful in places where some name may be specified as identifier, or as result of a constant expression. */ -ASTPtr evaluateConstantExpressionOrIdentifierAsLiteral(const ASTPtr & node, ContextPtr context); +ASTPtr evaluateConstantExpressionOrIdentifierAsLiteral(const ASTPtr & node, const ContextPtr & context); /** The same as evaluateConstantExpressionOrIdentifierAsLiteral(...), * but if result is an empty string, replace it with current database name * or default database name. */ -ASTPtr evaluateConstantExpressionForDatabaseName(const ASTPtr & node, ContextPtr context); +ASTPtr evaluateConstantExpressionForDatabaseName(const ASTPtr & node, const ContextPtr & context); /** Try to fold condition to countable set of constant values. * @param node a condition that we try to fold.