Merge pull request #30917 from ClickHouse/miscellaneous

Miscellaneous
This commit is contained in:
alexey-milovidov 2021-11-01 00:44:16 +03:00 committed by GitHub
commit e879c510b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 18 deletions

View File

@ -2,6 +2,7 @@
#include <iostream>
#include <iomanip>
#include <string_view>
#include <filesystem>
#include <base/argsToConfig.h>
@ -52,6 +53,7 @@
#include <Client/InternalTextLogs.h>
namespace fs = std::filesystem;
using namespace std::literals;
namespace DB
@ -1488,7 +1490,7 @@ void ClientBase::readArguments(int argc, char ** argv, Arguments & common_argume
{
const char * arg = argv[arg_num];
if (0 == strcmp(arg, "--external"))
if (arg == "--external"sv)
{
in_external_group = true;
external_tables_arguments.emplace_back(Arguments{""});
@ -1503,8 +1505,8 @@ void ClientBase::readArguments(int argc, char ** argv, Arguments & common_argume
}
/// Options with value after whitespace.
else if (in_external_group
&& (0 == strcmp(arg, "--file") || 0 == strcmp(arg, "--name") || 0 == strcmp(arg, "--format")
|| 0 == strcmp(arg, "--structure") || 0 == strcmp(arg, "--types")))
&& (arg == "--file"sv || arg == "--name"sv || arg == "--format"sv
|| arg == "--structure"sv || arg == "--types"sv))
{
if (arg_num + 1 < argc)
{

View File

@ -1,11 +1,14 @@
#include <string.h>
#include "clearPasswordFromCommandLine.h"
#include <string_view>
#include <Common/clearPasswordFromCommandLine.h>
using namespace std::literals;
void clearPasswordFromCommandLine(int argc, char ** argv)
{
for (int arg = 1; arg < argc; ++arg)
{
if (arg + 1 < argc && 0 == strcmp(argv[arg], "--password"))
if (arg + 1 < argc && argv[arg] == "--password"sv)
{
++arg;
memset(argv[arg], 0, strlen(argv[arg]));

View File

@ -13,6 +13,10 @@
#include <DataTypes/DataTypesNumber.h>
#include <Poco/String.h>
#include <string_view>
using namespace std::literals;
namespace DB
{
@ -58,15 +62,15 @@ std::shared_ptr<NamesAndTypesList> fetchSQLiteTableStructure(sqlite3 * connectio
for (int i = 0; i < col_num; ++i)
{
if (strcmp(col_names[i], "name") == 0)
if (col_names[i] == "name"sv)
{
name_and_type.name = data_by_col[i];
}
else if (strcmp(col_names[i], "type") == 0)
else if (col_names[i] == "type"sv)
{
name_and_type.type = convertSQLiteDataType(data_by_col[i]);
}
else if (strcmp(col_names[i], "notnull") == 0)
else if (col_names[i] == "notnull"sv)
{
is_nullable = (data_by_col[i][0] == '0');
}

View File

@ -1,3 +1,5 @@
#include <string_view>
#include <Parsers/ASTFunction.h>
#include <Common/quoteString.h>
@ -16,6 +18,8 @@
#include <Parsers/ASTWithAlias.h>
#include <Parsers/queryToString.h>
using namespace std::literals;
namespace DB
{
@ -339,7 +343,7 @@ void ASTFunction::formatImplWithoutAlias(const FormatSettings & settings, Format
for (const char ** func = operators; *func; func += 2)
{
if (0 == strcmp(name.c_str(), func[0]))
if (name == std::string_view(func[0]))
{
if (frame.need_parens)
settings.ostr << '(';
@ -376,7 +380,7 @@ void ASTFunction::formatImplWithoutAlias(const FormatSettings & settings, Format
}
}
if (!written && 0 == strcmp(name.c_str(), "arrayElement"))
if (!written && name == "arrayElement"sv)
{
if (frame.need_parens)
settings.ostr << '(';
@ -391,7 +395,7 @@ void ASTFunction::formatImplWithoutAlias(const FormatSettings & settings, Format
settings.ostr << ')';
}
if (!written && 0 == strcmp(name.c_str(), "tupleElement"))
if (!written && name == "tupleElement"sv)
{
// fuzzer sometimes may insert tupleElement() created from ASTLiteral:
//
@ -442,7 +446,7 @@ void ASTFunction::formatImplWithoutAlias(const FormatSettings & settings, Format
}
}
if (!written && 0 == strcmp(name.c_str(), "lambda"))
if (!written && name == "lambda"sv)
{
/// Special case: zero elements tuple in lhs of lambda is printed as ().
/// Special case: one-element tuple in lhs of lambda is printed as its element.
@ -483,7 +487,7 @@ void ASTFunction::formatImplWithoutAlias(const FormatSettings & settings, Format
for (const char ** func = operators; *func; func += 2)
{
if (0 == strcmp(name.c_str(), func[0]))
if (name == std::string_view(func[0]))
{
if (frame.need_parens)
settings.ostr << '(';
@ -500,7 +504,7 @@ void ASTFunction::formatImplWithoutAlias(const FormatSettings & settings, Format
}
}
if (!written && 0 == strcmp(name.c_str(), "array"))
if (!written && name == "array"sv)
{
settings.ostr << (settings.hilite ? hilite_operator : "") << '[' << (settings.hilite ? hilite_none : "");
for (size_t i = 0; i < arguments->children.size(); ++i)
@ -513,7 +517,7 @@ void ASTFunction::formatImplWithoutAlias(const FormatSettings & settings, Format
written = true;
}
if (!written && arguments->children.size() >= 2 && 0 == strcmp(name.c_str(), "tuple"))
if (!written && arguments->children.size() >= 2 && name == "tuple"sv)
{
settings.ostr << (settings.hilite ? hilite_operator : "") << '(' << (settings.hilite ? hilite_none : "");
for (size_t i = 0; i < arguments->children.size(); ++i)
@ -526,7 +530,7 @@ void ASTFunction::formatImplWithoutAlias(const FormatSettings & settings, Format
written = true;
}
if (!written && 0 == strcmp(name.c_str(), "map"))
if (!written && name == "map"sv)
{
settings.ostr << (settings.hilite ? hilite_operator : "") << "map(" << (settings.hilite ? hilite_none : "");
for (size_t i = 0; i < arguments->children.size(); ++i)

View File

@ -1,3 +1,5 @@
#include <string_view>
#include <Parsers/ExpressionListParsers.h>
#include <Parsers/ASTAsterisk.h>
@ -12,6 +14,8 @@
#include <Parsers/ParserUnionQueryElement.h>
#include <Common/StringUtils/StringUtils.h>
using namespace std::literals;
namespace DB
{
@ -345,7 +349,7 @@ bool ParserLeftAssociativeBinaryOperatorList::parseImpl(Pos & pos, ASTPtr & node
/** special exception for the access operator to the element of the array `x[y]`, which
* contains the infix part '[' and the suffix ''] '(specified as' [')
*/
if (0 == strcmp(it[0], "["))
if (it[0] == "["sv)
{
if (pos->type != TokenType::ClosingSquareBracket)
return false;

View File

@ -4,6 +4,7 @@
#include <memory>
#include <mutex>
#include <vector>
#include <string_view>
#include <string.h>
#include <base/types.h>
#include <base/scope_guard.h>
@ -55,6 +56,9 @@
#include <Common/config_version.h>
using namespace std::literals;
namespace CurrentMetrics
{
extern const Metric QueryThread;
@ -1844,7 +1848,7 @@ void TCPHandler::run()
catch (Poco::Exception & e)
{
/// Timeout - not an error.
if (!strcmp(e.what(), "Timeout"))
if (e.what() == "Timeout"sv)
{
LOG_DEBUG(log, "Poco::Exception. Code: {}, e.code() = {}, e.displayText() = {}, e.what() = {}", ErrorCodes::POCO_EXCEPTION, e.code(), e.displayText(), e.what());
}