temp-commit

This commit is contained in:
Konstantin Bogdanov 2024-09-19 13:51:02 +02:00
parent 2c29b3d98c
commit a065bc4718
No known key found for this signature in database
103 changed files with 619 additions and 700 deletions

View File

@ -6,6 +6,7 @@
# b) too noisy (checks with > 100 new warnings are considered noisy, this includes e.g. cppcoreguidelines-*).
HeaderFilterRegex: '^.*/(base|src|programs|utils)/.*(h|hpp)$'
ExcludeHeaderFilterRegex: '^.*/contrib/.*\.(h|hpp)$'
Checks: [
'*',
@ -116,7 +117,6 @@ Checks: [
'-readability-avoid-unconditional-preprocessor-if',
'-readability-braces-around-statements',
'-readability-convert-member-functions-to-static',
'-readability-else-after-return',
'-readability-function-cognitive-complexity',
'-readability-function-size',
'-readability-identifier-length',

View File

@ -110,8 +110,7 @@ struct DecomposedFloat
{
if (!isNegative())
return rhs > 0 ? -1 : 1;
else
return rhs >= 0 ? -1 : 1;
return rhs >= 0 ? -1 : 1;
}
/// The case of the most negative integer
@ -128,8 +127,7 @@ struct DecomposedFloat
if (mantissa() == 0)
return 0;
else
return -1;
return -1;
}
}
@ -169,9 +167,8 @@ struct DecomposedFloat
/// Float has no fractional part means that the numbers are equal.
if (large_and_always_integer || (mantissa() & ((1ULL << (Traits::mantissa_bits - normalizedExponent())) - 1)) == 0)
return 0;
else
/// Float has fractional part means its abs value is larger.
return isNegative() ? -1 : 1;
/// Float has fractional part means its abs value is larger.
return isNegative() ? -1 : 1;
}

View File

@ -205,8 +205,7 @@ JSON::ElementType JSON::getType() const
Pos after_string = skipString();
if (after_string < ptr_end && *after_string == ':')
return TYPE_NAME_VALUE_PAIR;
else
return TYPE_STRING;
return TYPE_STRING;
}
default:
throw JSONException(std::string("JSON: unexpected char ") + *ptr_begin + ", expected one of '{[tfn-0123456789\"'");
@ -474,8 +473,7 @@ JSON::Pos JSON::searchField(const char * data, size_t size) const
if (it == end())
return nullptr;
else
return it->data();
return it->data();
}
@ -487,7 +485,7 @@ bool JSON::hasEscapes() const
if (*pos == '"')
return false;
else if (*pos == '\\')
if (*pos == '\\')
return true;
throw JSONException("JSON: unexpected end of data.");
}
@ -503,7 +501,7 @@ bool JSON::hasSpecialChars() const
if (*pos == '"')
return false;
else if (pos < ptr_end)
if (pos < ptr_end)
return true;
throw JSONException("JSON: unexpected end of data.");
}
@ -682,7 +680,7 @@ double JSON::toDouble() const
if (type == TYPE_NUMBER)
return getDouble();
else if (type == TYPE_STRING)
if (type == TYPE_STRING)
return JSON(ptr_begin + 1, ptr_end, level + 1).getDouble();
else
throw JSONException("JSON: cannot convert value to double.");
@ -694,7 +692,7 @@ Int64 JSON::toInt() const
if (type == TYPE_NUMBER)
return getInt();
else if (type == TYPE_STRING)
if (type == TYPE_STRING)
return JSON(ptr_begin + 1, ptr_end, level + 1).getInt();
else
throw JSONException("JSON: cannot convert value to signed integer.");
@ -706,7 +704,7 @@ UInt64 JSON::toUInt() const
if (type == TYPE_NUMBER)
return getUInt();
else if (type == TYPE_STRING)
if (type == TYPE_STRING)
return JSON(ptr_begin + 1, ptr_end, level + 1).getUInt();
else
throw JSONException("JSON: cannot convert value to unsigned integer.");
@ -718,11 +716,9 @@ std::string JSON::toString() const
if (type == TYPE_STRING)
return getString();
else
{
Pos pos = skipElement();
return std::string(ptr_begin, pos - ptr_begin);
}
Pos pos = skipElement();
return std::string(ptr_begin, pos - ptr_begin);
}

View File

@ -203,9 +203,7 @@ T JSON::getWithDefault(const std::string & key, const T & default_) const
if (key_json.isType<T>())
return key_json.get<T>();
else
return default_;
}
else
return default_;
}
return default_;
}

View File

@ -151,19 +151,19 @@ inline bool memequalWide(const char * p1, const char * p2, size_t size)
return unalignedLoad<uint64_t>(p1) == unalignedLoad<uint64_t>(p2)
&& unalignedLoad<uint64_t>(p1 + size - 8) == unalignedLoad<uint64_t>(p2 + size - 8);
}
else if (size >= 4)
if (size >= 4)
{
/// Chunks of 4..7 bytes.
return unalignedLoad<uint32_t>(p1) == unalignedLoad<uint32_t>(p2)
&& unalignedLoad<uint32_t>(p1 + size - 4) == unalignedLoad<uint32_t>(p2 + size - 4);
}
else if (size >= 2)
if (size >= 2)
{
/// Chunks of 2..3 bytes.
return unalignedLoad<uint16_t>(p1) == unalignedLoad<uint16_t>(p2)
&& unalignedLoad<uint16_t>(p1 + size - 2) == unalignedLoad<uint16_t>(p2 + size - 2);
}
else if (size >= 1)
if (size >= 1)
{
/// A single byte.
return *p1 == *p2;

View File

@ -53,10 +53,9 @@ void argsToConfig(const Poco::Util::Application::ArgVec & argv,
key = arg.substr(key_start);
continue;
}
else
{
key = "";
}
key = "";
if (key_start == std::string::npos)
continue;

View File

@ -330,9 +330,8 @@ inline const char * find_first_symbols_dispatch(const char * begin, const char *
#if defined(__SSE4_2__)
if (sizeof...(symbols) >= 5)
return find_first_symbols_sse42<positive, return_mode, sizeof...(symbols), symbols...>(begin, end);
else
#endif
return find_first_symbols_sse2<positive, return_mode, symbols...>(begin, end);
return find_first_symbols_sse2<positive, return_mode, symbols...>(begin, end);
}
template <bool positive, ReturnMode return_mode>
@ -341,9 +340,8 @@ inline const char * find_first_symbols_dispatch(const std::string_view haystack,
#if defined(__SSE4_2__)
if (symbols.str.size() >= 5)
return find_first_symbols_sse42<positive, return_mode>(haystack.begin(), haystack.end(), symbols);
else
#endif
return find_first_symbols_sse2<positive, return_mode>(haystack.begin(), haystack.end(), symbols.str.data(), symbols.str.size());
return find_first_symbols_sse2<positive, return_mode>(haystack.begin(), haystack.end(), symbols.str.data(), symbols.str.size());
}
}

View File

@ -33,8 +33,7 @@ std::optional<uint64_t> getCgroupsV2MemoryLimit()
uint64_t value;
if (setting_file >> value)
return {value};
else
return {}; /// e.g. the cgroups default "max"
return {}; /// e.g. the cgroups default "max"
}
current_cgroup = current_cgroup.parent_path();
}

View File

@ -82,10 +82,8 @@ void * allocNoTrack(size_t size, size_t alignment)
return ptr;
}
else
{
ProfileEvents::increment(ProfileEvents::GWPAsanAllocateFailed);
}
ProfileEvents::increment(ProfileEvents::GWPAsanAllocateFailed);
}
#endif
if (alignment <= MALLOC_MIN_ALIGNMENT)
@ -204,11 +202,9 @@ void * Allocator<clear_memory_, populate>::realloc(void * buf, size_t old_size,
ProfileEvents::increment(ProfileEvents::GWPAsanAllocateSuccess);
return ptr;
}
else
{
[[maybe_unused]] auto trace_free = CurrentMemoryTracker::free(new_size);
ProfileEvents::increment(ProfileEvents::GWPAsanAllocateFailed);
}
[[maybe_unused]] auto trace_free = CurrentMemoryTracker::free(new_size);
ProfileEvents::increment(ProfileEvents::GWPAsanAllocateFailed);
}
if (unlikely(GWPAsan::GuardedAlloc.pointerIsMine(buf)))

View File

@ -579,8 +579,7 @@ String AsyncLoader::checkCycle(const LoadJobPtr & job, LoadJobSet & left, LoadJo
{
if (!visited.contains(job)) // Check for cycle end
throw Exception(ErrorCodes::ASYNC_LOAD_CYCLE, "Load job dependency cycle detected: {} -> {}", job->name, chain);
else
return fmt::format("{} -> {}", job->name, chain); // chain is not a cycle yet -- continue building
return fmt::format("{} -> {}", job->name, chain); // chain is not a cycle yet -- continue building
}
}
left.erase(job);

View File

@ -141,8 +141,7 @@ void AsynchronousMetrics::openSensors() TSA_REQUIRES(data_mutex)
/// Sometimes indices are from zero sometimes from one.
if (thermal_device_index == 0)
continue;
else
break;
break;
}
file->rewind();
@ -210,8 +209,7 @@ void AsynchronousMetrics::openEDAC() TSA_REQUIRES(data_mutex)
{
if (edac_index == 0)
continue;
else
break;
break;
}
edac.emplace_back();
@ -236,8 +234,7 @@ void AsynchronousMetrics::openSensorsChips() TSA_REQUIRES(data_mutex)
{
if (hwmon_index == 0)
continue;
else
break;
break;
}
String hwmon_name;
@ -258,8 +255,7 @@ void AsynchronousMetrics::openSensorsChips() TSA_REQUIRES(data_mutex)
{
if (sensor_index == 0)
continue;
else
break;
break;
}
std::unique_ptr<ReadBufferFromFilePRead> file = openFileIfExists(sensor_value_file);
@ -1007,8 +1003,7 @@ void AsynchronousMetrics::update(TimePoint update_time, bool force_update)
{
if (auto hz = sysconf(_SC_CLK_TCK); hz != -1)
return hz;
else
throw ErrnoException(ErrorCodes::CANNOT_SYSCONF, "Cannot call 'sysconf' to obtain system HZ");
throw ErrnoException(ErrorCodes::CANNOT_SYSCONF, "Cannot call 'sysconf' to obtain system HZ");
};
const auto cgroup_version_specific_divisor = cgroupcpu_stat ? 1e6 : get_clock_ticks();
const double multiplier = 1.0 / cgroup_version_specific_divisor
@ -1764,8 +1759,7 @@ void AsynchronousMetrics::update(TimePoint update_time, bool force_update)
auto it = metric_map.find(name);
if (it == metric_map.end())
return { nullptr, nullptr };
else
return it->second;
return it->second;
};
auto rejected_connections_get_metric_name_doc = [](const String & name) -> std::pair<const char *, const char *>
@ -1788,8 +1782,7 @@ void AsynchronousMetrics::update(TimePoint update_time, bool force_update)
auto it = metric_map.find(name);
if (it == metric_map.end())
return { nullptr, nullptr };
else
return it->second;
return it->second;
};
const auto server_metrics = protocol_server_metrics_func();

View File

@ -95,8 +95,7 @@ BufferAllocationPolicyPtr BufferAllocationPolicy::create(BufferAllocationPolicy:
{
if (settings_.strict_size > 0)
return std::make_unique<FixedSizeBufferAllocationPolicy>(settings_);
else
return std::make_unique<ExpBufferAllocationPolicy>(settings_);
return std::make_unique<ExpBufferAllocationPolicy>(settings_);
}
}

View File

@ -169,8 +169,7 @@ protected:
{
if (this->use_count() > 1)
return derived()->clone();
else
return assumeMutable();
return assumeMutable();
}
public:

View File

