From ed74a464bd69fbfb81bb18afd8c5dc22f57de518 Mon Sep 17 00:00:00 2001 From: Maksim Kita Date: Wed, 16 Mar 2022 11:21:18 +0000 Subject: [PATCH] Fixed tests --- src/Common/ThreadProfileEvents.cpp | 13 +++++++------ src/Interpreters/ActionsVisitor.cpp | 3 +++ src/Interpreters/Set.cpp | 2 +- src/Interpreters/evaluateConstantExpression.cpp | 5 +++++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Common/ThreadProfileEvents.cpp b/src/Common/ThreadProfileEvents.cpp index 90a9d6ede23..e28e5d3e85e 100644 --- a/src/Common/ThreadProfileEvents.cpp +++ b/src/Common/ThreadProfileEvents.cpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include @@ -21,6 +20,8 @@ #include #include +#include + #include @@ -247,9 +248,9 @@ static_assert(sizeof(raw_events_info) / sizeof(raw_events_info[0]) == NUMBER_OF_ #undef CACHE_EVENT // A map of event name -> event index, to parse event list in settings. -static std::unordered_map populateEventMap() +static std::unordered_map populateEventMap() { - std::unordered_map name_to_index; + std::unordered_map name_to_index; name_to_index.reserve(NUMBER_OF_RAW_EVENTS); for (size_t i = 0; i < NUMBER_OF_RAW_EVENTS; ++i) @@ -455,10 +456,10 @@ std::vector PerfEventsCounters::eventIndicesFromString(const std::string return result; } + std::vector event_names; + boost::split(event_names, events_list, [](char c) { return c == ','; }); - std::istringstream iss(events_list); // STYLE_CHECK_ALLOW_STD_STRING_STREAM - std::string event_name; - while (std::getline(iss, event_name, ',')) + for (auto & event_name : event_names) { // Allow spaces at the beginning of the token, so that you can write 'a, b'. event_name.erase(0, event_name.find_first_not_of(' ')); diff --git a/src/Interpreters/ActionsVisitor.cpp b/src/Interpreters/ActionsVisitor.cpp index 99583c41b64..fb9752ae391 100644 --- a/src/Interpreters/ActionsVisitor.cpp +++ b/src/Interpreters/ActionsVisitor.cpp @@ -81,7 +81,10 @@ static Block createBlockFromCollection(const Collection & collection, const Data size_t columns_num = types.size(); MutableColumns columns(columns_num); for (size_t i = 0; i < columns_num; ++i) + { columns[i] = types[i]->createColumn(); + columns[i]->reserve(collection.size()); + } Row tuple_values; for (const auto & value : collection) diff --git a/src/Interpreters/Set.cpp b/src/Interpreters/Set.cpp index 7af3e23d0d4..224b13d2c45 100644 --- a/src/Interpreters/Set.cpp +++ b/src/Interpreters/Set.cpp @@ -165,7 +165,7 @@ void Set::setHeader(const ColumnsWithTypeAndName & header) bool Set::insertFromBlock(const ColumnsWithTypeAndName & columns) { - std::unique_lock lock(rwlock); + std::lock_guard lock(rwlock); if (data.empty()) throw Exception("Method Set::setHeader must be called before Set::insertFromBlock", ErrorCodes::LOGICAL_ERROR); diff --git a/src/Interpreters/evaluateConstantExpression.cpp b/src/Interpreters/evaluateConstantExpression.cpp index ae304906476..2928de43cc2 100644 --- a/src/Interpreters/evaluateConstantExpression.cpp +++ b/src/Interpreters/evaluateConstantExpression.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -32,6 +33,10 @@ namespace ErrorCodes std::pair> evaluateConstantExpression(const ASTPtr & node, ContextPtr context) { + if (ASTLiteral * literal = node->as()) { + return std::make_pair(literal->value, applyVisitor(FieldToDataType(), literal->value)); + } + NamesAndTypesList source_columns = {{ "_dummy", std::make_shared() }}; auto ast = node->clone(); ReplaceQueryParameterVisitor param_visitor(context->getQueryParameters());