mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 16:42:05 +00:00
Fix a bunch of warnings from PVS-Studio
This commit is contained in:
parent
f59c55abb5
commit
604daa9581
@ -40,7 +40,7 @@ void Loggers::buildLoggers(Poco::Util::AbstractConfiguration & config, Poco::Log
|
||||
split->addTextLog(log, text_log_max_priority);
|
||||
|
||||
auto current_logger = config.getString("logger", "");
|
||||
if (config_logger == current_logger)
|
||||
if (config_logger == current_logger) //-V1051
|
||||
return;
|
||||
|
||||
config_logger = current_logger;
|
||||
|
@ -77,7 +77,7 @@ auto parseLDAPServer(const Poco::Util::AbstractConfiguration & config, const Str
|
||||
if (enable_tls_lc_str == "starttls")
|
||||
params.enable_tls = LDAPClient::Params::TLSEnable::YES_STARTTLS;
|
||||
else if (config.getBool(ldap_server_config + ".enable_tls"))
|
||||
params.enable_tls = LDAPClient::Params::TLSEnable::YES;
|
||||
params.enable_tls = LDAPClient::Params::TLSEnable::YES; //-V1048
|
||||
else
|
||||
params.enable_tls = LDAPClient::Params::TLSEnable::NO;
|
||||
}
|
||||
@ -96,7 +96,7 @@ auto parseLDAPServer(const Poco::Util::AbstractConfiguration & config, const Str
|
||||
else if (tls_minimum_protocol_version_lc_str == "tls1.1")
|
||||
params.tls_minimum_protocol_version = LDAPClient::Params::TLSProtocolVersion::TLS1_1;
|
||||
else if (tls_minimum_protocol_version_lc_str == "tls1.2")
|
||||
params.tls_minimum_protocol_version = LDAPClient::Params::TLSProtocolVersion::TLS1_2;
|
||||
params.tls_minimum_protocol_version = LDAPClient::Params::TLSProtocolVersion::TLS1_2; //-V1048
|
||||
else
|
||||
throw Exception("Bad value for 'tls_minimum_protocol_version' entry, allowed values are: 'ssl2', 'ssl3', 'tls1.0', 'tls1.1', 'tls1.2'", ErrorCodes::BAD_ARGUMENTS);
|
||||
}
|
||||
@ -113,7 +113,7 @@ auto parseLDAPServer(const Poco::Util::AbstractConfiguration & config, const Str
|
||||
else if (tls_require_cert_lc_str == "try")
|
||||
params.tls_require_cert = LDAPClient::Params::TLSRequireCert::TRY;
|
||||
else if (tls_require_cert_lc_str == "demand")
|
||||
params.tls_require_cert = LDAPClient::Params::TLSRequireCert::DEMAND;
|
||||
params.tls_require_cert = LDAPClient::Params::TLSRequireCert::DEMAND; //-V1048
|
||||
else
|
||||
throw Exception("Bad value for 'tls_require_cert' entry, allowed values are: 'never', 'allow', 'try', 'demand'", ErrorCodes::BAD_ARGUMENTS);
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ GrantedRoles::Elements GrantedRoles::getElements() const
|
||||
boost::range::set_difference(roles, roles_with_admin_option, std::back_inserter(element.ids));
|
||||
if (!element.empty())
|
||||
{
|
||||
element.admin_option = false;
|
||||
element.admin_option = false; //-V1048
|
||||
elements.emplace_back(std::move(element));
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
namespace DB
|
||||
{
|
||||
|
||||
namespace
|
||||
namespace detail
|
||||
{
|
||||
|
||||
/// This function returns true if both values are large and comparable.
|
||||
@ -72,7 +72,7 @@ public:
|
||||
Float64 factor = static_cast<Float64>(count * source.count) / total_count;
|
||||
Float64 delta = mean - source.mean;
|
||||
|
||||
if (areComparable(count, source.count))
|
||||
if (detail::areComparable(count, source.count))
|
||||
mean = (source.count * source.mean + count * mean) / total_count;
|
||||
else
|
||||
mean = source.mean + delta * (static_cast<Float64>(count) / total_count);
|
||||
@ -302,7 +302,7 @@ public:
|
||||
Float64 left_delta = left_mean - source.left_mean;
|
||||
Float64 right_delta = right_mean - source.right_mean;
|
||||
|
||||
if (areComparable(count, source.count))
|
||||
if (detail::areComparable(count, source.count))
|
||||
{
|
||||
left_mean = (source.count * source.left_mean + count * left_mean) / total_count;
|
||||
right_mean = (source.count * source.right_mean + count * right_mean) / total_count;
|
||||
|
@ -82,17 +82,12 @@ template <UInt8 precision, int max_rank, typename HashValueType, typename Denomi
|
||||
DenominatorMode denominator_mode, typename Enable = void>
|
||||
class __attribute__ ((packed)) Denominator;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
/// Returns true if rank storage is big.
|
||||
constexpr bool isBigRankStore(UInt8 precision)
|
||||
{
|
||||
return precision >= 12;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// Used to deduce denominator type depending on options provided.
|
||||
template <typename HashValueType, typename DenominatorType, DenominatorMode denominator_mode, typename Enable = void>
|
||||
struct IntermediateDenominator;
|
||||
@ -120,7 +115,7 @@ struct IntermediateDenominator<HashValueType, DenominatorType, DenominatorMode::
|
||||
/// Satisfiable when rank storage is small enough.
|
||||
template <UInt8 precision, int max_rank, typename HashValueType, typename DenominatorType,
|
||||
DenominatorMode denominator_mode>
|
||||
class __attribute__ ((packed)) Denominator<precision, max_rank, HashValueType, DenominatorType,
|
||||
class __attribute__ ((packed)) details::Denominator<precision, max_rank, HashValueType, DenominatorType,
|
||||
denominator_mode,
|
||||
std::enable_if_t<!details::isBigRankStore(precision) || !(denominator_mode == DenominatorMode::StableIfBig)>>
|
||||
{
|
||||
@ -164,7 +159,7 @@ private:
|
||||
/// Used when rank storage is big.
|
||||
template <UInt8 precision, int max_rank, typename HashValueType, typename DenominatorType,
|
||||
DenominatorMode denominator_mode>
|
||||
class __attribute__ ((packed)) Denominator<precision, max_rank, HashValueType, DenominatorType,
|
||||
class __attribute__ ((packed)) details::Denominator<precision, max_rank, HashValueType, DenominatorType,
|
||||
denominator_mode,
|
||||
std::enable_if_t<details::isBigRankStore(precision) && denominator_mode == DenominatorMode::StableIfBig>>
|
||||
{
|
||||
@ -252,6 +247,7 @@ struct RankWidth<UInt64>
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// Sets behavior of HyperLogLog class.
|
||||
enum class HyperLogLogMode
|
||||
{
|
||||
|
@ -388,7 +388,7 @@ void PoolWithFailoverBase<TNestedPool>::updateErrorCounts(PoolWithFailoverBase<T
|
||||
{
|
||||
time_t current_time = time(nullptr);
|
||||
|
||||
if (last_decrease_time)
|
||||
if (last_decrease_time) //-V1051
|
||||
{
|
||||
time_t delta = current_time - last_decrease_time;
|
||||
|
||||
|
@ -198,7 +198,7 @@ std::pair<ResponsePtr, Undo> TestKeeperCreateRequest::process(TestKeeper::Contai
|
||||
else
|
||||
{
|
||||
TestKeeper::Node created_node;
|
||||
created_node.seq_num = 0;
|
||||
created_node.seq_num = 0; //-V1044
|
||||
created_node.stat.czxid = zxid;
|
||||
created_node.stat.mzxid = zxid;
|
||||
created_node.stat.ctime = std::chrono::system_clock::now().time_since_epoch() / std::chrono::milliseconds(1);
|
||||
@ -271,7 +271,7 @@ std::pair<ResponsePtr, Undo> TestKeeperRemoveRequest::process(TestKeeper::Contai
|
||||
auto & parent = container.at(parentPath(path));
|
||||
--parent.stat.numChildren;
|
||||
++parent.stat.cversion;
|
||||
response.error = Error::ZOK;
|
||||
response.error = Error::ZOK; //-V1044
|
||||
|
||||
undo = [prev_node, &container, path = path]
|
||||
{
|
||||
@ -293,7 +293,7 @@ std::pair<ResponsePtr, Undo> TestKeeperExistsRequest::process(TestKeeper::Contai
|
||||
if (it != container.end())
|
||||
{
|
||||
response.stat = it->second.stat;
|
||||
response.error = Error::ZOK;
|
||||
response.error = Error::ZOK; //-V1044
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -316,7 +316,7 @@ std::pair<ResponsePtr, Undo> TestKeeperGetRequest::process(TestKeeper::Container
|
||||
{
|
||||
response.stat = it->second.stat;
|
||||
response.data = it->second.data;
|
||||
response.error = Error::ZOK;
|
||||
response.error = Error::ZOK; //-V1044
|
||||
}
|
||||
|
||||
return { std::make_shared<GetResponse>(response), {} };
|
||||
@ -343,7 +343,7 @@ std::pair<ResponsePtr, Undo> TestKeeperSetRequest::process(TestKeeper::Container
|
||||
it->second.data = data;
|
||||
++container.at(parentPath(path)).stat.cversion;
|
||||
response.stat = it->second.stat;
|
||||
response.error = Error::ZOK;
|
||||
response.error = Error::ZOK; //-V1044
|
||||
|
||||
undo = [prev_node, &container, path = path]
|
||||
{
|
||||
@ -387,7 +387,7 @@ std::pair<ResponsePtr, Undo> TestKeeperListRequest::process(TestKeeper::Containe
|
||||
}
|
||||
|
||||
response.stat = it->second.stat;
|
||||
response.error = Error::ZOK;
|
||||
response.error = Error::ZOK; //-V1044
|
||||
}
|
||||
|
||||
return { std::make_shared<ListResponse>(response), {} };
|
||||
@ -407,7 +407,7 @@ std::pair<ResponsePtr, Undo> TestKeeperCheckRequest::process(TestKeeper::Contain
|
||||
}
|
||||
else
|
||||
{
|
||||
response.error = Error::ZOK;
|
||||
response.error = Error::ZOK; //-V1044
|
||||
}
|
||||
|
||||
return { std::make_shared<CheckResponse>(response), {} };
|
||||
@ -422,7 +422,7 @@ std::pair<ResponsePtr, Undo> TestKeeperMultiRequest::process(TestKeeper::Contain
|
||||
try
|
||||
{
|
||||
auto request_it = requests.begin();
|
||||
response.error = Error::ZOK;
|
||||
response.error = Error::ZOK; //-V1044
|
||||
while (request_it != requests.end())
|
||||
{
|
||||
const TestKeeperRequest & concrete_request = dynamic_cast<const TestKeeperRequest &>(**request_it);
|
||||
|
@ -79,7 +79,6 @@ std::filesystem::path getMountPoint(std::filesystem::path absolute_path)
|
||||
if (device_id != parent_device_id)
|
||||
return absolute_path;
|
||||
absolute_path = parent;
|
||||
device_id = parent_device_id;
|
||||
}
|
||||
|
||||
return absolute_path;
|
||||
|
@ -35,29 +35,6 @@
|
||||
|
||||
using namespace DB;
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <typename T>
|
||||
std::ostream & operator<<(std::ostream & ostr, const std::optional<T> & opt)
|
||||
{
|
||||
if (!opt)
|
||||
{
|
||||
return ostr << "<empty optional>";
|
||||
}
|
||||
|
||||
return ostr << *opt;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::vector<T> operator+(std::vector<T> && left, std::vector<T> && right)
|
||||
{
|
||||
std::vector<T> result(std::move(left));
|
||||
std::move(std::begin(right), std::end(right), std::back_inserter(result));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -337,6 +314,14 @@ CodecTestSequence operator+(CodecTestSequence && left, const CodecTestSequence &
|
||||
return left.append(right);
|
||||
}
|
||||
|
||||
std::vector<CodecTestSequence> operator+(const std::vector<CodecTestSequence> & left, const std::vector<CodecTestSequence> & right)
|
||||
{
|
||||
std::vector<CodecTestSequence> result(std::move(left));
|
||||
std::move(std::begin(right), std::end(right), std::back_inserter(result));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
CodecTestSequence operator*(CodecTestSequence && left, T times)
|
||||
{
|
||||
@ -362,7 +347,7 @@ std::ostream & operator<<(std::ostream & ostr, const Codec & codec)
|
||||
{
|
||||
return ostr << "Codec{"
|
||||
<< "name: " << codec.codec_statement
|
||||
<< ", expected_compression_ratio: " << codec.expected_compression_ratio
|
||||
<< ", expected_compression_ratio: " << *codec.expected_compression_ratio
|
||||
<< "}";
|
||||
}
|
||||
|
||||
@ -775,15 +760,13 @@ auto FFand0Generator = []()
|
||||
return [step = 0](auto i) mutable
|
||||
{
|
||||
decltype(i) result;
|
||||
if (step++ % 2 == 0)
|
||||
{
|
||||
memset(&result, 0, sizeof(result));
|
||||
}
|
||||
else
|
||||
{
|
||||
memset(&result, 0xFF, sizeof(result));
|
||||
}
|
||||
|
||||
if (step % 2 == 0)
|
||||
memset(&result, 0, sizeof(result));
|
||||
else
|
||||
memset(&result, 0xFF, sizeof(result));
|
||||
|
||||
++step;
|
||||
return result;
|
||||
};
|
||||
};
|
||||
|
@ -158,7 +158,7 @@ public:
|
||||
|
||||
/** Set the approximate total number of rows to read.
|
||||
*/
|
||||
virtual void addTotalRowsApprox(size_t value) { total_rows_approx += value; }
|
||||
void addTotalRowsApprox(size_t value) { total_rows_approx += value; }
|
||||
|
||||
|
||||
/** Ask to abort the receipt of data as soon as possible.
|
||||
|
@ -51,7 +51,7 @@ static void writeData(const IDataType & type, const ColumnPtr & column, WriteBuf
|
||||
ISerialization::SerializeBinaryBulkSettings settings;
|
||||
settings.getter = [&ostr](ISerialization::SubstreamPath) -> WriteBuffer * { return &ostr; };
|
||||
settings.position_independent_encoding = false;
|
||||
settings.low_cardinality_max_dictionary_size = 0;
|
||||
settings.low_cardinality_max_dictionary_size = 0; //-V1048
|
||||
|
||||
auto serialization = type.getDefaultSerialization();
|
||||
|
||||
|
@ -210,7 +210,8 @@ void PostgreSQLBlockInputStream::insertValue(IColumn & column, std::string_view
|
||||
{
|
||||
max_dimension = std::max(max_dimension, dimension);
|
||||
|
||||
if (--dimension == 0)
|
||||
--dimension;
|
||||
if (dimension == 0)
|
||||
break;
|
||||
|
||||
dimensions[dimension].emplace_back(Array(dimensions[dimension + 1].begin(), dimensions[dimension + 1].end()));
|
||||
|
@ -15,8 +15,6 @@
|
||||
|
||||
#include <Core/iostream_debug_helpers.h>
|
||||
|
||||
namespace std
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
inline std::ostream& operator<<(std::ostream & ostr, const std::vector<T> & v)
|
||||
@ -29,8 +27,6 @@ inline std::ostream& operator<<(std::ostream & ostr, const std::vector<T> & v)
|
||||
return ostr << "] (" << v.size() << ") items";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
using namespace DB;
|
||||
|
||||
struct ParseDataTypeTestCase
|
||||
|
@ -84,7 +84,7 @@ public:
|
||||
{
|
||||
size_t language_id = static_cast<size_t>(language);
|
||||
|
||||
if (region_id >= names_refs[language_id].size())
|
||||
if (region_id >= names_refs[language_id].size()) //-V1051
|
||||
return StringRef("", 0);
|
||||
|
||||
StringRef ref = names_refs[language_id][region_id];
|
||||
|
@ -164,7 +164,7 @@ bool MySQLDictionarySource::isModified() const
|
||||
if (!invalidate_query.empty())
|
||||
{
|
||||
auto response = doInvalidateQuery(invalidate_query);
|
||||
if (response == invalidate_query_response)
|
||||
if (response == invalidate_query_response) //-V1051
|
||||
return false;
|
||||
invalidate_query_response = response;
|
||||
return true;
|
||||
|
@ -103,7 +103,7 @@ bool PostgreSQLDictionarySource::isModified() const
|
||||
if (!invalidate_query.empty())
|
||||
{
|
||||
auto response = doInvalidateQuery(invalidate_query);
|
||||
if (response == invalidate_query_response)
|
||||
if (response == invalidate_query_response) //-V1051
|
||||
return false;
|
||||
invalidate_query_response = response;
|
||||
}
|
||||
|
@ -225,7 +225,7 @@ bool XDBCDictionarySource::isModified() const
|
||||
if (!invalidate_query.empty())
|
||||
{
|
||||
auto response = doInvalidateQuery(invalidate_query);
|
||||
if (invalidate_query_response == response)
|
||||
if (invalidate_query_response == response) //-V1051
|
||||
return false;
|
||||
invalidate_query_response = response;
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ public:
|
||||
if (!outlen)
|
||||
{
|
||||
outlen = 0;
|
||||
dst_pos = savepoint;
|
||||
dst_pos = savepoint; //-V1048
|
||||
// clean the symbol
|
||||
dst_pos[0] = 0;
|
||||
}
|
||||
|
@ -277,7 +277,7 @@ SOFTWARE.
|
||||
len -= 16;
|
||||
};
|
||||
|
||||
while (len >= 16) // NOLINT
|
||||
while (len >= 16) // NOLINT //-V1044
|
||||
check_packed(_mm_loadu_si128(reinterpret_cast<const __m128i *>(data)));
|
||||
|
||||
/// 0 <= len <= 15 for now. Reading data from data - 1 because of right padding of 15 and left padding
|
||||
|
186
src/Interpreters/ConvertStringsToEnumVisitor.cpp
Normal file
186
src/Interpreters/ConvertStringsToEnumVisitor.cpp
Normal file
@ -0,0 +1,186 @@
|
||||
#include <Interpreters/ConvertStringsToEnumVisitor.h>
|
||||
#include <Parsers/ASTFunction.h>
|
||||
#include <Parsers/ASTLiteral.h>
|
||||
#include <Parsers/IAST.h>
|
||||
#include <Common/typeid_cast.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
/// @note We place strings in ascending order here under the assumption it colud speed up String to Enum conversion.
|
||||
String makeStringsEnum(const std::set<String> & values)
|
||||
{
|
||||
String enum_string = "Enum8(";
|
||||
if (values.size() >= 255)
|
||||
enum_string = "Enum16(";
|
||||
|
||||
size_t number = 1;
|
||||
for (const auto & item : values)
|
||||
{
|
||||
enum_string += "\'" + item + "\' = " + std::to_string(number++);
|
||||
|
||||
if (number <= values.size())
|
||||
enum_string += ", ";
|
||||
}
|
||||
|
||||
enum_string += ")";
|
||||
return enum_string;
|
||||
}
|
||||
|
||||
void changeIfArguments(ASTPtr & first, ASTPtr & second)
|
||||
{
|
||||
String first_value = first->as<ASTLiteral>()->value.get<String>();
|
||||
String second_value = second->as<ASTLiteral>()->value.get<String>();
|
||||
|
||||
std::set<String> values;
|
||||
values.insert(first_value);
|
||||
values.insert(second_value);
|
||||
|
||||
String enum_string = makeStringsEnum(values);
|
||||
auto enum_literal = std::make_shared<ASTLiteral>(enum_string);
|
||||
|
||||
auto first_cast = makeASTFunction("CAST");
|
||||
first_cast->arguments->children.push_back(first);
|
||||
first_cast->arguments->children.push_back(enum_literal);
|
||||
|
||||
auto second_cast = makeASTFunction("CAST");
|
||||
second_cast->arguments->children.push_back(second);
|
||||
second_cast->arguments->children.push_back(enum_literal);
|
||||
|
||||
first = first_cast;
|
||||
second = second_cast;
|
||||
}
|
||||
|
||||
void changeTransformArguments(ASTPtr & array_to, ASTPtr & other)
|
||||
{
|
||||
std::set<String> values;
|
||||
|
||||
for (const auto & item : array_to->as<ASTLiteral>()->value.get<Array>())
|
||||
values.insert(item.get<String>());
|
||||
values.insert(other->as<ASTLiteral>()->value.get<String>());
|
||||
|
||||
String enum_string = makeStringsEnum(values);
|
||||
|
||||
auto array_cast = makeASTFunction("CAST");
|
||||
array_cast->arguments->children.push_back(array_to);
|
||||
array_cast->arguments->children.push_back(std::make_shared<ASTLiteral>("Array(" + enum_string + ")"));
|
||||
array_to = array_cast;
|
||||
|
||||
auto other_cast = makeASTFunction("CAST");
|
||||
other_cast->arguments->children.push_back(other);
|
||||
other_cast->arguments->children.push_back(std::make_shared<ASTLiteral>(enum_string));
|
||||
other = other_cast;
|
||||
}
|
||||
|
||||
bool checkSameType(const Array & array, const String & type)
|
||||
{
|
||||
for (const auto & item : array)
|
||||
if (item.getTypeName() != type)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool FindUsedFunctionsMatcher::needChildVisit(const ASTPtr & node, const ASTPtr &)
|
||||
{
|
||||
return !(node->as<ASTFunction>());
|
||||
}
|
||||
|
||||
void FindUsedFunctionsMatcher::visit(const ASTPtr & ast, Data & data)
|
||||
{
|
||||
if (auto * func = ast->as<ASTFunction>())
|
||||
visit(*func, data);
|
||||
}
|
||||
|
||||
void FindUsedFunctionsMatcher::visit(const ASTFunction & func, Data & data)
|
||||
{
|
||||
if (data.names.count(func.name) && !data.call_stack.empty())
|
||||
{
|
||||
String alias = func.tryGetAlias();
|
||||
if (!alias.empty())
|
||||
{
|
||||
data.used_functions.insert(alias);
|
||||
}
|
||||
}
|
||||
|
||||
data.call_stack.push_back(func.name);
|
||||
|
||||
/// Visit children with known call stack
|
||||
Visitor(data).visit(func.arguments);
|
||||
|
||||
data.call_stack.pop_back();
|
||||
}
|
||||
|
||||
|
||||
bool ConvertStringsToEnumMatcher::needChildVisit(const ASTPtr & node, const ASTPtr &)
|
||||
{
|
||||
return !(node->as<ASTFunction>());
|
||||
}
|
||||
|
||||
void ConvertStringsToEnumMatcher::visit(ASTPtr & ast, Data & data)
|
||||
{
|
||||
if (auto * func = ast->as<ASTFunction>())
|
||||
visit(*func, data);
|
||||
}
|
||||
|
||||
void ConvertStringsToEnumMatcher::visit(ASTFunction & function_node, Data & data)
|
||||
{
|
||||
if (!function_node.arguments)
|
||||
return;
|
||||
|
||||
/// We are not sure we could change the type of function result
|
||||
/// cause it is present in other function as argument
|
||||
if (data.used_functions.count(function_node.tryGetAlias()))
|
||||
return;
|
||||
|
||||
if (function_node.name == "if")
|
||||
{
|
||||
if (function_node.arguments->children.size() != 2)
|
||||
return;
|
||||
|
||||
auto literal1 = function_node.arguments->children[1]->as<ASTLiteral>();
|
||||
auto literal2 = function_node.arguments->children[2]->as<ASTLiteral>();
|
||||
if (!literal1 || !literal2)
|
||||
return;
|
||||
|
||||
if (String(literal1->value.getTypeName()) != "String" ||
|
||||
String(literal2->value.getTypeName()) != "String")
|
||||
return;
|
||||
|
||||
changeIfArguments(function_node.arguments->children[1],
|
||||
function_node.arguments->children[2]);
|
||||
}
|
||||
else if (function_node.name == "transform")
|
||||
{
|
||||
if (function_node.arguments->children.size() != 4)
|
||||
return;
|
||||
|
||||
auto literal_to = function_node.arguments->children[2]->as<ASTLiteral>();
|
||||
auto literal_other = function_node.arguments->children[3]->as<ASTLiteral>();
|
||||
if (!literal_to || !literal_other)
|
||||
return;
|
||||
|
||||
if (String(literal_to->value.getTypeName()) != "Array" ||
|
||||
String(literal_other->value.getTypeName()) != "String")
|
||||
return;
|
||||
|
||||
Array array_to = literal_to->value.get<Array>();
|
||||
if (array_to.size() == 0)
|
||||
return;
|
||||
|
||||
bool to_strings = checkSameType(array_to, "String");
|
||||
if (!to_strings)
|
||||
return;
|
||||
|
||||
changeTransformArguments(function_node.arguments->children[2], function_node.arguments->children[3]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,98 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <Functions/FunctionFactory.h>
|
||||
#include <IO/WriteHelpers.h>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
#include <Interpreters/InDepthNodeVisitor.h>
|
||||
#include <Parsers/ASTFunction.h>
|
||||
#include <Parsers/ASTLiteral.h>
|
||||
#include <Parsers/ASTSelectQuery.h>
|
||||
#include <Parsers/ASTSetQuery.h>
|
||||
#include <Parsers/ASTTablesInSelectQuery.h>
|
||||
#include <Parsers/ASTWithAlias.h>
|
||||
#include <Parsers/ASTExpressionList.h>
|
||||
#include <Parsers/IAST.h>
|
||||
#include <Common/typeid_cast.h>
|
||||
#include <Parsers/IAST_fwd.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
/// @note We place strings in ascending order here under the assumption it colud speed up String to Enum conversion.
|
||||
String makeStringsEnum(const std::set<String> & values)
|
||||
{
|
||||
String enum_string = "Enum8(";
|
||||
if (values.size() >= 255)
|
||||
enum_string = "Enum16(";
|
||||
|
||||
size_t number = 1;
|
||||
for (const auto & item : values)
|
||||
{
|
||||
enum_string += "\'" + item + "\' = " + std::to_string(number++);
|
||||
|
||||
if (number <= values.size())
|
||||
enum_string += ", ";
|
||||
}
|
||||
|
||||
enum_string += ")";
|
||||
return enum_string;
|
||||
}
|
||||
|
||||
void changeIfArguments(ASTPtr & first, ASTPtr & second)
|
||||
{
|
||||
String first_value = first->as<ASTLiteral>()->value.get<String>();
|
||||
String second_value = second->as<ASTLiteral>()->value.get<String>();
|
||||
|
||||
std::set<String> values;
|
||||
values.insert(first_value);
|
||||
values.insert(second_value);
|
||||
|
||||
String enum_string = makeStringsEnum(values);
|
||||
auto enum_literal = std::make_shared<ASTLiteral>(enum_string);
|
||||
|
||||
auto first_cast = makeASTFunction("CAST");
|
||||
first_cast->arguments->children.push_back(first);
|
||||
first_cast->arguments->children.push_back(enum_literal);
|
||||
|
||||
auto second_cast = makeASTFunction("CAST");
|
||||
second_cast->arguments->children.push_back(second);
|
||||
second_cast->arguments->children.push_back(enum_literal);
|
||||
|
||||
first = first_cast;
|
||||
second = second_cast;
|
||||
}
|
||||
|
||||
void changeTransformArguments(ASTPtr & array_to, ASTPtr & other)
|
||||
{
|
||||
std::set<String> values;
|
||||
|
||||
for (const auto & item : array_to->as<ASTLiteral>()->value.get<Array>())
|
||||
values.insert(item.get<String>());
|
||||
values.insert(other->as<ASTLiteral>()->value.get<String>());
|
||||
|
||||
String enum_string = makeStringsEnum(values);
|
||||
|
||||
auto array_cast = makeASTFunction("CAST");
|
||||
array_cast->arguments->children.push_back(array_to);
|
||||
array_cast->arguments->children.push_back(std::make_shared<ASTLiteral>("Array(" + enum_string + ")"));
|
||||
array_to = array_cast;
|
||||
|
||||
auto other_cast = makeASTFunction("CAST");
|
||||
other_cast->arguments->children.push_back(other);
|
||||
other_cast->arguments->children.push_back(std::make_shared<ASTLiteral>(enum_string));
|
||||
other = other_cast;
|
||||
}
|
||||
|
||||
bool checkSameType(const Array & array, const String & type)
|
||||
{
|
||||
for (const auto & item : array)
|
||||
if (item.getTypeName() != type)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
class ASTFunction;
|
||||
|
||||
struct FindUsedFunctionsMatcher
|
||||
{
|
||||
@ -105,35 +24,9 @@ struct FindUsedFunctionsMatcher
|
||||
std::vector<String> call_stack = {};
|
||||
};
|
||||
|
||||
static bool needChildVisit(const ASTPtr & node, const ASTPtr &)
|
||||
{
|
||||
return !(node->as<ASTFunction>());
|
||||
}
|
||||
|
||||
static void visit(const ASTPtr & ast, Data & data)
|
||||
{
|
||||
if (auto * func = ast->as<ASTFunction>())
|
||||
visit(*func, data);
|
||||
}
|
||||
|
||||
static void visit(const ASTFunction & func, Data & data)
|
||||
{
|
||||
if (data.names.count(func.name) && !data.call_stack.empty())
|
||||
{
|
||||
String alias = func.tryGetAlias();
|
||||
if (!alias.empty())
|
||||
{
|
||||
data.used_functions.insert(alias);
|
||||
}
|
||||
}
|
||||
|
||||
data.call_stack.push_back(func.name);
|
||||
|
||||
/// Visit children with known call stack
|
||||
Visitor(data).visit(func.arguments);
|
||||
|
||||
data.call_stack.pop_back();
|
||||
}
|
||||
static bool needChildVisit(const ASTPtr & node, const ASTPtr &);
|
||||
static void visit(const ASTPtr & ast, Data & data);
|
||||
static void visit(const ASTFunction & func, Data & data);
|
||||
};
|
||||
|
||||
using FindUsedFunctionsVisitor = FindUsedFunctionsMatcher::Visitor;
|
||||
@ -145,70 +38,9 @@ struct ConvertStringsToEnumMatcher
|
||||
std::unordered_set<String> & used_functions;
|
||||
};
|
||||
|
||||
static bool needChildVisit(const ASTPtr & node, const ASTPtr &)
|
||||
{
|
||||
return !(node->as<ASTFunction>());
|
||||
}
|
||||
|
||||
static void visit(ASTPtr & ast, Data & data)
|
||||
{
|
||||
if (auto * func = ast->as<ASTFunction>())
|
||||
visit(*func, data);
|
||||
}
|
||||
|
||||
static void visit(ASTFunction & function_node, Data & data)
|
||||
{
|
||||
if (!function_node.arguments)
|
||||
return;
|
||||
|
||||
/// We are not sure we could change the type of function result
|
||||
/// cause it is present in other function as argument
|
||||
if (data.used_functions.count(function_node.tryGetAlias()))
|
||||
return;
|
||||
|
||||
if (function_node.name == "if")
|
||||
{
|
||||
if (function_node.arguments->children.size() != 2)
|
||||
return;
|
||||
|
||||
auto literal1 = function_node.arguments->children[1]->as<ASTLiteral>();
|
||||
auto literal2 = function_node.arguments->children[2]->as<ASTLiteral>();
|
||||
if (!literal1 || !literal2)
|
||||
return;
|
||||
|
||||
if (String(literal1->value.getTypeName()) != "String" ||
|
||||
String(literal2->value.getTypeName()) != "String")
|
||||
return;
|
||||
|
||||
changeIfArguments(function_node.arguments->children[1],
|
||||
function_node.arguments->children[2]);
|
||||
}
|
||||
else if (function_node.name == "transform")
|
||||
{
|
||||
if (function_node.arguments->children.size() != 4)
|
||||
return;
|
||||
|
||||
auto literal_to = function_node.arguments->children[2]->as<ASTLiteral>();
|
||||
auto literal_other = function_node.arguments->children[3]->as<ASTLiteral>();
|
||||
if (!literal_to || !literal_other)
|
||||
return;
|
||||
|
||||
if (String(literal_to->value.getTypeName()) != "Array" ||
|
||||
String(literal_other->value.getTypeName()) != "String")
|
||||
return;
|
||||
|
||||
Array array_to = literal_to->value.get<Array>();
|
||||
if (array_to.size() == 0)
|
||||
return;
|
||||
|
||||
bool to_strings = checkSameType(array_to, "String");
|
||||
if (!to_strings)
|
||||
return;
|
||||
|
||||
changeTransformArguments(function_node.arguments->children[2],
|
||||
function_node.arguments->children[3]);
|
||||
}
|
||||
}
|
||||
static bool needChildVisit(const ASTPtr & node, const ASTPtr &);
|
||||
static void visit(ASTPtr & ast, Data & data);
|
||||
static void visit(ASTFunction & function_node, Data & data);
|
||||
};
|
||||
|
||||
using ConvertStringsToEnumVisitor = InDepthNodeVisitor<ConvertStringsToEnumMatcher, true>;
|
||||
|
@ -77,7 +77,7 @@ BlockIO InterpreterWatchQuery::execute()
|
||||
if (IBlockInputStream * stream = dynamic_cast<IBlockInputStream *>(streams[0].get()))
|
||||
{
|
||||
StreamLocalLimits limits;
|
||||
limits.mode = LimitsMode::LIMITS_CURRENT;
|
||||
limits.mode = LimitsMode::LIMITS_CURRENT; //-V1048
|
||||
limits.size_limits.max_rows = settings.max_result_rows;
|
||||
limits.size_limits.max_bytes = settings.max_result_bytes;
|
||||
limits.size_limits.overflow_mode = settings.result_overflow_mode;
|
||||
|
@ -143,7 +143,7 @@ bool PartLog::addNewParts(
|
||||
if (query_id.data && query_id.size)
|
||||
elem.query_id.insert(0, query_id.data, query_id.size);
|
||||
|
||||
elem.event_type = PartLogElement::NEW_PART;
|
||||
elem.event_type = PartLogElement::NEW_PART; //-V1048
|
||||
|
||||
// construct event_time and event_time_microseconds using the same time point
|
||||
// so that the two times will always be equal up to a precision of a second.
|
||||
|
@ -552,7 +552,7 @@ static std::tuple<ASTPtr, BlockIO> executeQueryImpl(
|
||||
StreamLocalLimits limits;
|
||||
if (!interpreter->ignoreLimits())
|
||||
{
|
||||
limits.mode = LimitsMode::LIMITS_CURRENT;
|
||||
limits.mode = LimitsMode::LIMITS_CURRENT; //-V1048
|
||||
limits.size_limits = SizeLimits(settings.max_result_rows, settings.max_result_bytes, settings.result_overflow_mode);
|
||||
}
|
||||
|
||||
@ -632,7 +632,7 @@ static std::tuple<ASTPtr, BlockIO> executeQueryImpl(
|
||||
{
|
||||
QueryLogElement elem;
|
||||
|
||||
elem.type = QueryLogElementType::QUERY_START;
|
||||
elem.type = QueryLogElementType::QUERY_START; //-V1048
|
||||
|
||||
elem.event_time = time_in_seconds(current_time);
|
||||
elem.event_time_microseconds = time_in_microseconds(current_time);
|
||||
|
@ -281,7 +281,7 @@ void createMissedColumns(Block & block)
|
||||
for (size_t i = 0; i < block.columns(); ++i)
|
||||
{
|
||||
auto & column = block.getByPosition(i);
|
||||
if (!column.column)
|
||||
if (!column.column) //-V1051
|
||||
column.column = column.type->createColumn();
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ bool ParserExplainQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected
|
||||
else if (s_pipeline.ignore(pos, expected))
|
||||
kind = ASTExplainQuery::ExplainKind::QueryPipeline;
|
||||
else if (s_plan.ignore(pos, expected))
|
||||
kind = ASTExplainQuery::ExplainKind::QueryPlan;
|
||||
kind = ASTExplainQuery::ExplainKind::QueryPlan; //-V1048
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
@ -121,11 +121,4 @@ void PipelineExecutingBlockInputStream::setQuota(const std::shared_ptr<const Ena
|
||||
ErrorCodes::LOGICAL_ERROR);
|
||||
}
|
||||
|
||||
void PipelineExecutingBlockInputStream::addTotalRowsApprox(size_t)
|
||||
{
|
||||
throw Exception("Progress is not supported by PipelineExecutingBlockInputStream",
|
||||
ErrorCodes::LOGICAL_ERROR);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -26,7 +26,6 @@ public:
|
||||
void setProcessListElement(QueryStatus * elem) final;
|
||||
void setLimits(const StreamLocalLimits & limits_) final;
|
||||
void setQuota(const std::shared_ptr<const EnabledQuota> & quota_) final;
|
||||
void addTotalRowsApprox(size_t value) final;
|
||||
|
||||
protected:
|
||||
void readPrefixImpl() override;
|
||||
|
@ -135,7 +135,7 @@ public:
|
||||
{
|
||||
auto num_threads = pipe.maxParallelStreams();
|
||||
|
||||
if (max_threads)
|
||||
if (max_threads) //-V1051
|
||||
num_threads = std::min(num_threads, max_threads);
|
||||
|
||||
return std::max<size_t>(1, num_threads);
|
||||
|
@ -58,7 +58,7 @@ void PartialSortingStep::transformPipeline(QueryPipeline & pipeline, const Build
|
||||
});
|
||||
|
||||
StreamLocalLimits limits;
|
||||
limits.mode = LimitsMode::LIMITS_CURRENT;
|
||||
limits.mode = LimitsMode::LIMITS_CURRENT; //-V1048
|
||||
limits.size_limits = size_limits;
|
||||
|
||||
pipeline.addSimpleTransform([&](const Block & header, QueryPipeline::StreamType stream_type) -> ProcessorPtr
|
||||
|
@ -158,7 +158,7 @@ QueryPipelinePtr QueryPlan::buildQueryPipeline(
|
||||
if (last_pipeline)
|
||||
{
|
||||
frame.pipelines.emplace_back(std::move(last_pipeline));
|
||||
last_pipeline = nullptr;
|
||||
last_pipeline = nullptr; //-V1048
|
||||
}
|
||||
|
||||
size_t next_child = frame.pipelines.size();
|
||||
|
@ -745,7 +745,7 @@ void TCPHandler::processTablesStatusRequest()
|
||||
status.absolute_delay = replicated_table->getAbsoluteDelay();
|
||||
}
|
||||
else
|
||||
status.is_replicated = false;
|
||||
status.is_replicated = false; //-V1048
|
||||
|
||||
response.table_states_by_id.emplace(table_name, std::move(status));
|
||||
}
|
||||
|
@ -1179,7 +1179,7 @@ void MergeTreeData::removePartsFinally(const MergeTreeData::DataPartsVector & pa
|
||||
|
||||
part_log_elem.event_type = PartLogElement::REMOVE_PART;
|
||||
part_log_elem.event_time = time(nullptr);
|
||||
part_log_elem.duration_ms = 0;
|
||||
part_log_elem.duration_ms = 0; //-V1048
|
||||
|
||||
part_log_elem.database_name = table_id.database_name;
|
||||
part_log_elem.table_name = table_id.table_name;
|
||||
|
@ -114,8 +114,8 @@ void writeColumnSingleGranule(
|
||||
ISerialization::SerializeBinaryBulkSettings serialize_settings;
|
||||
|
||||
serialize_settings.getter = stream_getter;
|
||||
serialize_settings.position_independent_encoding = true;
|
||||
serialize_settings.low_cardinality_max_dictionary_size = 0;
|
||||
serialize_settings.position_independent_encoding = true; //-V1048
|
||||
serialize_settings.low_cardinality_max_dictionary_size = 0; //-V1048
|
||||
|
||||
serialization->serializeBinaryBulkStatePrefix(serialize_settings, state);
|
||||
serialization->serializeBinaryBulkWithMultipleStreams(*column.column, from_row, number_of_rows, serialize_settings, state);
|
||||
|
@ -69,7 +69,7 @@ void MergeTreeIndexGranuleSet::serializeBinary(WriteBuffer & ostr) const
|
||||
ISerialization::SerializeBinaryBulkSettings settings;
|
||||
settings.getter = [&ostr](ISerialization::SubstreamPath) -> WriteBuffer * { return &ostr; };
|
||||
settings.position_independent_encoding = false;
|
||||
settings.low_cardinality_max_dictionary_size = 0;
|
||||
settings.low_cardinality_max_dictionary_size = 0; //-V1048
|
||||
|
||||
auto serialization = type->getDefaultSerialization();
|
||||
ISerialization::SerializeBinaryBulkStatePtr state;
|
||||
|
@ -401,7 +401,7 @@ void StorageRabbitMQ::bindExchange()
|
||||
}
|
||||
}
|
||||
|
||||
while (!binding_created)
|
||||
while (!binding_created) //-V1044
|
||||
{
|
||||
event_handler->iterateLoop();
|
||||
}
|
||||
@ -462,7 +462,7 @@ void StorageRabbitMQ::bindQueue(size_t queue_id)
|
||||
const String queue_name = !hash_exchange ? queue_base : std::to_string(queue_id) + "_" + queue_base;
|
||||
setup_channel->declareQueue(queue_name, AMQP::durable, queue_settings).onSuccess(success_callback).onError(error_callback);
|
||||
|
||||
while (!binding_created)
|
||||
while (!binding_created) //-V1044
|
||||
{
|
||||
event_handler->iterateLoop();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user