@ -122,13 +122,11 @@ std::chrono::sys_seconds CalendarTimeInterval::floor(std::chrono::system_clock::
if (months)
return startOfAbsoluteMonth(toAbsoluteMonth(tp) / months * months);
else
{
constexpr std::chrono::seconds epoch(-3600*24*3);
auto t = std::chrono::sys_seconds(std::chrono::floor<std::chrono::seconds>(tp));
/// We want to align with weeks, but 1970-01-01 is a Thursday, so align with 1969-12-29 instead.
return std::chrono::sys_seconds((t.time_since_epoch() - epoch) / seconds * seconds + epoch);
}
constexpr std::chrono::seconds epoch(-3600 * 24 * 3);
auto t = std::chrono::sys_seconds(std::chrono::floor<std::chrono::seconds>(tp));
/// We want to align with weeks, but 1970-01-01 is a Thursday, so align with 1969-12-29 instead.
return std::chrono::sys_seconds((t.time_since_epoch() - epoch) / seconds * seconds + epoch);
}
bool CalendarTimeInterval::operator==(const CalendarTimeInterval & rhs) const

View File

@ -121,11 +121,9 @@ bool CancelToken::wait(UInt32 * address, UInt32 value)
{
if (s == canceled)
break; // Signaled; futex "release" has been done by the signaling thread
else
{
s = state.load();
continue; // To avoid race (may lead to futex destruction) we have to wait for signaling thread to finish
}
s = state.load();
continue; // To avoid race (may lead to futex destruction) we have to wait for signaling thread to finish
}
if (state.compare_exchange_strong(s, 0))
return true; // There was no cancellation; futex "released"
@ -143,8 +141,7 @@ void CancelToken::raise()
throw DB::Exception::createRuntime(
std::exchange(exception_code, 0),
std::exchange(exception_message, {}));
else
throw DB::Exception(ErrorCodes::THREAD_WAS_CANCELED, "Thread was canceled");
throw DB::Exception(ErrorCodes::THREAD_WAS_CANCELED, "Thread was canceled");
}
void CancelToken::notifyOne(UInt32 * address)

View File

@ -153,7 +153,7 @@ namespace DB
{
continue;
}
else if (poll_error)
if (poll_error)
{
return false;
}

View File

@ -108,8 +108,7 @@ ConcurrencyControl::~ConcurrencyControl()
if (granted < max)
return SlotAllocationPtr(new Allocation(*this, max, granted,
waiters.insert(cur_waiter, nullptr /* pointer is set by Allocation ctor */)));
else
return SlotAllocationPtr(new Allocation(*this, max, granted));
return SlotAllocationPtr(new Allocation(*this, max, granted));
}
void ConcurrencyControl::setMaxConcurrency(SlotCount value)
@ -172,8 +171,7 @@ SlotCount ConcurrencyControl::available(std::unique_lock<std::mutex> &) const
{
if (cur_concurrency < max_concurrency)
return max_concurrency - cur_concurrency;
else
return 0;
return 0;
}
}

View File

@ -59,12 +59,10 @@ AllocationTrace CurrentMemoryTracker::allocImpl(Int64 size, bool throw_if_memory
current_thread->untracked_memory = 0;
return res;
}
else
{
/// Update after successful allocations,
/// since failed allocations should not be take into account.
current_thread->untracked_memory = will_be;
}
/// Update after successful allocations,
/// since failed allocations should not be take into account.
current_thread->untracked_memory = will_be;
}
/// total_memory_tracker only, ignore untracked_memory
else

View File

@ -147,10 +147,8 @@ std::unordered_set<String> reverseResolveImpl(const Poco::Net::IPAddress & addre
if (address.family() == Poco::Net::IPAddress::Family::IPv4)
{
return ptr_resolver->resolve(address.toString());
} else
{
return ptr_resolver->resolve_v6(address.toString());
}
return ptr_resolver->resolve_v6(address.toString());
}
std::unordered_set<String> reverseResolveWithCache(

View File

@ -267,11 +267,9 @@ namespace cctz_extension
size -= offset;
return 0;
}
else
{
errno = EINVAL;
return -1;
}
errno = EINVAL;
return -1;
}
private:
const char * data;

View File

@ -883,14 +883,12 @@ public:
{
return toFirstDayNumOfWeek(v);
}
const auto day_of_week = toDayOfWeek(v);
if constexpr (std::is_unsigned_v<DateOrTime> || std::is_same_v<DateOrTime, DayNum>)
return (day_of_week != 7) ? DayNum(saturateMinus(v, day_of_week)) : toDayNum(v);
else
{
const auto day_of_week = toDayOfWeek(v);
if constexpr (std::is_unsigned_v<DateOrTime> || std::is_same_v<DateOrTime, DayNum>)
return (day_of_week != 7) ? DayNum(saturateMinus(v, day_of_week)) : toDayNum(v);
else
return (day_of_week != 7) ? ExtendedDayNum(v - day_of_week) : toDayNum(v);
}
return (day_of_week != 7) ? ExtendedDayNum(v - day_of_week) : toDayNum(v);
}
/// Get last day of week with week_mode, return Saturday or Sunday
@ -902,15 +900,13 @@ public:
{
return toLastDayNumOfWeek(v);
}
const auto day_of_week = toDayOfWeek(v);
v += 6;
if constexpr (std::is_unsigned_v<DateOrTime> || std::is_same_v<DateOrTime, DayNum>)
return (day_of_week != 7) ? DayNum(saturateMinus(v, day_of_week)) : toDayNum(v);
else
{
const auto day_of_week = toDayOfWeek(v);
v += 6;
if constexpr (std::is_unsigned_v<DateOrTime> || std::is_same_v<DateOrTime, DayNum>)
return (day_of_week != 7) ? DayNum(saturateMinus(v, day_of_week)) : toDayNum(v);
else
return (day_of_week != 7) ? ExtendedDayNum(v - day_of_week) : toDayNum(v);
}
return (day_of_week != 7) ? ExtendedDayNum(v - day_of_week) : toDayNum(v);
}
/// Check and change mode to effective.
@ -937,8 +933,7 @@ public:
const LUTIndex i = toLUTIndex(v);
if (!sunday_first_day_of_week)
return toDayOfWeek(i) - 1;
else
return toDayOfWeek(i + 1) - 1;
return toDayOfWeek(i + 1) - 1;
}
/// Calculate days in one year.
@ -1367,14 +1362,12 @@ public:
return makeLUTIndex(year, month, day_of_month);
}
else
{
auto year = values.year - (12 - month) / 12;
month = 12 - (-month % 12);
auto day_of_month = saturateDayOfMonth(year, month, values.day_of_month);
return makeLUTIndex(year, month, day_of_month);
}
auto year = values.year - (12 - month) / 12;
month = 12 - (-month % 12);
auto day_of_month = saturateDayOfMonth(year, month, values.day_of_month);
return makeLUTIndex(year, month, day_of_month);
}
/// If resulting month has less days than source month, then saturation can happen.

View File

@ -1480,7 +1480,7 @@ bool Dwarf::findAddress(
findLocation(address, mode, unit, locationInfo, inline_frames, /*assume_in_cu_range*/ true);
return locationInfo.has_file_and_line;
}
else if (mode == LocationInfoMode::FAST)
if (mode == LocationInfoMode::FAST)
{
// NOTE: Clang (when using -gdwarf-aranges) doesn't generate entries
// in .debug_aranges for some functions, but always generates
@ -1488,11 +1488,9 @@ bool Dwarf::findAddress(
// it only if such behavior is requested via LocationInfoMode.
return false;
}
else
{
SAFE_CHECK(mode == LocationInfoMode::FULL || mode == LocationInfoMode::FULL_WITH_INLINE, "unexpected mode");
// Fall back to the linear scan.
}
SAFE_CHECK(mode == LocationInfoMode::FULL || mode == LocationInfoMode::FULL_WITH_INLINE, "unexpected mode");
// Fall back to the linear scan.
}
// Slow path (linear scan): Iterate over all .debug_info entries
@ -1947,33 +1945,31 @@ Dwarf::LineNumberVM::FileName Dwarf::LineNumberVM::getFileName(uint64_t index) c
return fn;
}
else
FileName fn;
SAFE_CHECK(index < v5_.fileNamesCount, "invalid file index");
std::string_view file_names = v5_.fileNames;
for (uint64_t i = 0; i < v5_.fileNamesCount; i++)
{
FileName fn;
SAFE_CHECK(index < v5_.fileNamesCount, "invalid file index");
std::string_view file_names = v5_.fileNames;
for (uint64_t i = 0; i < v5_.fileNamesCount; i++)
std::string_view format = v5_.fileNameEntryFormat;
for (uint8_t f = 0; f < v5_.fileNameEntryFormatCount; f++)
{
std::string_view format = v5_.fileNameEntryFormat;
for (uint8_t f = 0; f < v5_.fileNameEntryFormatCount; f++)
auto attr = readLineNumberAttribute(is64Bit_, format, file_names, debugStr_, debugLineStr_);
if (i == index)
{
auto attr = readLineNumberAttribute(is64Bit_, format, file_names, debugStr_, debugLineStr_);
if (i == index)
switch (attr.content_type_code) // NOLINT(bugprone-switch-missing-default-case)
{
switch (attr.content_type_code) // NOLINT(bugprone-switch-missing-default-case)
{
case DW_LNCT_path:
fn.relativeName = std::get<std::string_view>(attr.attr_value);
break;
case DW_LNCT_directory_index:
fn.directoryIndex = std::get<uint64_t>(attr.attr_value);
break;
}
case DW_LNCT_path:
fn.relativeName = std::get<std::string_view>(attr.attr_value);
break;
case DW_LNCT_directory_index:
fn.directoryIndex = std::get<uint64_t>(attr.attr_value);
break;
}
}
}
return fn;
}
return fn;
}
std::string_view Dwarf::LineNumberVM::getIncludeDirectory(uint64_t index) const
@ -2004,26 +2000,24 @@ std::string_view Dwarf::LineNumberVM::getIncludeDirectory(uint64_t index) const
return dir;
}
else
SAFE_CHECK(index < v5_.directoriesCount, "invalid file index");
std::string_view directories = v5_.directories;
for (uint64_t i = 0; i < v5_.directoriesCount; i++)
{
SAFE_CHECK(index < v5_.directoriesCount, "invalid file index");
std::string_view directories = v5_.directories;
for (uint64_t i = 0; i < v5_.directoriesCount; i++)
std::string_view format = v5_.directoryEntryFormat;
for (uint8_t f = 0; f < v5_.directoryEntryFormatCount; f++)
{
std::string_view format = v5_.directoryEntryFormat;
for (uint8_t f = 0; f < v5_.directoryEntryFormatCount; f++)
auto attr = readLineNumberAttribute(is64Bit_, format, directories, debugStr_, debugLineStr_);
if (i == index && attr.content_type_code == DW_LNCT_path)
{
auto attr = readLineNumberAttribute(is64Bit_, format, directories, debugStr_, debugLineStr_);
if (i == index && attr.content_type_code == DW_LNCT_path)
{
return std::get<std::string_view>(attr.attr_value);
}
return std::get<std::string_view>(attr.attr_value);
}
}
// This could only happen if DWARF5's directory_entry_format doesn't contain
// a DW_LNCT_path. Highly unlikely, but we shouldn't crash.
return std::string_view("<directory not found>");
}
// This could only happen if DWARF5's directory_entry_format doesn't contain
// a DW_LNCT_path. Highly unlikely, but we shouldn't crash.
return std::string_view("<directory not found>");
}
bool Dwarf::LineNumberVM::readFileName(std::string_view & program, FileName & fn)

View File

@ -192,8 +192,7 @@ String Elf::getStoredBinaryHash() const
{
if (auto section = findSectionByName(".clickhouse.hash"))
return {section->begin(), section->end()};
else
return {};
return {};
}

View File

@ -81,8 +81,7 @@ size_t Epoll::getManyReady(int max_events, epoll_event * events_out, int timeout
}
continue;
}
else
throw ErrnoException(ErrorCodes::EPOLL_ERROR, "Error in epoll_wait");
throw ErrnoException(ErrorCodes::EPOLL_ERROR, "Error in epoll_wait");
}
else
break;

View File

