From 54e601019c9d1db4aa8d8c32797e338218798349 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sat, 2 Dec 2017 00:40:58 +0300 Subject: [PATCH] Better [#CLICKHOUSE-2]. --- contrib/libdivide/libdivide.h | 10 +- .../AggregateFunctionCount.cpp | 2 +- .../src/Client/ConnectionPoolWithFailover.cpp | 2 +- dbms/src/Common/tests/hashes_test.cpp | 2 +- .../tests/block_tab_separated_streams.cpp | 2 +- .../tests/collapsing_sorted_stream.cpp | 2 +- dbms/src/DataStreams/tests/glue_streams.cpp | 2 +- .../tests/tab_separated_streams.cpp | 2 +- dbms/src/Functions/FunctionsArithmetic.h | 92 ++++++++----------- .../Storages/MergeTree/DataPartsExchange.cpp | 2 +- .../MergeTree/MergeTreeBaseBlockInputStream.h | 2 +- dbms/src/Storages/MergeTree/MergeTreeData.cpp | 5 +- dbms/src/Storages/MergeTree/MergeTreeData.h | 6 +- dbms/src/Storages/MergeTree/PKCondition.cpp | 5 +- dbms/src/Storages/MergeTree/PKCondition.h | 1 - .../Storages/StorageReplicatedMergeTree.cpp | 3 +- 16 files changed, 56 insertions(+), 84 deletions(-) diff --git a/contrib/libdivide/libdivide.h b/contrib/libdivide/libdivide.h index 6a32d271903..dd3b85008c5 100644 --- a/contrib/libdivide/libdivide.h +++ b/contrib/libdivide/libdivide.h @@ -1220,14 +1220,14 @@ namespace libdivide_internal { #endif /* Some bogus unswitch functions for unsigned types so the same (presumably templated) code can work for both signed and unsigned. */ - uint32_t crash_u32(uint32_t, const libdivide_u32_t *) { abort(); return *(uint32_t *)NULL; } - uint64_t crash_u64(uint64_t, const libdivide_u64_t *) { abort(); return *(uint64_t *)NULL; } + uint32_t crash_u32(uint32_t, const libdivide_u32_t *) { abort(); } + uint64_t crash_u64(uint64_t, const libdivide_u64_t *) { abort(); } #ifdef __APPLE__ - UInt64 crash_u64(UInt64, const libdivide_u64_t *) { abort(); return *(UInt64 *)NULL; } + UInt64 crash_u64(UInt64, const libdivide_u64_t *) { abort(); } #endif #if LIBDIVIDE_USE_SSE2 - __m128i crash_u32_vector(__m128i, const libdivide_u32_t *) { abort(); return *(__m128i *)NULL; } - __m128i crash_u64_vector(__m128i, const libdivide_u64_t *) { abort(); return *(__m128i *)NULL; } + __m128i crash_u32_vector(__m128i, const libdivide_u32_t *) { abort(); } + __m128i crash_u64_vector(__m128i, const libdivide_u64_t *) { abort(); } #endif template diff --git a/dbms/src/AggregateFunctions/AggregateFunctionCount.cpp b/dbms/src/AggregateFunctions/AggregateFunctionCount.cpp index 6959567fc13..643343731be 100644 --- a/dbms/src/AggregateFunctions/AggregateFunctionCount.cpp +++ b/dbms/src/AggregateFunctions/AggregateFunctionCount.cpp @@ -7,7 +7,7 @@ namespace DB namespace { -AggregateFunctionPtr createAggregateFunctionCount(const std::string & name, const DataTypes & argument_types, const Array & parameters) +AggregateFunctionPtr createAggregateFunctionCount(const std::string & /*name*/, const DataTypes & /*argument_types*/, const Array & /*parameters*/) { return std::make_shared(); } diff --git a/dbms/src/Client/ConnectionPoolWithFailover.cpp b/dbms/src/Client/ConnectionPoolWithFailover.cpp index 7ec99cb83c5..acba75086b2 100644 --- a/dbms/src/Client/ConnectionPoolWithFailover.cpp +++ b/dbms/src/Client/ConnectionPoolWithFailover.cpp @@ -50,7 +50,7 @@ ConnectionPoolWithFailover::ConnectionPoolWithFailover( } } -IConnectionPool::Entry ConnectionPoolWithFailover::get(const Settings * settings, bool force_connected) +IConnectionPool::Entry ConnectionPoolWithFailover::get(const Settings * settings, bool /*force_connected*/) { TryGetEntryFunc try_get_entry = [&](NestedPool & pool, std::string & fail_message) { diff --git a/dbms/src/Common/tests/hashes_test.cpp b/dbms/src/Common/tests/hashes_test.cpp index 219e7dd2a77..f2d6836a998 100644 --- a/dbms/src/Common/tests/hashes_test.cpp +++ b/dbms/src/Common/tests/hashes_test.cpp @@ -11,7 +11,7 @@ #include -int main(int argc, char ** argv) +int main(int, char **) { using Strings = std::vector; using Hashes = std::vector; diff --git a/dbms/src/DataStreams/tests/block_tab_separated_streams.cpp b/dbms/src/DataStreams/tests/block_tab_separated_streams.cpp index d4c3bcde704..58910fb851d 100644 --- a/dbms/src/DataStreams/tests/block_tab_separated_streams.cpp +++ b/dbms/src/DataStreams/tests/block_tab_separated_streams.cpp @@ -21,7 +21,7 @@ using namespace DB; -int main(int argc, char ** argv) +int main(int, char **) try { NamesAndTypesList names_and_types_list diff --git a/dbms/src/DataStreams/tests/collapsing_sorted_stream.cpp b/dbms/src/DataStreams/tests/collapsing_sorted_stream.cpp index e338bbb7520..c297d015245 100644 --- a/dbms/src/DataStreams/tests/collapsing_sorted_stream.cpp +++ b/dbms/src/DataStreams/tests/collapsing_sorted_stream.cpp @@ -15,7 +15,7 @@ #include -int main(int argc, char ** argv) +int main(int, char **) try { using namespace DB; diff --git a/dbms/src/DataStreams/tests/glue_streams.cpp b/dbms/src/DataStreams/tests/glue_streams.cpp index 55f3131264b..87a5a98d773 100644 --- a/dbms/src/DataStreams/tests/glue_streams.cpp +++ b/dbms/src/DataStreams/tests/glue_streams.cpp @@ -32,7 +32,7 @@ void forkThread(ForkPtr fork) } -int main(int argc, char ** argv) +int main(int, char **) try { Context context = Context::createGlobal(); diff --git a/dbms/src/DataStreams/tests/tab_separated_streams.cpp b/dbms/src/DataStreams/tests/tab_separated_streams.cpp index 233b2b4a7d4..2cc6abf9835 100644 --- a/dbms/src/DataStreams/tests/tab_separated_streams.cpp +++ b/dbms/src/DataStreams/tests/tab_separated_streams.cpp @@ -16,7 +16,7 @@ using namespace DB; -int main(int argc, char ** argv) +int main(int, char **) try { Block sample; diff --git a/dbms/src/Functions/FunctionsArithmetic.h b/dbms/src/Functions/FunctionsArithmetic.h index baf1ecba1dc..0f5d7cec994 100644 --- a/dbms/src/Functions/FunctionsArithmetic.h +++ b/dbms/src/Functions/FunctionsArithmetic.h @@ -410,24 +410,14 @@ struct AbsImpl { using ResultType = typename NumberTraits::ResultOfAbs::Type; - template - static inline ResultType apply(T a, - typename std::enable_if::value && std::is_signed::value, void>::type * = nullptr) + static inline ResultType apply(A a) { - return a < 0 ? static_cast(~a) + 1 : a; - } - - template - static inline ResultType apply(T a, - typename std::enable_if::value && std::is_unsigned::value, void>::type * = nullptr) - { - return static_cast(a); - } - - template - static inline ResultType apply(T a, typename std::enable_if::value, void>::type * = nullptr) - { - return static_cast(std::abs(a)); + if constexpr (std::is_integral::value && std::is_signed::value) + return a < 0 ? static_cast(~a) + 1 : a; + else if constexpr (std::is_integral::value && std::is_unsigned::value) + return static_cast(a); + else if constexpr (std::is_floating_point::value) + return static_cast(std::abs(a)); } }; @@ -582,21 +572,17 @@ public: private: const Context & context; - /// Overload for InvalidType - template ::value>::type * = nullptr> + template bool checkRightTypeImpl(DataTypePtr & type_res) const { - return false; - } - - /// Overload for well-defined operations - template ::value>::type * = nullptr> - bool checkRightTypeImpl(DataTypePtr & type_res) const - { - type_res = std::make_shared(); - return true; + /// Overload for InvalidType + if constexpr (std::is_same::value) + return false; + else + { + type_res = std::make_shared(); + return true; + } } template @@ -646,27 +632,21 @@ private: } /// Overload for InvalidType - template ::value>::type * = nullptr> - bool executeRightTypeDispatch(Block & block, const ColumnNumbers & arguments, const size_t result, - const ColumnType * col_left) + template + bool executeRightTypeDispatch(Block & block, const ColumnNumbers & arguments, const size_t result, const ColumnType * col_left) { - throw Exception("Types " + String(TypeName::get()) - + " and " + String(TypeName::get()) - + " are incompatible for function " + getName() + " or not upscaleable to common type", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); - } + if constexpr (std::is_same::value) + throw Exception("Types " + String(TypeName::get()) + + " and " + String(TypeName::get()) + + " are incompatible for function " + getName() + " or not upscaleable to common type", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); + else + { + using T0 = typename LeftDataType::FieldType; + using T1 = typename RightDataType::FieldType; + using ResultType = typename ResultDataType::FieldType; - /// Overload for well-defined operations - template ::value>::type * = nullptr> - bool executeRightTypeDispatch(Block & block, const ColumnNumbers & arguments, const size_t result, - const ColumnType * col_left) - { - using T0 = typename LeftDataType::FieldType; - using T1 = typename RightDataType::FieldType; - using ResultType = typename ResultDataType::FieldType; - - return executeRightTypeImpl(block, arguments, result, col_left); + return executeRightTypeImpl(block, arguments, result, col_left); + } } /// ColumnVector overload @@ -923,7 +903,7 @@ class FunctionUnaryArithmetic : public IFunction { public: static constexpr auto name = Name::name; - static FunctionPtr create(const Context & context) { return std::make_shared(); } + static FunctionPtr create(const Context &) { return std::make_shared(); } private: template @@ -1010,7 +990,7 @@ public: return FunctionUnaryArithmeticMonotonicity::has(); } - Monotonicity getMonotonicityForRange(const IDataType & type, const Field & left, const Field & right) const override + Monotonicity getMonotonicityForRange(const IDataType &, const Field & left, const Field & right) const override { return FunctionUnaryArithmeticMonotonicity::get(left, right); } @@ -1070,7 +1050,7 @@ using FunctionLCM = FunctionBinaryArithmetic; template <> struct FunctionUnaryArithmeticMonotonicity { static bool has() { return true; } - static IFunction::Monotonicity get(const Field & left, const Field & right) + static IFunction::Monotonicity get(const Field &, const Field &) { return { true, false }; } @@ -1094,7 +1074,7 @@ template <> struct FunctionUnaryArithmeticMonotonicity template <> struct FunctionUnaryArithmeticMonotonicity { static bool has() { return false; } - static IFunction::Monotonicity get(const Field & left, const Field & right) + static IFunction::Monotonicity get(const Field &, const Field &) { return {}; } @@ -1325,7 +1305,7 @@ private: { const auto size = value_col->size(); bool is_const; - const auto mask = createConstMask(size, block, arguments, is_const); + const auto mask = createConstMask(block, arguments, is_const); const auto & val = value_col->getData(); const auto out_col = std::make_shared>(size); @@ -1351,7 +1331,7 @@ private: { const auto size = value_col->size(); bool is_const; - const auto mask = createConstMask(size, block, arguments, is_const); + const auto mask = createConstMask(block, arguments, is_const); const auto val = value_col->template getValue(); if (is_const) @@ -1378,7 +1358,7 @@ private: } template - ValueType createConstMask(const size_t size, const Block & block, const ColumnNumbers & arguments, bool & is_const) + ValueType createConstMask(const Block & block, const ColumnNumbers & arguments, bool & is_const) { is_const = true; ValueType mask = 0; diff --git a/dbms/src/Storages/MergeTree/DataPartsExchange.cpp b/dbms/src/Storages/MergeTree/DataPartsExchange.cpp index 8aa5e713404..b2b7c2b3392 100644 --- a/dbms/src/Storages/MergeTree/DataPartsExchange.cpp +++ b/dbms/src/Storages/MergeTree/DataPartsExchange.cpp @@ -45,7 +45,7 @@ std::string Service::getId(const std::string & node_id) const return getEndpointId(node_id); } -void Service::processQuery(const Poco::Net::HTMLForm & params, ReadBuffer & body, WriteBuffer & out, Poco::Net::HTTPServerResponse & response) +void Service::processQuery(const Poco::Net::HTMLForm & params, ReadBuffer & /*body*/, WriteBuffer & out, Poco::Net::HTTPServerResponse & response) { if (blocker.isCancelled()) throw Exception("Transferring part to replica was cancelled", ErrorCodes::ABORTED); diff --git a/dbms/src/Storages/MergeTree/MergeTreeBaseBlockInputStream.h b/dbms/src/Storages/MergeTree/MergeTreeBaseBlockInputStream.h index 0797ecd818b..9294cfa7d41 100644 --- a/dbms/src/Storages/MergeTree/MergeTreeBaseBlockInputStream.h +++ b/dbms/src/Storages/MergeTree/MergeTreeBaseBlockInputStream.h @@ -39,7 +39,7 @@ protected: virtual bool getNewTask() = 0; /// We will call progressImpl manually. - void progress(const Progress & value) override {} + void progress(const Progress &) override {} Block readFromPart(); diff --git a/dbms/src/Storages/MergeTree/MergeTreeData.cpp b/dbms/src/Storages/MergeTree/MergeTreeData.cpp index 28c160780f7..e035c7dcc04 100644 --- a/dbms/src/Storages/MergeTree/MergeTreeData.cpp +++ b/dbms/src/Storages/MergeTree/MergeTreeData.cpp @@ -94,8 +94,7 @@ MergeTreeData::MergeTreeData( const String & log_name_, bool require_part_metadata_, bool attach, - BrokenPartCallback broken_part_callback_, - PartsCleanCallback parts_clean_callback_) + BrokenPartCallback broken_part_callback_) : ITableDeclaration{materialized_columns_, alias_columns_, column_defaults_}, context(context_), sampling_expression(sampling_expression_), index_granularity(settings_.index_granularity), @@ -2120,7 +2119,7 @@ MergeTreeData::DataPartsVector MergeTreeData::getDataPartsVector() const } MergeTreeData::DataPartPtr MergeTreeData::getAnyPartInPartition( - const String & partition_id, std::unique_lock & data_parts_lock) + const String & partition_id, std::unique_lock & /*data_parts_lock*/) { auto min_block = std::numeric_limits::min(); MergeTreePartInfo dummy_part_info(partition_id, min_block, min_block, 0); diff --git a/dbms/src/Storages/MergeTree/MergeTreeData.h b/dbms/src/Storages/MergeTree/MergeTreeData.h index 02dee56f777..d98f028b682 100644 --- a/dbms/src/Storages/MergeTree/MergeTreeData.h +++ b/dbms/src/Storages/MergeTree/MergeTreeData.h @@ -93,8 +93,6 @@ class MergeTreeData : public ITableDeclaration public: /// Function to call if the part is suspected to contain corrupt data. using BrokenPartCallback = std::function; - /// Callback to delete outdated parts immediately - using PartsCleanCallback = std::function; using DataPart = MergeTreeDataPart; using MutableDataPartPtr = std::shared_ptr; @@ -290,9 +288,7 @@ public: const String & log_name_, bool require_part_metadata_, bool attach, - BrokenPartCallback broken_part_callback_ = [](const String &){}, - PartsCleanCallback parts_clean_callback_ = nullptr - ); + BrokenPartCallback broken_part_callback_ = [](const String &){}); /// Load the set of data parts from disk. Call once - immediately after the object is created. void loadDataParts(bool skip_sanity_checks); diff --git a/dbms/src/Storages/MergeTree/PKCondition.cpp b/dbms/src/Storages/MergeTree/PKCondition.cpp index 8d5018cc753..ee6fae43521 100644 --- a/dbms/src/Storages/MergeTree/PKCondition.cpp +++ b/dbms/src/Storages/MergeTree/PKCondition.cpp @@ -358,7 +358,6 @@ void PKCondition::traverseAST(const ASTPtr & node, const Context & context, Bloc bool PKCondition::canConstantBeWrappedByMonotonicFunctions( const ASTPtr & node, - const Context & context, size_t & out_primary_key_column_num, DataTypePtr & out_primary_key_column_type, Field & out_value, @@ -537,7 +536,7 @@ bool PKCondition::atomFromAST(const ASTPtr & node, const Context & context, Bloc key_arg_pos = 0; } else if (getConstant(args[1], block_with_constants, const_value, const_type) - && canConstantBeWrappedByMonotonicFunctions(args[0], context, key_column_num, key_expr_type, const_value, const_type)) + && canConstantBeWrappedByMonotonicFunctions(args[0], key_column_num, key_expr_type, const_value, const_type)) { key_arg_pos = 0; is_constant_transformed = true; @@ -548,7 +547,7 @@ bool PKCondition::atomFromAST(const ASTPtr & node, const Context & context, Bloc key_arg_pos = 1; } else if (getConstant(args[0], block_with_constants, const_value, const_type) - && canConstantBeWrappedByMonotonicFunctions(args[1], context, key_column_num, key_expr_type, const_value, const_type)) + && canConstantBeWrappedByMonotonicFunctions(args[1], key_column_num, key_expr_type, const_value, const_type)) { key_arg_pos = 1; is_constant_transformed = true; diff --git a/dbms/src/Storages/MergeTree/PKCondition.h b/dbms/src/Storages/MergeTree/PKCondition.h index 07deeb2ceaf..ab96a160162 100644 --- a/dbms/src/Storages/MergeTree/PKCondition.h +++ b/dbms/src/Storages/MergeTree/PKCondition.h @@ -319,7 +319,6 @@ private: bool canConstantBeWrappedByMonotonicFunctions( const ASTPtr & node, - const Context & context, size_t & out_primary_key_column_num, DataTypePtr & out_primary_key_column_type, Field & out_value, diff --git a/dbms/src/Storages/StorageReplicatedMergeTree.cpp b/dbms/src/Storages/StorageReplicatedMergeTree.cpp index ad39255c03c..1f83246142d 100644 --- a/dbms/src/Storages/StorageReplicatedMergeTree.cpp +++ b/dbms/src/Storages/StorageReplicatedMergeTree.cpp @@ -187,8 +187,7 @@ StorageReplicatedMergeTree::StorageReplicatedMergeTree( context_, primary_expr_ast_, date_column_name, partition_expr_ast_, sampling_expression_, merging_params_, settings_, database_name_ + "." + table_name, true, attach, - [this] (const std::string & name) { enqueuePartForCheck(name); }, - [this] () { clearOldPartsAndRemoveFromZK(); }), + [this] (const std::string & name) { enqueuePartForCheck(name); }), reader(data), writer(data), merger(data, context.getBackgroundPool()), queue(data.format_version), fetcher(data), shutdown_event(false), part_check_thread(*this),