@ -183,14 +183,13 @@ void FailPointInjection::disableFailPoint(const String & fail_point_name)
void FailPointInjection::wait(const String & fail_point_name)
{
std::unique_lock lock(mu);
if (auto iter = fail_point_wait_channels.find(fail_point_name); iter == fail_point_wait_channels.end())
auto iter = fail_point_wait_channels.find(fail_point_name);
if (iter == fail_point_wait_channels.end())
throw Exception(ErrorCodes::LOGICAL_ERROR, "Can not find channel for fail point {}", fail_point_name);
else
{
lock.unlock();
auto ptr = iter->second;
ptr->wait();
}
lock.unlock();
auto ptr = iter->second;
ptr->wait();
}
void FailPointInjection::enableFromGlobalConfig(const Poco::Util::AbstractConfiguration & config)

View File

@ -69,7 +69,7 @@ public:
/// Conversion of infinite values to integer is undefined.
throw Exception(ErrorCodes::CANNOT_CONVERT_TYPE, "Cannot convert infinite value to integer type");
}
else if (x > Float64(std::numeric_limits<T>::max()) || x < Float64(std::numeric_limits<T>::lowest()))
if (x > Float64(std::numeric_limits<T>::max()) || x < Float64(std::numeric_limits<T>::lowest()))
{
throw Exception(ErrorCodes::CANNOT_CONVERT_TYPE, "Cannot convert out of range floating point value to integer type");
}

View File

@ -1166,10 +1166,8 @@ public:
this->clearHasZero();
return true;
}
else
{
return false;
}
return false;
}
size_t erased_key_position = findCell(x, hash_value, grower.place(hash_value));

View File

@ -417,8 +417,7 @@ public:
auto it = map.find(key, hash);
if (!it)
return decltype(&it->getMapped()){};
else
return &it->getMapped();
return &it->getMapped();
}
};

View File

@ -29,10 +29,9 @@ protected:
{
if (aliases.contains(name))
return aliases.at(name);
else if (String name_lowercase = Poco::toLower(name); case_insensitive_aliases.contains(name_lowercase))
if (String name_lowercase = Poco::toLower(name); case_insensitive_aliases.contains(name_lowercase))
return case_insensitive_aliases.at(name_lowercase);
else
return name;
return name;
}
std::unordered_map<String, String> case_insensitive_name_mapping;
@ -102,7 +101,7 @@ public:
{
if (auto it = aliases.find(name); it != aliases.end())
return it->second;
else if (auto jt = case_insensitive_aliases.find(Poco::toLower(name)); jt != case_insensitive_aliases.end())
if (auto jt = case_insensitive_aliases.find(Poco::toLower(name)); jt != case_insensitive_aliases.end())
return jt->second;
throw Exception(ErrorCodes::LOGICAL_ERROR, "{}: name '{}' is not alias", getFactoryName(), name);

View File

@ -77,10 +77,9 @@ String Macros::expand(const String & s,
res.append(s, pos, String::npos);
break;
}
else
{
res.append(s, pos, begin - pos);
}
res.append(s, pos, begin - pos);
++begin;
size_t end = s.find('}', begin);

View File

@ -289,11 +289,9 @@ AllocationTrace MemoryTracker::allocImpl(Int64 size, bool throw_if_memory_exceed
size,
formatReadableSizeWithBinarySuffix(current_hard_limit));
}
else
{
memory_limit_exceeded_ignored = true;
debugLogBigAllocationWithoutCheck(size);
}
memory_limit_exceeded_ignored = true;
debugLogBigAllocationWithoutCheck(size);
}
if (unlikely(
@ -329,13 +327,11 @@ AllocationTrace MemoryTracker::allocImpl(Int64 size, bool throw_if_memory_exceed
overcommit_result == OvercommitResult::NONE ? "" : " OvercommitTracker decision: ",
toDescription(overcommit_result));
}
else
{
// If OvercommitTracker::needToStopQuery returned false, it guarantees that enough memory is freed.
// This memory is already counted in variable `amount` in the moment of `will_be` initialization.
// Now we just need to update value stored in `will_be`, because it should have changed.
will_be = amount.load(std::memory_order_relaxed);
}
// If OvercommitTracker::needToStopQuery returned false, it guarantees that enough memory is freed.
// This memory is already counted in variable `amount` in the moment of `will_be` initialization.
// Now we just need to update value stored in `will_be`, because it should have changed.
will_be = amount.load(std::memory_order_relaxed);
}
else
{

View File

@ -170,11 +170,9 @@ std::shared_ptr<ICgroupsReader> ICgroupsReader::createCgroupsReader(ICgroupsRead
{
if (version == CgroupsVersion::V2)
return std::make_shared<CgroupsV2Reader>(cgroup_path);
else
{
chassert(version == CgroupsVersion::V1);
return std::make_shared<CgroupsV1Reader>(cgroup_path);
}
chassert(version == CgroupsVersion::V1);
return std::make_shared<CgroupsV1Reader>(cgroup_path);
}
#endif

View File

@ -114,8 +114,7 @@ struct NetlinkMessage
{
if (bytes_sent < 0 && errno == EAGAIN)
continue;
else
throw ErrnoException(ErrorCodes::NETLINK_ERROR, "Can't send a Netlink command");
throw ErrnoException(ErrorCodes::NETLINK_ERROR, "Can't send a Netlink command");
}
if (bytes_sent > request_size)

View File

@ -105,8 +105,7 @@ OvercommitResult OvercommitTracker::needToStopQuery(MemoryTracker * tracker, Int
return OvercommitResult::TIMEOUTED;
if (still_need)
return OvercommitResult::NOT_ENOUGH_FREED;
else
return OvercommitResult::MEMORY_FREED;
return OvercommitResult::MEMORY_FREED;
}
void OvercommitTracker::tryContinueQueryExecutionAfterFree(Int64 amount)

View File

@ -631,12 +631,12 @@ public:
{
return;
}
else if (!this->isInitialized() && rhs.isInitialized())
if (!this->isInitialized() && rhs.isInitialized())
{
do_move(rhs, *this);
return;
}
else if (this->isInitialized() && !rhs.isInitialized())
if (this->isInitialized() && !rhs.isInitialized())
{
do_move(*this, rhs);
return;

View File

@ -112,8 +112,7 @@ bool AtomicBitSet::set(size_t i, bool val) const
{
if (val)
return set(i);
else
return unset(i);
return unset(i);
}
bool AtomicBitSet::unset(size_t i) const

View File

@ -25,7 +25,7 @@ struct ProxyConfiguration
{
return Protocol::HTTP;
}
else if (str == "https")
if (str == "https")
{
return Protocol::HTTPS;
}

View File

@ -176,7 +176,7 @@ std::shared_ptr<ProxyConfigurationResolver> ProxyConfigurationResolverProvider::
{
return getRemoteResolver(request_protocol, prefix, configuration);
}
else if (hasListResolver(prefix, configuration))
if (hasListResolver(prefix, configuration))
{
return getListResolver(request_protocol, prefix, configuration);
}

View File

@ -760,7 +760,7 @@ ASTExplainQuery::ExplainKind QueryFuzzer::fuzzExplainKind(ASTExplainQuery::Expla
{
return kind;
}
else if (fuzz_rand() % 11 == 0)
if (fuzz_rand() % 11 == 0)
{
return ASTExplainQuery::ExplainKind::ParsedAST;
}

View File

@ -338,15 +338,13 @@ public:
}
if (postponed.empty())
return false;
else
if (postponed.front().key <= now())
{
if (postponed.front().key <= now())
{
processPostponed(std::move(lock));
return true;
}
return false;
processPostponed(std::move(lock));
return true;
}
return false;
}
/// Wait for single event (if not available) and process it
@ -360,7 +358,7 @@ public:
processQueue(std::move(lock));
return;
}
else if (postponed.empty())
if (postponed.empty())
{
wait(lock);
}
@ -371,20 +369,18 @@ public:
processPostponed(std::move(lock));
return;
}
else
{
waitUntil(lock, postponed.front().key);
}
waitUntil(lock, postponed.front().key);
}
}
}
TimePoint now()
{
if (auto result = manual_time.load(); likely(result == TimePoint()))
auto result = manual_time.load();
if (likely(result == TimePoint()))
return std::chrono::system_clock::now();
else
return result;
return result;
}
/// For testing only

View File

@ -33,8 +33,7 @@ const ClassifierDescription & ClassifiersConfig::get(const String & classifier_n
{
if (auto it = classifiers.find(classifier_name); it != classifiers.end())
return it->second;
else
throw Exception(ErrorCodes::RESOURCE_NOT_FOUND, "Unknown workload classifier '{}' to access resources", classifier_name);
throw Exception(ErrorCodes::RESOURCE_NOT_FOUND, "Unknown workload classifier '{}' to access resources", classifier_name);
}
}

View File

@ -166,8 +166,7 @@ ResourceLink DynamicResourceManager::Classifier::get(const String & resource_nam
{
if (auto iter = resources.find(resource_name); iter != resources.end())
return iter->second;
else
throw Exception(ErrorCodes::RESOURCE_ACCESS_DENIED, "Access denied to resource '{}'", resource_name);
throw Exception(ErrorCodes::RESOURCE_ACCESS_DENIED, "Access denied to resource '{}'", resource_name);
}
DynamicResourceManager::DynamicResourceManager()

View File

@ -128,8 +128,7 @@ public:
{
if (auto iter = children.find(child_name); iter != children.end())
return iter->second.get();
else
return nullptr;
return nullptr;
}
std::pair<ResourceRequest *, bool> dequeueRequest() override

View File

@ -96,8 +96,7 @@ public:
{
if (auto iter = children.find(child_name); iter != children.end())
return iter->second.get();
else
return nullptr;
return nullptr;
}
std::pair<ResourceRequest *, bool> dequeueRequest() override

View File

@ -58,8 +58,7 @@ public:
{
if (child->basename == child_name)
return child.get();
else
return nullptr;
return nullptr;
}
std::pair<ResourceRequest *, bool> dequeueRequest() override

View File

@ -68,8 +68,7 @@ public:
{
if (child->basename == child_name)
return child.get();
else
return nullptr;
return nullptr;
}
std::pair<ResourceRequest *, bool> dequeueRequest() override

View File

@ -221,8 +221,8 @@ private:
busy_periods++;
return;
}
else // Just move current to next to avoid invalidation
current = current->next;
// Just move current to next to avoid invalidation
current = current->next;
}
value->prev->next = value->next;
value->next->prev = value->prev;

View File

@ -275,7 +275,7 @@ void SignalListener::run()
LOG_INFO(log, "Stop SignalListener thread");
break;
}
else if (sig == SIGHUP)
if (sig == SIGHUP)
{
LOG_DEBUG(log, "Received signal to close logs.");
BaseDaemon::instance().closeLogs(BaseDaemon::instance().logger());
@ -291,9 +291,7 @@ void SignalListener::run()
onTerminate(message, thread_num);
}
else if (sig == SIGINT ||
sig == SIGQUIT ||
sig == SIGTERM)
else if (sig == SIGINT || sig == SIGQUIT || sig == SIGTERM)
{
if (daemon)
daemon->handleSignal(sig);
@ -323,7 +321,8 @@ void SignalListener::run()
/// Example: segfault while symbolizing stack trace.
try
{
std::thread([=, this] { onFault(sig, info, context, stack_trace, thread_frame_pointers, thread_num, thread_ptr); }).detach();
std::thread([=, this] { onFault(sig, info, context, stack_trace, thread_frame_pointers, thread_num, thread_ptr); })
.detach();
}
catch (...)
{

View File

@ -73,8 +73,7 @@ StatusFile::StatusFile(std::string path_, FillFunction fill_)
{
if (errno == EWOULDBLOCK)
throw Exception(ErrorCodes::CANNOT_OPEN_FILE, "Cannot lock file {}. Another server instance in same directory is already running.", path);
else
ErrnoException::throwFromPath(ErrorCodes::CANNOT_OPEN_FILE, path, "Cannot lock file {}", path);
ErrnoException::throwFromPath(ErrorCodes::CANNOT_OPEN_FILE, path, "Cannot lock file {}", path);
}
if (0 != ftruncate(fd, 0))

View File

@ -162,9 +162,7 @@ std::pair<bool, std::string> StudentTTest::compareAndReport(size_t confidence_le
out << "mean difference is " << mean_difference << ", but confidence interval is " << mean_confidence_interval;
return {false, out.str()};
}
else
{
out << "No difference proven at " << confidence_level[confidence_level_index] << "% confidence";
return {true, out.str()};
}
out << "No difference proven at " << confidence_level[confidence_level_index] << "% confidence";
return {true, out.str()};
}

View File

@ -460,13 +460,11 @@ const T * find(const void * address, const std::vector<T> & vec)
if (it == vec.begin())
return nullptr;
else
--it; /// Last range that has left boundary less or equals than address.
--it; /// Last range that has left boundary less or equals than address.
if (address >= it->address_begin && address < it->address_end)
return &*it;
else
return nullptr;
return nullptr;
}
}

View File

@ -157,8 +157,7 @@ void SystemLogQueue<LogElement>::waitFlush(SystemLogQueue<LogElement>::Index exp
{
if (should_prepare_tables_anyway)
return (flushed_index >= expected_flushed_index && prepared_tables >= requested_prepare_tables) || is_shutdown;
else
return (flushed_index >= expected_flushed_index) || is_shutdown;
return (flushed_index >= expected_flushed_index) || is_shutdown;
});
if (!result)

View File

@ -100,7 +100,7 @@ TasksStatsCounters::MetricsProvider TasksStatsCounters::findBestAvailableProvide
{
return MetricsProvider::Netlink;
}
else if (ProcfsMetricsProvider::isAvailable())
if (ProcfsMetricsProvider::isAvailable())
{
return MetricsProvider::Procfs;
}

View File

@ -133,11 +133,9 @@ size_t computeWidthImpl(const UInt8 * data, size_t size, size_t prefix, size_t l
i += num_regular_chars;
break;
}
else
{
i += 16;
width += 16;
}
i += 16;
width += 16;
}
#endif

View File

@ -40,7 +40,7 @@ int VersionNumber::compare(const VersionNumber & rhs) const
{
return components[min] >= 0 ? 1 : -1;
}
else if (rhs.components.size() > min)
if (rhs.components.size() > min)
{
return -rhs.components[min] > 0 ? 1 : -1;
}

View File

@ -57,10 +57,8 @@ void assertProcessUserMatchesDataOwner(const std::string & path, std::function<v
message += fmt::format(" Run under 'sudo -u {}'.", data_owner);
throw Exception(ErrorCodes::MISMATCHING_USERS_FOR_PROCESS_AND_DATA, "{}", message);
}
else
{
on_warning(message);
}
on_warning(message);
}
}

View File

@ -63,8 +63,7 @@ static size_t getStackSize(void ** out_address)
/// Most likely procfs is not mounted.
return 0;
}
else
throw ErrnoException(ErrorCodes::CANNOT_PTHREAD_ATTR, "Cannot pthread_getattr_np");
throw ErrnoException(ErrorCodes::CANNOT_PTHREAD_ATTR, "Cannot pthread_getattr_np");
}
# endif

View File

@ -26,8 +26,7 @@ int32_t readFrom(const std::filesystem::path & filename, int default_value)
int idata;
if (infile >> idata)
return idata;
else
return default_value;
return default_value;
}
/// Try to look at cgroups limit if it is available.

View File

@ -359,7 +359,7 @@ inline int memcmpSmallLikeZeroPaddedAllowOverflow15(const Char * a, size_t a_siz
{
return 0;
}
else if (a_size > b_size)
if (a_size > b_size)
{
max_size = a_size;
longest = a;

View File

@ -46,10 +46,8 @@ inline ALWAYS_INLINE void * newImpl(std::size_t size, TAlign... align)
ProfileEvents::increment(ProfileEvents::GWPAsanAllocateSuccess);
return ptr;
}
else
{
ProfileEvents::increment(ProfileEvents::GWPAsanAllocateFailed);
}
ProfileEvents::increment(ProfileEvents::GWPAsanAllocateFailed);
}
else
{
@ -58,11 +56,8 @@ inline ALWAYS_INLINE void * newImpl(std::size_t size, TAlign... align)
ProfileEvents::increment(ProfileEvents::GWPAsanAllocateSuccess);
return ptr;
}
else
{
ProfileEvents::increment(ProfileEvents::GWPAsanAllocateFailed);
}
ProfileEvents::increment(ProfileEvents::GWPAsanAllocateFailed);
}
}
#endif
@ -90,10 +85,8 @@ inline ALWAYS_INLINE void * newNoExcept(std::size_t size) noexcept
ProfileEvents::increment(ProfileEvents::GWPAsanAllocateSuccess);
return ptr;
}
else
{
ProfileEvents::increment(ProfileEvents::GWPAsanAllocateFailed);
}
ProfileEvents::increment(ProfileEvents::GWPAsanAllocateFailed);
}
#endif
return malloc(size);
@ -109,10 +102,8 @@ inline ALWAYS_INLINE void * newNoExcept(std::size_t size, std::align_val_t align
ProfileEvents::increment(ProfileEvents::GWPAsanAllocateSuccess);
return ptr;
}
else
{
ProfileEvents::increment(ProfileEvents::GWPAsanAllocateFailed);
}
ProfileEvents::increment(ProfileEvents::GWPAsanAllocateFailed);
}
#endif
return aligned_alloc(static_cast<size_t>(align), size);

View File

@ -50,13 +50,14 @@ std::pair<std::string, UInt16> parseAddress(const std::string & str, UInt16 defa
}
return { std::string(begin, port - 1), port_number };
}
else if (default_port)
if (default_port)
{
return { str, default_port };
return {str, default_port};
}
else
throw Exception(ErrorCodes::BAD_ARGUMENTS,
"The address passed to function parseAddress doesn't contain port number and no 'default_port' was passed");
throw Exception(
ErrorCodes::BAD_ARGUMENTS,
"The address passed to function parseAddress doesn't contain port number and no 'default_port' was passed");
}
}

View File

@ -2,16 +2,16 @@
#if defined(OS_LINUX) && defined(__amd64__) && defined(__SSE2__) && !defined(SANITIZER) && defined(NDEBUG)
#include <sys/mman.h>
#include <unistd.h>
#include <string.h>
#include <sys/syscall.h>
# include <cstring>
# include <unistd.h>
# include <sys/mman.h>
# include <sys/syscall.h>
#include <emmintrin.h>
# include <emmintrin.h>
#include <Common/getMappedArea.h>
#include <Common/Exception.h>
#include <fmt/format.h>
# include <Common/getMappedArea.h>
# include <Common/Exception.h>
# include <fmt/format.h>
namespace DB

View File

@ -41,8 +41,7 @@ To typeid_cast(From * from) noexcept
{
if ((typeid(From) == typeid(std::remove_pointer_t<To>)) || (from && typeid(*from) == typeid(std::remove_pointer_t<To>)))
return static_cast<To>(from);
else
return nullptr;
return nullptr;
}
namespace detail
@ -69,6 +68,5 @@ To typeid_cast(const std::shared_ptr<From> & from) noexcept
{
if ((typeid(From) == typeid(typename To::element_type)) || (from && typeid(*from) == typeid(typename To::element_type)))
return std::static_pointer_cast<typename To::element_type>(from);
else
return nullptr;
return nullptr;
}

View File

@ -82,8 +82,7 @@ struct PerformanceStatistics
if (adjustedCount() < 2)
return adjustedCount() - 1;
else
return std::normal_distribution<>(mean(), sigma())(stat_rng);
return std::normal_distribution<>(mean(), sigma())(stat_rng);
}
};
@ -118,8 +117,7 @@ struct PerformanceStatistics
return std::min_element(samples, samples + max_method) - samples;
}
else
return choose_method;
return choose_method;
}
PerformanceStatistics() = default;

View File

@ -241,8 +241,7 @@ Field BaseSettings<TTraits>::get(std::string_view name) const
const auto & accessor = Traits::Accessor::instance();
if (size_t index = accessor.find(name); index != static_cast<size_t>(-1))
return accessor.getValue(*this, index);
else
return static_cast<Field>(getCustomSetting(name));
return static_cast<Field>(getCustomSetting(name));
}
template <typename TTraits>
@ -263,8 +262,7 @@ String BaseSettings<TTraits>::getString(std::string_view name) const
const auto & accessor = Traits::Accessor::instance();
if (size_t index = accessor.find(name); index != static_cast<size_t>(-1))
return accessor.getValueString(*this, index);
else
return getCustomSetting(name).toString();
return getCustomSetting(name).toString();
}
template <typename TTraits>
@ -387,10 +385,9 @@ const char * BaseSettings<TTraits>::getTypeName(std::string_view name) const
const auto & accessor = Traits::Accessor::instance();
if (size_t index = accessor.find(name); index != static_cast<size_t>(-1))
return accessor.getTypeName(index);
else if (tryGetCustomSetting(name))
if (tryGetCustomSetting(name))
return "Custom";
else
BaseSettingsHelpers::throwSettingNotFound(name);
BaseSettingsHelpers::throwSettingNotFound(name);
}
template <typename TTraits>
@ -400,10 +397,9 @@ const char * BaseSettings<TTraits>::getDescription(std::string_view name) const
const auto & accessor = Traits::Accessor::instance();
if (size_t index = accessor.find(name); index != static_cast<size_t>(-1))
return accessor.getDescription(index);
else if (tryGetCustomSetting(name))
if (tryGetCustomSetting(name))
return "Custom";
else
BaseSettingsHelpers::throwSettingNotFound(name);
BaseSettingsHelpers::throwSettingNotFound(name);
}
template <typename TTraits>

View File

@ -86,11 +86,11 @@ constexpr ASOFJoinInequality reverseASOFJoinInequality(ASOFJoinInequality inequa
{
if (inequality == ASOFJoinInequality::Less)
return ASOFJoinInequality::Greater;
else if (inequality == ASOFJoinInequality::Greater)
if (inequality == ASOFJoinInequality::Greater)
return ASOFJoinInequality::Less;
else if (inequality == ASOFJoinInequality::LessOrEquals)
if (inequality == ASOFJoinInequality::LessOrEquals)
return ASOFJoinInequality::GreaterOrEquals;
else if (inequality == ASOFJoinInequality::GreaterOrEquals)
if (inequality == ASOFJoinInequality::GreaterOrEquals)
return ASOFJoinInequality::LessOrEquals;
return ASOFJoinInequality::None;

View File

@ -44,16 +44,14 @@ struct QualifiedTableName
{
if (database.empty())
return {table};
else
return {database, table};
return {database, table};
}
std::string getFullName() const
{
if (database.empty())
return table;
else
return database + '.' + table;
return database + '.' + table;
}
/// NOTE: It's different from compound identifier parsing and does not support escaping and dots in name.

View File

@ -187,8 +187,7 @@ std::optional<std::reference_wrapper<Daemon>> BaseDaemon::tryGetInstance()
if (ptr)
return std::optional<std::reference_wrapper<Daemon>>(*ptr);
else
return {};
return {};
}
#if defined(OS_LINUX)

View File

@ -200,10 +200,10 @@ inline DataTypePtr createDecimal(UInt64 precision_value, UInt64 scale_value)
if (precision_value <= DecimalUtils::max_precision<Decimal32>)
return std::make_shared<DecimalType<Decimal32>>(precision_value, scale_value);
else if (precision_value <= DecimalUtils::max_precision<Decimal64>)
if (precision_value <= DecimalUtils::max_precision<Decimal64>)
return std::make_shared<DecimalType<Decimal64>>(precision_value, scale_value);
else if (precision_value <= DecimalUtils::max_precision<Decimal128>)
return std::make_shared<DecimalType<Decimal128>>(precision_value, scale_value);
return std::make_shared<DecimalType<Decimal128>>(precision_value, scale_value);
return std::make_shared<DecimalType<Decimal256>>(precision_value, scale_value);
}

View File

@ -76,16 +76,14 @@ public:
{
if (custom_name)
return custom_name->getName();
else
return doGetName();
return doGetName();
}
String getPrettyName(size_t indent = 0) const
{
if (custom_name)
return custom_name->getName();
else
return doGetPrettyName(indent);
return doGetPrettyName(indent);
}
DataTypePtr getPtr() const { return shared_from_this(); }

View File

@ -114,8 +114,7 @@ private:
{
if (size)
return size;
else
return offset();
return offset();
}
void closeFile(bool throw_if_error)

View File

@ -345,7 +345,7 @@ int ZipArchiveWriter::compressionMethodToInt(const String & compression_method_)
{
if (compression_method_.empty())
return MZ_COMPRESS_METHOD_DEFLATE; /// By default the compression method is "deflate".
else if (compression_method_ == kStore)
if (compression_method_ == kStore)
return MZ_COMPRESS_METHOD_STORE;
else if (compression_method_ == kDeflate)
return MZ_COMPRESS_METHOD_DEFLATE;

View File

@ -196,7 +196,7 @@ off_t AsynchronousReadBufferFromFileDescriptor::seek(off_t offset, int whence)
return new_pos;
}
else if (prefetch_future.valid())
if (prefetch_future.valid())
{
/// Read from prefetch buffer and recheck if the new position is valid inside.
if (nextImpl())

View File

@ -106,7 +106,7 @@ namespace
if (!max_part_number)
throw Exception(ErrorCodes::INVALID_CONFIG_PARAMETER, "max_blocks_in_multipart_upload must not be 0");
else if (!min_upload_part_size)
if (!min_upload_part_size)
throw Exception(ErrorCodes::INVALID_CONFIG_PARAMETER, "min_upload_part_size must not be 0");
else if (max_upload_part_size < min_upload_part_size)
throw Exception(ErrorCodes::INVALID_CONFIG_PARAMETER, "max_upload_part_size must not be less than min_upload_part_size");
@ -383,8 +383,12 @@ void copyAzureBlobStorageFile(
if (copy_status.HasValue())
throw Exception(ErrorCodes::AZURE_BLOB_STORAGE_ERROR, "Copy from {} to {} failed with status {} description {} (operation is done {})",
src_blob, dest_blob, copy_status.Value().ToString(), copy_status_description.Value(), operation.IsDone());
else
throw Exception(ErrorCodes::AZURE_BLOB_STORAGE_ERROR, "Copy from {} to {} didn't complete with success status (operation is done {})", src_blob, dest_blob, operation.IsDone());
throw Exception(
ErrorCodes::AZURE_BLOB_STORAGE_ERROR,
"Copy from {} to {} didn't complete with success status (operation is done {})",
src_blob,
dest_blob,
operation.IsDone());
}
}
}

View File

@ -85,13 +85,8 @@ bool BrotliReadBuffer::nextImpl()
eof_flag = true;
return !working_buffer.empty();
}
else
{
throw Exception(
ErrorCodes::BROTLI_READ_FAILED,
"brotli decode error{}",
getExceptionEntryWithFileName(*in));
}
throw Exception(ErrorCodes::BROTLI_READ_FAILED, "brotli decode error{}", getExceptionEntryWithFileName(*in));
}
if (brotli->result == BROTLI_DECODER_RESULT_ERROR)

View File

@ -60,7 +60,7 @@ CompressionMethod chooseHTTPCompressionMethod(const std::string & list)
if (std::string::npos != list.find("zstd"))
return CompressionMethod::Zstd;
else if (std::string::npos != list.find("br"))
if (std::string::npos != list.find("br"))
return CompressionMethod::Brotli;
else if (std::string::npos != list.find("lz4"))
return CompressionMethod::Lz4;

View File

@ -12,8 +12,7 @@ Poco::Timespan ConnectionTimeouts::saturate(Poco::Timespan timespan, Poco::Times
{
if (limit.totalMicroseconds() == 0)
return timespan;
else
return (timespan > limit) ? limit : timespan;
return (timespan > limit) ? limit : timespan;
}
/// Timeouts for the case when we have just single attempt to connect.

View File

@ -226,7 +226,7 @@ Algorithm parseAlgorithmFromString(const String & str)
{
if (boost::iequals(str, "aes_128_ctr"))
return Algorithm::AES_128_CTR;
else if (boost::iequals(str, "aes_192_ctr"))
if (boost::iequals(str, "aes_192_ctr"))
return Algorithm::AES_192_CTR;
else if (boost::iequals(str, "aes_256_ctr"))
return Algorithm::AES_256_CTR;

View File

@ -224,7 +224,7 @@ bool HadoopSnappyReadBuffer::nextImpl()
}
return true;
}
else if (decoder->result != Status::NEEDS_MORE_INPUT)
if (decoder->result != Status::NEEDS_MORE_INPUT)
{
throw Exception(
ErrorCodes::SNAPPY_UNCOMPRESS_FAILED,

View File

@ -26,8 +26,7 @@ public:
{
if (block_pos)
return CityHash_v1_0_2::CityHash128WithSeed(BufferWithOwnMemory<Buffer>::memory.data(), block_pos, state);
else
return state;
return state;
}
void append(DB::BufferBase::Position data)

View File

@ -75,15 +75,13 @@ bool LZMAInflatingReadBuffer::nextImpl()
eof_flag = true;
return !working_buffer.empty();
}
else
{
throw Exception(
ErrorCodes::LZMA_STREAM_DECODER_FAILED,
"lzma decoder finished, but input stream has not exceeded: error code: {}; lzma version: {}{}",
ret,
LZMA_VERSION_STRING,
getExceptionEntryWithFileName(*in));
}
throw Exception(
ErrorCodes::LZMA_STREAM_DECODER_FAILED,
"lzma decoder finished, but input stream has not exceeded: error code: {}; lzma version: {}{}",
ret,
LZMA_VERSION_STRING,
getExceptionEntryWithFileName(*in));
}
if (ret != LZMA_OK)

View File

@ -185,53 +185,45 @@ off_t ReadBufferFromFileDescriptor::seek(off_t offset, int whence)
return new_pos;
}
else
/// Position is out of the buffer, we need to do real seek.
off_t seek_pos = required_alignment > 1 ? new_pos / required_alignment * required_alignment : new_pos;
off_t offset_after_seek_pos = new_pos - seek_pos;
/// First reset the buffer so the next read will fetch new data to the buffer.
resetWorkingBuffer();
/// In case of using 'pread' we just update the info about the next position in file.
/// In case of using 'read' we call 'lseek'.
/// We account both cases as seek event as it leads to non-contiguous reads from file.
ProfileEvents::increment(ProfileEvents::Seek);
if (!use_pread)
{
/// Position is out of the buffer, we need to do real seek.
off_t seek_pos = required_alignment > 1
? new_pos / required_alignment * required_alignment
: new_pos;
Stopwatch watch(profile_callback ? clock_type : CLOCK_MONOTONIC);
off_t offset_after_seek_pos = new_pos - seek_pos;
off_t res = ::lseek(fd, seek_pos, SEEK_SET);
if (-1 == res)
ErrnoException::throwFromPath(
ErrorCodes::CANNOT_SEEK_THROUGH_FILE, getFileName(), "Cannot seek through file {} at offset {}", getFileName(), seek_pos);
/// First reset the buffer so the next read will fetch new data to the buffer.
resetWorkingBuffer();
/// Also note that seeking past the file size is not allowed.
if (res != seek_pos)
throw Exception(
ErrorCodes::CANNOT_SEEK_THROUGH_FILE, "The 'lseek' syscall returned value ({}) that is not expected ({})", res, seek_pos);
/// In case of using 'pread' we just update the info about the next position in file.
/// In case of using 'read' we call 'lseek'.
/// We account both cases as seek event as it leads to non-contiguous reads from file.
ProfileEvents::increment(ProfileEvents::Seek);
if (!use_pread)
{
Stopwatch watch(profile_callback ? clock_type : CLOCK_MONOTONIC);
off_t res = ::lseek(fd, seek_pos, SEEK_SET);
if (-1 == res)
ErrnoException::throwFromPath(
ErrorCodes::CANNOT_SEEK_THROUGH_FILE,
getFileName(),
"Cannot seek through file {} at offset {}",
getFileName(),
seek_pos);
/// Also note that seeking past the file size is not allowed.
if (res != seek_pos)
throw Exception(ErrorCodes::CANNOT_SEEK_THROUGH_FILE,
"The 'lseek' syscall returned value ({}) that is not expected ({})", res, seek_pos);
watch.stop();
ProfileEvents::increment(ProfileEvents::DiskReadElapsedMicroseconds, watch.elapsedMicroseconds());
}
file_offset_of_buffer_end = seek_pos;
if (offset_after_seek_pos > 0)
ignore(offset_after_seek_pos);
return seek_pos;
watch.stop();
ProfileEvents::increment(ProfileEvents::DiskReadElapsedMicroseconds, watch.elapsedMicroseconds());
}
file_offset_of_buffer_end = seek_pos;
if (offset_after_seek_pos > 0)
ignore(offset_after_seek_pos);
return seek_pos;
}

View File

@ -18,9 +18,11 @@ off_t ReadBufferFromMemory::seek(off_t offset, int whence)
working_buffer = internal_buffer; /// We need to restore `working_buffer` in case the position was at EOF before this seek().
return static_cast<size_t>(pos - internal_buffer.begin());
}
else
throw Exception(ErrorCodes::SEEK_POSITION_OUT_OF_BOUND, "Seek position is out of bounds. Offset: {}, Max: {}",
offset, std::to_string(static_cast<size_t>(internal_buffer.end() - internal_buffer.begin())));
throw Exception(
ErrorCodes::SEEK_POSITION_OUT_OF_BOUND,
"Seek position is out of bounds. Offset: {}, Max: {}",
offset,
std::to_string(static_cast<size_t>(internal_buffer.end() - internal_buffer.begin())));
}
else if (whence == SEEK_CUR)
{
@ -31,9 +33,11 @@ off_t ReadBufferFromMemory::seek(off_t offset, int whence)
working_buffer = internal_buffer; /// We need to restore `working_buffer` in case the position was at EOF before this seek().
return static_cast<size_t>(pos - internal_buffer.begin());
}
else
throw Exception(ErrorCodes::SEEK_POSITION_OUT_OF_BOUND, "Seek position is out of bounds. Offset: {}, Max: {}",
offset, std::to_string(static_cast<size_t>(internal_buffer.end() - internal_buffer.begin())));
throw Exception(
ErrorCodes::SEEK_POSITION_OUT_OF_BOUND,
"Seek position is out of bounds. Offset: {}, Max: {}",
offset,
std::to_string(static_cast<size_t>(internal_buffer.end() - internal_buffer.begin())));
}
else
throw Exception(ErrorCodes::CANNOT_SEEK_THROUGH_FILE, "Only SEEK_SET and SEEK_CUR seek modes allowed.");

View File

@ -427,11 +427,9 @@ Aws::S3::Model::GetObjectResult ReadBufferFromS3::sendRequest(size_t attempt, si
if (outcome.IsSuccess())
return outcome.GetResultWithOwnership();
else
{
const auto & error = outcome.GetError();
throw S3Exception(error.GetMessage(), error.GetErrorType());
}
const auto & error = outcome.GetError();
throw S3Exception(error.GetMessage(), error.GetErrorType());
}
}

View File

@ -1372,8 +1372,7 @@ ReturnType readDateTextFallback(LocalDate & date, ReadBuffer & buf, const char *
++buf.position();
return true;
}
else
return false;
return false;
};
UInt16 year = 0;
@ -1606,7 +1605,7 @@ ReturnType skipJSONFieldImpl(ReadBuffer & buf, StringRef name_of_field, const Fo
throw Exception(ErrorCodes::INCORRECT_DATA, "Unexpected EOF for key '{}'", name_of_field.toString());
return ReturnType(false);
}
else if (*buf.position() == '"') /// skip double-quoted string
if (*buf.position() == '"') /// skip double-quoted string
{
NullOutput sink;
if constexpr (throw_exception)
@ -2112,7 +2111,7 @@ ReturnType readQuotedFieldInto(Vector & s, ReadBuffer & buf)
if (*buf.position() == '\'')
return readQuotedStringFieldInto<ReturnType>(s, buf);
else if (*buf.position() == '[')
if (*buf.position() == '[')
return readQuotedFieldInBracketsInto<ReturnType, '[', ']'>(s, buf);
else if (*buf.position() == '(')
return readQuotedFieldInBracketsInto<ReturnType, '(', ')'>(s, buf);

View File

@ -314,8 +314,7 @@ inline ReturnType readBoolTextWord(bool & x, ReadBuffer & buf, bool support_uppe
x = true;
break;
}
else
[[fallthrough]];
[[fallthrough]];
}
case 'F':
{
@ -328,8 +327,7 @@ inline ReturnType readBoolTextWord(bool & x, ReadBuffer & buf, bool support_uppe
x = false;
break;
}
else
[[fallthrough]];
[[fallthrough]];
}
default:
{
@ -822,8 +820,7 @@ inline ReturnType readDateTextImpl(LocalDate & date, ReadBuffer & buf, const cha
date = LocalDate(year, month, day);
return ReturnType(true);
}
else
return readDateTextFallback<ReturnType>(date, buf, allowed_delimiters);
return readDateTextFallback<ReturnType>(date, buf, allowed_delimiters);
}
inline void convertToDayNum(DayNum & date, ExtendedDayNum & from)
@ -935,18 +932,16 @@ inline ReturnType readUUIDTextImpl(UUID & uuid, ReadBuffer & buf)
uuid = parseUUID({reinterpret_cast<const UInt8 *>(s), size});
return ReturnType(true);
}
s[size] = 0;
if constexpr (throw_exception)
{
throw Exception(ErrorCodes::CANNOT_PARSE_UUID, "Cannot parse uuid {}", s);
}
else
{
s[size] = 0;
if constexpr (throw_exception)
{
throw Exception(ErrorCodes::CANNOT_PARSE_UUID, "Cannot parse uuid {}", s);
}
else
{
return ReturnType(false);
}
return ReturnType(false);
}
}
@ -1098,12 +1093,10 @@ inline ReturnType readDateTimeTextImpl(time_t & datetime, ReadBuffer & buf, cons
return ReturnType(true);
}
else
/// Why not readIntTextUnsafe? Because for needs of AdFox, parsing of unix timestamp with leading zeros is supported: 000...NNNN.
return readIntTextImpl<time_t, ReturnType, ReadIntTextCheckOverflow::CHECK_OVERFLOW>(datetime, buf);
/// Why not readIntTextUnsafe? Because for needs of AdFox, parsing of unix timestamp with leading zeros is supported: 000...NNNN.
return readIntTextImpl<time_t, ReturnType, ReadIntTextCheckOverflow::CHECK_OVERFLOW>(datetime, buf);
}
else
return readDateTimeTextFallback<ReturnType, dt64_mode>(datetime, buf, date_lut, allowed_date_delimiters, allowed_time_delimiters);
return readDateTimeTextFallback<ReturnType, dt64_mode>(datetime, buf, date_lut, allowed_date_delimiters, allowed_time_delimiters);
}
template <typename ReturnType>

View File

@ -426,13 +426,13 @@ std::unique_ptr<ReadBuffer> ReadWriteBufferFromHTTP::initialize()
reason,
"");
}
else
throw Exception(
ErrorCodes::HTTP_RANGE_NOT_SATISFIABLE,
"Cannot read with range: [{}, {}] (response status: {}, reason: {})",
*read_range.begin,
read_range.end ? toString(*read_range.end) : "-",
toString(response.getStatus()), response.getReason());
throw Exception(
ErrorCodes::HTTP_RANGE_NOT_SATISFIABLE,
"Cannot read with range: [{}, {}] (response status: {}, reason: {})",
*read_range.begin,
read_range.end ? toString(*read_range.end) : "-",
toString(response.getStatus()),
response.getReason());
}
else if (read_range.end)
{

View File

@ -50,8 +50,7 @@ Aws::Utils::Logging::LogLevel AWSLogger::GetLogLevel() const
{
if (enable_s3_requests_logging)
return Aws::Utils::Logging::LogLevel::Trace;
else
return Aws::Utils::Logging::LogLevel::Info;
return Aws::Utils::Logging::LogLevel::Info;
}
void AWSLogger::Log(Aws::Utils::Logging::LogLevel log_level, const char * tag, const char * format_str, ...) // NOLINT

View File

@ -151,10 +151,13 @@ Aws::String AWSEC2MetadataClient::getDefaultCredentialsSecurely() const
/// At least the host should be available and reply, otherwise neither IMDSv2 nor IMDSv1 are usable.
return {};
}
else if (response_code != Aws::Http::HttpResponseCode::OK || new_token.empty())
if (response_code != Aws::Http::HttpResponseCode::OK || new_token.empty())
{
LOG_TRACE(logger, "Calling EC2MetadataService to get token failed, "
"falling back to a less secure way. HTTP response code: {}", response_code);
LOG_TRACE(
logger,
"Calling EC2MetadataService to get token failed, "
"falling back to a less secure way. HTTP response code: {}",
response_code);
return getDefaultCredentials();
}
@ -444,20 +447,18 @@ AwsAuthSTSAssumeRoleWebIdentityCredentialsProvider::AwsAuthSTSAssumeRoleWebIdent
LOG_WARNING(logger, "Token file must be specified to use STS AssumeRole web identity creds provider.");
return; // No need to do further constructing
}
else
{
LOG_DEBUG(logger, "Resolved token_file from profile_config or environment variable to be {}", token_file);
}
LOG_DEBUG(logger, "Resolved token_file from profile_config or environment variable to be {}", token_file);
if (role_arn.empty())
{
LOG_WARNING(logger, "RoleArn must be specified to use STS AssumeRole web identity creds provider.");
return; // No need to do further constructing
}
else
{
LOG_DEBUG(logger, "Resolved role_arn from profile_config or environment variable to be {}", role_arn);
}
LOG_DEBUG(logger, "Resolved role_arn from profile_config or environment variable to be {}", role_arn);
if (tmp_region.empty())
{
@ -663,11 +664,9 @@ Aws::String SSOCredentialsProvider::loadAccessTokenFile(const Aws::String & sso_
expires_at = expiration;
return tmp_access_token;
}
else
{
LOG_TEST(logger, "Unable to open token file on path: {}", sso_access_token_path);
return "";
}
LOG_TEST(logger, "Unable to open token file on path: {}", sso_access_token_path);
return "";
}
S3CredentialsProviderChain::S3CredentialsProviderChain(

View File

@ -17,8 +17,8 @@ PocoHTTPClientFactory::CreateHttpClient(const Aws::Client::ClientConfiguration &
{
if (client_configuration.userAgent.starts_with("ClickHouse"))
return std::make_shared<PocoHTTPClient>(static_cast<const PocoHTTPClientConfiguration &>(client_configuration));
else /// This client is created inside the AWS SDK with default settings to obtain ECS credentials from localhost.
return std::make_shared<PocoHTTPClient>(client_configuration);
/// This client is created inside the AWS SDK with default settings to obtain ECS credentials from localhost.
return std::make_shared<PocoHTTPClient>(client_configuration);
}
std::shared_ptr<Aws::Http::HttpRequest> PocoHTTPClientFactory::CreateHttpRequest(

View File

@ -296,7 +296,7 @@ namespace
if (!max_part_number)
throw Exception(ErrorCodes::INVALID_CONFIG_PARAMETER, "max_part_number must not be 0");
else if (!min_upload_part_size)
if (!min_upload_part_size)
throw Exception(ErrorCodes::INVALID_CONFIG_PARAMETER, "min_upload_part_size must not be 0");
else if (max_upload_part_size < min_upload_part_size)
throw Exception(ErrorCodes::INVALID_CONFIG_PARAMETER, "max_upload_part_size must not be less than min_upload_part_size");
@ -769,21 +769,19 @@ namespace
fallback_method();
break;
}
else
{
// Can't come here with MinIO, MinIO allows single part upload for large objects.
LOG_INFO(
log,
"Single operation copy failed with error {} for Bucket: {}, Key: {}, Object size: {}, will retry with multipart "
"upload copy",
outcome.GetError().GetExceptionName(),
dest_bucket,
dest_key,
size);
performMultipartUploadCopy();
break;
}
// Can't come here with MinIO, MinIO allows single part upload for large objects.
LOG_INFO(
log,
"Single operation copy failed with error {} for Bucket: {}, Key: {}, Object size: {}, will retry with multipart "
"upload copy",
outcome.GetError().GetExceptionName(),
dest_bucket,
dest_key,
size);
performMultipartUploadCopy();
break;
}
if ((outcome.GetError().GetErrorType() == Aws::S3::S3Errors::NO_SUCH_KEY) && (retries < max_retries))

View File

@ -82,11 +82,13 @@ ObjectInfo getObjectInfo(
{
return *object_info;
}
else if (throw_on_error)
if (throw_on_error)
{
throw S3Exception(error.GetErrorType(),
throw S3Exception(
error.GetErrorType(),
"Failed to get object info: {}. HTTP response code: {}",
error.GetMessage(), static_cast<size_t>(error.GetResponseCode()));
error.GetMessage(),
static_cast<size_t>(error.GetResponseCode()));
}
return {};
}

View File

@ -54,7 +54,7 @@ std::streampos StdStreamBufFromReadBuffer::seekoff(std::streamoff off, std::ios_
{
if (dir == std::ios_base::beg)
return seekpos(off, which);
else if (dir == std::ios_base::cur)
if (dir == std::ios_base::cur)
return seekpos(getCurrentPosition() + off, which);
else if (dir == std::ios_base::end)
return seekpos(size + off, which);
@ -94,8 +94,7 @@ std::streampos StdStreamBufFromReadBuffer::getCurrentPosition() const
{
if (seekable_read_buffer)
return seekable_read_buffer->getPosition();
else
return read_buffer->count();
return read_buffer->count();
}
std::streamsize StdStreamBufFromReadBuffer::xsputn(const char*, std::streamsize)

View File

@ -18,7 +18,7 @@ String getFileNameFromReadBuffer(const ReadBuffer & in)
{
if (const auto * wrapper = dynamic_cast<const ReadBufferWrapperBase *>(&in))
return getFileNameFromReadBuffer(wrapper->getWrappedReadBuffer());
else if (const auto * parallel = dynamic_cast<const ParallelReadBuffer *>(&in))
if (const auto * parallel = dynamic_cast<const ParallelReadBuffer *>(&in))
return getFileNameFromReadBuffer(parallel->getReadBuffer());
else if (const auto * peekable = dynamic_cast<const PeekableReadBuffer *>(&in))
return getFileNameFromReadBuffer(peekable->getSubBuffer());

View File

@ -44,7 +44,7 @@ std::optional<size_t> tryGetFileSizeFromReadBuffer(ReadBuffer & in)
{
if (auto * delegate = dynamic_cast<ReadBufferFromFileDecorator *>(&in))
return tryGetFileSize(delegate->getWrappedReadBuffer());
else if (auto * compressed = dynamic_cast<CompressedReadBufferWrapper *>(&in))
if (auto * compressed = dynamic_cast<CompressedReadBufferWrapper *>(&in))
return tryGetFileSize(compressed->getWrappedReadBuffer());
return tryGetFileSize(in);
}
@ -63,7 +63,7 @@ bool isBufferWithFileSize(const ReadBuffer & in)
{
return delegate->isWithFileSize();
}
else if (const auto * compressed = dynamic_cast<const CompressedReadBufferWrapper *>(&in))
if (const auto * compressed = dynamic_cast<const CompressedReadBufferWrapper *>(&in))
{
return isBufferWithFileSize(compressed->getWrappedReadBuffer());
}
@ -77,7 +77,7 @@ size_t getDataOffsetMaybeCompressed(const ReadBuffer & in)
{
return getDataOffsetMaybeCompressed(delegate->getWrappedReadBuffer());
}
else if (const auto * compressed = dynamic_cast<const CompressedReadBufferWrapper *>(&in))
if (const auto * compressed = dynamic_cast<const CompressedReadBufferWrapper *>(&in))
{
return getDataOffsetMaybeCompressed(compressed->getWrappedReadBuffer());
}

View File

@ -323,55 +323,52 @@ void writeAnyEscapedString(const char * begin, const char * end, WriteBuffer & b
buf.write(pos, next_pos - pos);
break;
}
else
buf.write(pos, next_pos - pos);
pos = next_pos;
switch (*pos)
{
buf.write(pos, next_pos - pos);
pos = next_pos;
switch (*pos)
{
case quote_character:
{
if constexpr (escape_quote_with_quote)
writeChar(quote_character, buf);
else
writeChar('\\', buf);
case quote_character: {
if constexpr (escape_quote_with_quote)
writeChar(quote_character, buf);
break;
}
case '\b':
else
writeChar('\\', buf);
writeChar('b', buf);
break;
case '\f':
writeChar('\\', buf);
writeChar('f', buf);
break;
case '\n':
writeChar('\\', buf);
writeChar('n', buf);
break;
case '\r':
writeChar('\\', buf);
writeChar('r', buf);
break;
case '\t':
writeChar('\\', buf);
writeChar('t', buf);
break;
case '\0':
writeChar('\\', buf);
writeChar('0', buf);
break;
case '\\':
if constexpr (escape_backslash_with_backslash)
writeChar('\\', buf);
writeChar('\\', buf);
break;
default:
writeChar(*pos, buf);
writeChar(quote_character, buf);
break;
}
++pos;
case '\b':
writeChar('\\', buf);
writeChar('b', buf);
break;
case '\f':
writeChar('\\', buf);
writeChar('f', buf);
break;
case '\n':
writeChar('\\', buf);
writeChar('n', buf);
break;
case '\r':
writeChar('\\', buf);
writeChar('r', buf);
break;
case '\t':
writeChar('\\', buf);
writeChar('t', buf);
break;
case '\0':
writeChar('\\', buf);
writeChar('0', buf);
break;
case '\\':
if constexpr (escape_backslash_with_backslash)
writeChar('\\', buf);
writeChar('\\', buf);
break;
default:
writeChar(*pos, buf);
}
++pos;
}
}
@ -683,12 +680,11 @@ void writeCSVString(const char * begin, const char * end, WriteBuffer & buf)
buf.write(pos, end - pos);
break;
}
else /// Quotation.
{
++next_pos;
buf.write(pos, next_pos - pos);
writeChar(quote, buf);
}
/// Quotation.
++next_pos;
buf.write(pos, next_pos - pos);
writeChar(quote, buf);
pos = next_pos;
}
@ -720,7 +716,7 @@ inline void writeXMLStringForTextElementOrAttributeValue(const char * begin, con
buf.write(pos, end - pos);
break;
}
else if (*next_pos == '<')
if (*next_pos == '<')
{
buf.write(pos, next_pos - pos);
++next_pos;
@ -774,7 +770,7 @@ inline void writeXMLStringForTextElement(const char * begin, const char * end, W
buf.write(pos, end - pos);
break;
}
else if (*next_pos == '<')
if (*next_pos == '<')
{
buf.write(pos, next_pos - pos);
++next_pos;
@ -1088,12 +1084,12 @@ void writeDecimalFractional(const T & x, UInt32 scale, WriteBuffer & ostr, bool
writeDecimalFractional(static_cast<UInt32>(x), scale, ostr, trailing_zeros, fixed_fractional_length, fractional_length);
return;
}
else if (x <= std::numeric_limits<UInt64>::max())
if (x <= std::numeric_limits<UInt64>::max())
{
writeDecimalFractional(static_cast<UInt64>(x), scale, ostr, trailing_zeros, fixed_fractional_length, fractional_length);
return;
}
else if (x <= std::numeric_limits<UInt128>::max())
if (x <= std::numeric_limits<UInt128>::max())
{
writeDecimalFractional(static_cast<UInt128>(x), scale, ostr, trailing_zeros, fixed_fractional_length, fractional_length);
return;
@ -1106,7 +1102,7 @@ void writeDecimalFractional(const T & x, UInt32 scale, WriteBuffer & ostr, bool
writeDecimalFractional(static_cast<UInt32>(x), scale, ostr, trailing_zeros, fixed_fractional_length, fractional_length);
return;
}
else if (x <= std::numeric_limits<UInt64>::max())
if (x <= std::numeric_limits<UInt64>::max())
{
writeDecimalFractional(static_cast<UInt64>(x), scale, ostr, trailing_zeros, fixed_fractional_length, fractional_length);
return;

View File

@ -95,17 +95,12 @@ bool ZlibInflatingReadBuffer::nextImpl()
return !working_buffer.empty();
}
/// If it is not end of file, we need to reset zstr and return true, because we still have some data to read
else
{
rc = inflateReset(&zstr);
if (rc != Z_OK)
throw Exception(
ErrorCodes::ZLIB_INFLATE_FAILED,
"inflateReset failed: {}{}",
zError(rc),
getExceptionEntryWithFileName(*in));
return true;
}
rc = inflateReset(&zstr);
if (rc != Z_OK)
throw Exception(
ErrorCodes::ZLIB_INFLATE_FAILED, "inflateReset failed: {}{}", zError(rc), getExceptionEntryWithFileName(*in));
return true;
}
/// If it is not end and not OK, something went wrong, throw exception

View File

@ -210,12 +210,13 @@ bool ZstdDeflatingAppendableWriteBuffer::isNeedToAddEmptyBlock()
/// But in this case file still corrupted and we have to remove it.
return result != ZSTD_CORRECT_TERMINATION_LAST_BLOCK;
}
else if (fsize > 0)
if (fsize > 0)
{
throw Exception(
ErrorCodes::ZSTD_ENCODER_FAILED,
"Trying to write to non-empty file '{}' with tiny size {}. It can lead to data corruption",
out->getFileName(), fsize);
out->getFileName(),
fsize);
}
return false;
}

View File

@ -178,7 +178,7 @@ ReturnType parseDateTimeBestEffortImpl(
}
return ReturnType(true);
}
else if (num_digits == 10 && !year && !has_time)
if (num_digits == 10 && !year && !has_time)
{
if (strict)
return on_error(ErrorCodes::CANNOT_PARSE_DATETIME, "Strict best effort parsing doesn't allow timestamps");
@ -199,7 +199,8 @@ ReturnType parseDateTimeBestEffortImpl(
else if (num_digits == 14 && !year && !has_time)
{
if (strict)
return on_error(ErrorCodes::CANNOT_PARSE_DATETIME, "Strict best effort parsing doesn't allow date times without separators");
return on_error(
ErrorCodes::CANNOT_PARSE_DATETIME, "Strict best effort parsing doesn't allow date times without separators");
/// This is YYYYMMDDhhmmss
readDecimalNumber<4>(year, digits);
@ -213,7 +214,8 @@ ReturnType parseDateTimeBestEffortImpl(
else if (num_digits == 8 && !year)
{
if (strict)
return on_error(ErrorCodes::CANNOT_PARSE_DATETIME, "Strict best effort parsing doesn't allow date times without separators");
return on_error(
ErrorCodes::CANNOT_PARSE_DATETIME, "Strict best effort parsing doesn't allow date times without separators");
/// This is YYYYMMDD
readDecimalNumber<4>(year, digits);
@ -223,7 +225,8 @@ ReturnType parseDateTimeBestEffortImpl(
else if (num_digits == 6)
{
if (strict)
return on_error(ErrorCodes::CANNOT_PARSE_DATETIME, "Strict best effort parsing doesn't allow date times without separators");
return on_error(
ErrorCodes::CANNOT_PARSE_DATETIME, "Strict best effort parsing doesn't allow date times without separators");
/// This is YYYYMM or hhmmss
if (!year && !month)
@ -239,7 +242,8 @@ ReturnType parseDateTimeBestEffortImpl(
has_time = true;
}
else
return on_error(ErrorCodes::CANNOT_PARSE_DATETIME, "Cannot read DateTime: ambiguous 6 digits, it can be YYYYMM or hhmmss");
return on_error(
ErrorCodes::CANNOT_PARSE_DATETIME, "Cannot read DateTime: ambiguous 6 digits, it can be YYYYMM or hhmmss");
}
else if (num_digits == 4 && !year)
{
@ -256,11 +260,8 @@ ReturnType parseDateTimeBestEffortImpl(
{
char delimiter_after_year = *in.position();
if (delimiter_after_year < 0x20
|| delimiter_after_year == ','
|| delimiter_after_year == ';'
|| delimiter_after_year == '\''
|| delimiter_after_year == '"')
if (delimiter_after_year < 0x20 || delimiter_after_year == ',' || delimiter_after_year == ';'
|| delimiter_after_year == '\'' || delimiter_after_year == '"')
break;
if (month)
@ -277,7 +278,10 @@ ReturnType parseDateTimeBestEffortImpl(
else if (delimiter_after_year == ' ')
continue;
else
return on_error(ErrorCodes::CANNOT_PARSE_DATETIME, "Cannot read DateTime: unexpected number of decimal digits after year: {}", num_digits);
return on_error(
ErrorCodes::CANNOT_PARSE_DATETIME,
"Cannot read DateTime: unexpected number of decimal digits after year: {}",
num_digits);
/// Only the same delimiter.
if (!day_of_month && checkChar(delimiter_after_year, in))
@ -291,11 +295,17 @@ ReturnType parseDateTimeBestEffortImpl(
else if (delimiter_after_year == ' ')
continue;
else
return on_error(ErrorCodes::CANNOT_PARSE_DATETIME, "Cannot read DateTime: unexpected number of decimal digits after year and month: {}", num_digits);
return on_error(
ErrorCodes::CANNOT_PARSE_DATETIME,
"Cannot read DateTime: unexpected number of decimal digits after year and month: {}",
num_digits);
}
if (!isSymbolIn(delimiter_after_year, allowed_date_delimiters))
return on_error(ErrorCodes::CANNOT_PARSE_DATETIME, "Cannot read DateTime: '{}' delimiter between date parts is not allowed", delimiter_after_year);
return on_error(
ErrorCodes::CANNOT_PARSE_DATETIME,
"Cannot read DateTime: '{}' delimiter between date parts is not allowed",
delimiter_after_year);
}
}
else if (num_digits == 2 || num_digits == 1)
@ -334,7 +344,10 @@ ReturnType parseDateTimeBestEffortImpl(
else if (num_digits == 1)
readDecimalNumber<1>(minute, digits);
else
return on_error(ErrorCodes::CANNOT_PARSE_DATETIME, "Cannot read DateTime: unexpected number of decimal digits after hour: {}", num_digits);
return on_error(
ErrorCodes::CANNOT_PARSE_DATETIME,
"Cannot read DateTime: unexpected number of decimal digits after hour: {}",
num_digits);
if (checkChar(':', in))
{
@ -345,7 +358,10 @@ ReturnType parseDateTimeBestEffortImpl(
else if (num_digits == 1)
readDecimalNumber<1>(second, digits);
else
return on_error(ErrorCodes::CANNOT_PARSE_DATETIME, "Cannot read DateTime: unexpected number of decimal digits after hour and minute: {}", num_digits);
return on_error(
ErrorCodes::CANNOT_PARSE_DATETIME,
"Cannot read DateTime: unexpected number of decimal digits after hour and minute: {}",
num_digits);
}
}
else if (checkChar(',', in))
@ -353,7 +369,9 @@ ReturnType parseDateTimeBestEffortImpl(
if (month && !day_of_month)
day_of_month = hour_or_day_of_month_or_month;
}
else if ((!in.eof() && isSymbolIn(*in.position(), allowed_date_delimiters)) && (checkChar('/', in) || checkChar('.', in) || checkChar('-', in)))
else if (
(!in.eof() && isSymbolIn(*in.position(), allowed_date_delimiters))
&& (checkChar('/', in) || checkChar('.', in) || checkChar('-', in)))
{
if (day_of_month)
return on_error(ErrorCodes::CANNOT_PARSE_DATETIME, "Cannot read DateTime: day of month is duplicated");
@ -370,7 +388,10 @@ ReturnType parseDateTimeBestEffortImpl(
else if (num_digits == 1)
readDecimalNumber<1>(day_of_month, digits);
else
return on_error(ErrorCodes::CANNOT_PARSE_DATETIME, "Cannot read DateTime: unexpected number of decimal digits after month: {}", num_digits);
return on_error(
ErrorCodes::CANNOT_PARSE_DATETIME,
"Cannot read DateTime: unexpected number of decimal digits after month: {}",
num_digits);
}
else
{
@ -384,25 +405,35 @@ ReturnType parseDateTimeBestEffortImpl(
readDecimalNumber<1>(month, digits);
else if (num_digits == 0)
{
/// Month in alphabetical form
/// Month in alphabetical form
char alpha[9]; /// The longest month name: September
size_t num_alpha = readAlpha(alpha, sizeof(alpha), in);
char alpha[9]; /// The longest month name: September
size_t num_alpha = readAlpha(alpha, sizeof(alpha), in);
if (num_alpha < 3)
return on_error(ErrorCodes::CANNOT_PARSE_DATETIME, "Cannot read DateTime: unexpected number of alphabetical characters after day of month: {}", num_alpha);
if (num_alpha < 3)
return on_error(
ErrorCodes::CANNOT_PARSE_DATETIME,
"Cannot read DateTime: unexpected number of alphabetical characters after day of month: {}",
num_alpha);
if (!read_alpha_month(alpha))
return on_error(ErrorCodes::CANNOT_PARSE_DATETIME, "Cannot read DateTime: alphabetical characters after day of month don't look like month: {}", std::string(alpha, 3));
if (!read_alpha_month(alpha))
return on_error(
ErrorCodes::CANNOT_PARSE_DATETIME,
"Cannot read DateTime: alphabetical characters after day of month don't look like month: {}",
std::string(alpha, 3));
}
else
return on_error(ErrorCodes::CANNOT_PARSE_DATETIME, "Cannot read DateTime: unexpected number of decimal digits after day of month: {}", num_digits);
return on_error(
ErrorCodes::CANNOT_PARSE_DATETIME,
"Cannot read DateTime: unexpected number of decimal digits after day of month: {}",
num_digits);
}
if (month > 12)
std::swap(month, day_of_month);
if ((!in.eof() && isSymbolIn(*in.position(), allowed_date_delimiters)) && (checkChar('/', in) || checkChar('.', in) || checkChar('-', in)))
if ((!in.eof() && isSymbolIn(*in.position(), allowed_date_delimiters))
&& (checkChar('/', in) || checkChar('.', in) || checkChar('-', in)))
{
if (year)
return on_error(ErrorCodes::CANNOT_PARSE_DATETIME, "Cannot read DateTime: year component is duplicated");
@ -421,7 +452,10 @@ ReturnType parseDateTimeBestEffortImpl(
year += 2000;
}
else
return on_error(ErrorCodes::CANNOT_PARSE_DATETIME, "Cannot read DateTime: unexpected number of decimal digits after day of month and month: {}", num_digits);
return on_error(
ErrorCodes::CANNOT_PARSE_DATETIME,
"Cannot read DateTime: unexpected number of decimal digits after day of month and month: {}",
num_digits);
}
}
else
@ -440,7 +474,8 @@ ReturnType parseDateTimeBestEffortImpl(
}
}
else if (num_digits != 0)
return on_error(ErrorCodes::CANNOT_PARSE_DATETIME, "Cannot read DateTime: unexpected number of decimal digits: {}", num_digits);
return on_error(
ErrorCodes::CANNOT_PARSE_DATETIME, "Cannot read DateTime: unexpected number of decimal digits: {}", num_digits);
}
if (num_digits == 0)
@ -551,7 +586,7 @@ ReturnType parseDateTimeBestEffortImpl(
{
break;
}
else if (num_alpha == 1)
if (num_alpha == 1)
{
return on_error(ErrorCodes::CANNOT_PARSE_DATETIME, "Cannot read DateTime: unexpected alphabetical character");
}
@ -580,18 +615,35 @@ ReturnType parseDateTimeBestEffortImpl(
if (read_alpha_month(alpha))
{
}
else if (0 == strncasecmp(alpha, "UTC", 3)) has_time_zone_offset = true; // NOLINT
else if (0 == strncasecmp(alpha, "GMT", 3)) has_time_zone_offset = true;
else if (0 == strncasecmp(alpha, "MSK", 3)) { has_time_zone_offset = true; time_zone_offset_hour = 3; }
else if (0 == strncasecmp(alpha, "MSD", 3)) { has_time_zone_offset = true; time_zone_offset_hour = 4; }
else if (0 == strncasecmp(alpha, "UTC", 3))
has_time_zone_offset = true; // NOLINT
else if (0 == strncasecmp(alpha, "GMT", 3))
has_time_zone_offset = true;
else if (0 == strncasecmp(alpha, "MSK", 3))
{
has_time_zone_offset = true;
time_zone_offset_hour = 3;
}
else if (0 == strncasecmp(alpha, "MSD", 3))
{
has_time_zone_offset = true;
time_zone_offset_hour = 4;
}
else if (0 == strncasecmp(alpha, "Mon", 3)) has_day_of_week = true; // NOLINT
else if (0 == strncasecmp(alpha, "Tue", 3)) has_day_of_week = true;
else if (0 == strncasecmp(alpha, "Wed", 3)) has_day_of_week = true;
else if (0 == strncasecmp(alpha, "Thu", 3)) has_day_of_week = true;
else if (0 == strncasecmp(alpha, "Fri", 3)) has_day_of_week = true;
else if (0 == strncasecmp(alpha, "Sat", 3)) has_day_of_week = true;
else if (0 == strncasecmp(alpha, "Sun", 3)) has_day_of_week = true;
else if (0 == strncasecmp(alpha, "Mon", 3))
has_day_of_week = true; // NOLINT
else if (0 == strncasecmp(alpha, "Tue", 3))
has_day_of_week = true;
else if (0 == strncasecmp(alpha, "Wed", 3))
has_day_of_week = true;
else if (0 == strncasecmp(alpha, "Thu", 3))
has_day_of_week = true;
else if (0 == strncasecmp(alpha, "Fri", 3))
has_day_of_week = true;
else if (0 == strncasecmp(alpha, "Sat", 3))
has_day_of_week = true;
else if (0 == strncasecmp(alpha, "Sun", 3))
has_day_of_week = true;
else
return on_error(ErrorCodes::CANNOT_PARSE_DATETIME, "Cannot read DateTime: unexpected word");
@ -653,7 +705,7 @@ ReturnType parseDateTimeBestEffortImpl(
{
if ((month_ == 1 || month_ == 3 || month_ == 5 || month_ == 7 || month_ == 8 || month_ == 10 || month_ == 12) && day_ >= 1 && day_ <= 31)
return true;
else if (month_ == 2 && ((is_leap_year_ && day_ >= 1 && day_ <= 29) || (!is_leap_year_ && day_ >= 1 && day_ <= 28)))
if (month_ == 2 && ((is_leap_year_ && day_ >= 1 && day_ <= 29) || (!is_leap_year_ && day_ >= 1 && day_ <= 28)))
return true;
else if ((month_ == 4 || month_ == 6 || month_ == 9 || month_ == 11) && day_ >= 1 && day_ <= 30)
return true;

View File

@ -167,98 +167,95 @@ ReturnType readFloatTextPreciseImpl(T & x, ReadBuffer & buf)
return ReturnType(true);
}
else
/// Slow path. Copy characters that may be present in floating point number to temporary buffer.
bool negative = false;
/// We check eof here because we can parse +inf +nan
while (!buf.eof())
{
/// Slow path. Copy characters that may be present in floating point number to temporary buffer.
bool negative = false;
/// We check eof here because we can parse +inf +nan
while (!buf.eof())
switch (*buf.position())
{
switch (*buf.position())
{
case '+':
++buf.position();
continue;
case '+':
++buf.position();
continue;
case '-':
{
negative = true;
++buf.position();
continue;
}
case 'i': [[fallthrough]];
case 'I':
{
if (assertOrParseInfinity<throw_exception>(buf))
{
x = std::numeric_limits<T>::infinity();
if (negative)
x = -x;
return ReturnType(true);
}
return ReturnType(false);
}
case 'n': [[fallthrough]];
case 'N':
{
if (assertOrParseNaN<throw_exception>(buf))
{
x = std::numeric_limits<T>::quiet_NaN();
if (negative)
x = -x;
return ReturnType(true);
}
return ReturnType(false);
}
default:
break;
case '-': {
negative = true;
++buf.position();
continue;
}
break;
}
char tmp_buf[MAX_LENGTH];
int num_copied_chars = 0;
while (!buf.eof() && num_copied_chars < MAX_LENGTH)
{
char c = *buf.position();
if (!(isNumericASCII(c) || c == '-' || c == '+' || c == '.' || c == 'e' || c == 'E'))
break;
tmp_buf[num_copied_chars] = c;
++buf.position();
++num_copied_chars;
}
fast_float::from_chars_result res;
if constexpr (std::endian::native == std::endian::little)
res = fast_float::from_chars(tmp_buf, tmp_buf + num_copied_chars, x);
else
{
Float64 x64 = 0.0;
res = fast_float::from_chars(tmp_buf, tmp_buf + num_copied_chars, x64);
x = static_cast<T>(x64);
}
if (unlikely(res.ec != std::errc() || res.ptr - tmp_buf != num_copied_chars))
{
if constexpr (throw_exception)
throw Exception(
ErrorCodes::CANNOT_PARSE_NUMBER, "Cannot read floating point value here: {}", String(tmp_buf, num_copied_chars));
else
case 'i':
[[fallthrough]];
case 'I': {
if (assertOrParseInfinity<throw_exception>(buf))
{
x = std::numeric_limits<T>::infinity();
if (negative)
x = -x;
return ReturnType(true);
}
return ReturnType(false);
}
case 'n':
[[fallthrough]];
case 'N': {
if (assertOrParseNaN<throw_exception>(buf))
{
x = std::numeric_limits<T>::quiet_NaN();
if (negative)
x = -x;
return ReturnType(true);
}
return ReturnType(false);
}
default:
break;
}
if (negative)
x = -x;
return ReturnType(true);
break;
}
char tmp_buf[MAX_LENGTH];
int num_copied_chars = 0;
while (!buf.eof() && num_copied_chars < MAX_LENGTH)
{
char c = *buf.position();
if (!(isNumericASCII(c) || c == '-' || c == '+' || c == '.' || c == 'e' || c == 'E'))
break;
tmp_buf[num_copied_chars] = c;
++buf.position();
++num_copied_chars;
}
fast_float::from_chars_result res;
if constexpr (std::endian::native == std::endian::little)
res = fast_float::from_chars(tmp_buf, tmp_buf + num_copied_chars, x);
else
{
Float64 x64 = 0.0;
res = fast_float::from_chars(tmp_buf, tmp_buf + num_copied_chars, x64);
x = static_cast<T>(x64);
}
if (unlikely(res.ec != std::errc() || res.ptr - tmp_buf != num_copied_chars))
{
if constexpr (throw_exception)
throw Exception(
ErrorCodes::CANNOT_PARSE_NUMBER, "Cannot read floating point value here: {}", String(tmp_buf, num_copied_chars));
else
return ReturnType(false);
}
if (negative)
x = -x;
return ReturnType(true);
}
@ -479,7 +476,7 @@ ReturnType readFloatTextFastImpl(T & x, ReadBuffer & in, bool & has_fractional)
}
return ReturnType(false);
}
else if (*in.position() == 'n' || *in.position() == 'N')
if (*in.position() == 'n' || *in.position() == 'N')
{
if (assertOrParseNaN<throw_exception>(in))
{

Some files were not shown because too many files have changed in this diff Show More