From 0c8e12affd2967d6716e2fafd84348610bfc0134 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Thu, 9 Jul 2020 03:46:00 +0300 Subject: [PATCH] Remove ridiculous code --- src/Compression/CompressionCodecDelta.cpp | 8 +++++++- src/Compression/CompressionCodecDelta.h | 3 --- src/Compression/CompressionCodecDoubleDelta.cpp | 6 +++++- src/Compression/CompressionCodecDoubleDelta.h | 3 --- src/Compression/CompressionCodecGorilla.cpp | 10 +++++++--- src/Compression/CompressionCodecGorilla.h | 3 --- src/Compression/CompressionCodecLZ4.h | 5 ----- src/Compression/CompressionCodecMultiple.cpp | 8 -------- src/Compression/CompressionCodecMultiple.h | 5 ----- src/Compression/CompressionCodecNone.h | 2 -- src/Compression/CompressionCodecT64.h | 3 --- src/Compression/CompressionCodecZSTD.h | 4 ---- src/Compression/CompressionFactory.cpp | 7 ++++--- .../0_stateless/01380_coded_delta_exception_code.sql | 3 +++ 14 files changed, 26 insertions(+), 44 deletions(-) diff --git a/src/Compression/CompressionCodecDelta.cpp b/src/Compression/CompressionCodecDelta.cpp index 58ba95d7765..f7de36288dc 100644 --- a/src/Compression/CompressionCodecDelta.cpp +++ b/src/Compression/CompressionCodecDelta.cpp @@ -166,7 +166,8 @@ void registerCodecDelta(CompressionCodecFactory & factory) UInt8 method_code = UInt8(CompressionMethodByte::Delta); factory.registerCompressionCodecWithType("Delta", method_code, [&](const ASTPtr & arguments, DataTypePtr column_type) -> CompressionCodecPtr { - UInt8 delta_bytes_size = getDeltaBytesSize(column_type); + UInt8 delta_bytes_size; + if (arguments && !arguments->children.empty()) { if (arguments->children.size() > 1) @@ -182,6 +183,11 @@ void registerCodecDelta(CompressionCodecFactory & factory) throw Exception("Delta value for delta codec can be 1, 2, 4 or 8, given " + toString(user_bytes_size), ErrorCodes::ILLEGAL_CODEC_PARAMETER); delta_bytes_size = static_cast(user_bytes_size); } + else + { + delta_bytes_size = getDeltaBytesSize(column_type); + } + return std::make_shared(delta_bytes_size); }); } diff --git a/src/Compression/CompressionCodecDelta.h b/src/Compression/CompressionCodecDelta.h index 1077a791535..b7b35a83c85 100644 --- a/src/Compression/CompressionCodecDelta.h +++ b/src/Compression/CompressionCodecDelta.h @@ -30,7 +30,4 @@ private: UInt8 delta_bytes_size; }; -class CompressionCodecFactory; -void registerCodecDelta(CompressionCodecFactory & factory); - } diff --git a/src/Compression/CompressionCodecDoubleDelta.cpp b/src/Compression/CompressionCodecDoubleDelta.cpp index 07486d8d2e8..bdd33bcc983 100644 --- a/src/Compression/CompressionCodecDoubleDelta.cpp +++ b/src/Compression/CompressionCodecDoubleDelta.cpp @@ -419,8 +419,12 @@ void CompressionCodecDoubleDelta::useInfoAboutType(DataTypePtr data_type) void registerCodecDoubleDelta(CompressionCodecFactory & factory) { UInt8 method_code = UInt8(CompressionMethodByte::DoubleDelta); - factory.registerCompressionCodecWithType("DoubleDelta", method_code, [&](const ASTPtr &, DataTypePtr column_type) -> CompressionCodecPtr + factory.registerCompressionCodecWithType("DoubleDelta", method_code, + [&](const ASTPtr & arguments, DataTypePtr column_type) -> CompressionCodecPtr { + if (arguments) + throw Exception("Codec DoubleDelta does not accept any arguments", ErrorCodes::BAD_ARGUMENTS); + UInt8 delta_bytes_size = getDataBytesSize(column_type); return std::make_shared(delta_bytes_size); }); diff --git a/src/Compression/CompressionCodecDoubleDelta.h b/src/Compression/CompressionCodecDoubleDelta.h index 7803a29c34a..c1f6e847382 100644 --- a/src/Compression/CompressionCodecDoubleDelta.h +++ b/src/Compression/CompressionCodecDoubleDelta.h @@ -116,7 +116,4 @@ private: UInt8 data_bytes_size; }; -class CompressionCodecFactory; -void registerCodecDoubleDelta(CompressionCodecFactory & factory); - } diff --git a/src/Compression/CompressionCodecGorilla.cpp b/src/Compression/CompressionCodecGorilla.cpp index 562e7ab4def..2a1688ed76b 100644 --- a/src/Compression/CompressionCodecGorilla.cpp +++ b/src/Compression/CompressionCodecGorilla.cpp @@ -336,10 +336,14 @@ void CompressionCodecGorilla::useInfoAboutType(DataTypePtr data_type) void registerCodecGorilla(CompressionCodecFactory & factory) { UInt8 method_code = UInt8(CompressionMethodByte::Gorilla); - factory.registerCompressionCodecWithType("Gorilla", method_code, [&](const ASTPtr &, DataTypePtr column_type) -> CompressionCodecPtr + factory.registerCompressionCodecWithType("Gorilla", method_code, + [&](const ASTPtr & arguments, DataTypePtr column_type) -> CompressionCodecPtr { - UInt8 delta_bytes_size = getDataBytesSize(column_type); - return std::make_shared(delta_bytes_size); + if (arguments) + throw Exception("Codec Gorilla does not accept any arguments", ErrorCodes::BAD_ARGUMENTS); + + UInt8 data_bytes_size = getDataBytesSize(column_type); + return std::make_shared(data_bytes_size); }); } } diff --git a/src/Compression/CompressionCodecGorilla.h b/src/Compression/CompressionCodecGorilla.h index d11aeed6056..f2d874901a4 100644 --- a/src/Compression/CompressionCodecGorilla.h +++ b/src/Compression/CompressionCodecGorilla.h @@ -113,7 +113,4 @@ private: UInt8 data_bytes_size; }; -class CompressionCodecFactory; -void registerCodecGorilla(CompressionCodecFactory & factory); - } diff --git a/src/Compression/CompressionCodecLZ4.h b/src/Compression/CompressionCodecLZ4.h index a73dd48a36c..0cfa694c416 100644 --- a/src/Compression/CompressionCodecLZ4.h +++ b/src/Compression/CompressionCodecLZ4.h @@ -32,8 +32,6 @@ private: mutable LZ4::PerformanceStatistics lz4_stat; }; -class CompressionCodecFactory; -void registerCodecLZ4(CompressionCodecFactory & factory); class CompressionCodecLZ4HC : public CompressionCodecLZ4 { @@ -50,7 +48,4 @@ private: const int level; }; -class CompressionCodecFactory; -void registerCodecLZ4HC(CompressionCodecFactory & factory); - } diff --git a/src/Compression/CompressionCodecMultiple.cpp b/src/Compression/CompressionCodecMultiple.cpp index d9a8c3cf8df..d157d1e2502 100644 --- a/src/Compression/CompressionCodecMultiple.cpp +++ b/src/Compression/CompressionCodecMultiple.cpp @@ -155,12 +155,4 @@ bool CompressionCodecMultiple::isCompression() const return false; } -void registerCodecMultiple(CompressionCodecFactory & factory) -{ - factory.registerSimpleCompressionCodec("Multiple", static_cast(CompressionMethodByte::Multiple), [&] () - { - return std::make_shared(); - }); -} - } diff --git a/src/Compression/CompressionCodecMultiple.h b/src/Compression/CompressionCodecMultiple.h index ff208d619cb..00e5b50642a 100644 --- a/src/Compression/CompressionCodecMultiple.h +++ b/src/Compression/CompressionCodecMultiple.h @@ -8,7 +8,6 @@ namespace DB class CompressionCodecMultiple final : public ICompressionCodec { public: - CompressionCodecMultiple() = default; CompressionCodecMultiple(Codecs codecs_, bool sanity_check); uint8_t getMethodByte() const override; @@ -33,8 +32,4 @@ private: String getCodecDescImpl() const; }; - -class CompressionCodecFactory; -void registerCodecMultiple(CompressionCodecFactory & factory); - } diff --git a/src/Compression/CompressionCodecNone.h b/src/Compression/CompressionCodecNone.h index ef7029e244b..88bd8790810 100644 --- a/src/Compression/CompressionCodecNone.h +++ b/src/Compression/CompressionCodecNone.h @@ -25,6 +25,4 @@ protected: bool isNone() const override { return true; } }; -class CompressionCodecFactory; -void registerCodecNone(CompressionCodecFactory & factory); } diff --git a/src/Compression/CompressionCodecT64.h b/src/Compression/CompressionCodecT64.h index cafc9959a9d..d95a370985a 100644 --- a/src/Compression/CompressionCodecT64.h +++ b/src/Compression/CompressionCodecT64.h @@ -56,7 +56,4 @@ private: Variant variant; }; -class CompressionCodecFactory; -void registerCodecT64(CompressionCodecFactory & factory); - } diff --git a/src/Compression/CompressionCodecZSTD.h b/src/Compression/CompressionCodecZSTD.h index 234f49b279b..d0790f2f2d7 100644 --- a/src/Compression/CompressionCodecZSTD.h +++ b/src/Compression/CompressionCodecZSTD.h @@ -33,8 +33,4 @@ private: const int level; }; - -class CompressionCodecFactory; -void registerCodecZSTD(CompressionCodecFactory & factory); - } diff --git a/src/Compression/CompressionFactory.cpp b/src/Compression/CompressionFactory.cpp index 2598fc07b08..d284e79cdef 100644 --- a/src/Compression/CompressionFactory.cpp +++ b/src/Compression/CompressionFactory.cpp @@ -9,7 +9,6 @@ #include #include #include -#include #include @@ -146,6 +145,8 @@ void CompressionCodecFactory::registerSimpleCompressionCodec( void registerCodecNone(CompressionCodecFactory & factory); +void registerCodecLZ4(CompressionCodecFactory & factory); +void registerCodecLZ4HC(CompressionCodecFactory & factory); void registerCodecZSTD(CompressionCodecFactory & factory); void registerCodecDelta(CompressionCodecFactory & factory); void registerCodecT64(CompressionCodecFactory & factory); @@ -154,16 +155,16 @@ void registerCodecGorilla(CompressionCodecFactory & factory); CompressionCodecFactory::CompressionCodecFactory() { - default_codec = std::make_shared(); registerCodecLZ4(*this); registerCodecNone(*this); registerCodecZSTD(*this); - registerCodecMultiple(*this); registerCodecLZ4HC(*this); registerCodecDelta(*this); registerCodecT64(*this); registerCodecDoubleDelta(*this); registerCodecGorilla(*this); + + default_codec = get("LZ4", {}, false); } CompressionCodecFactory & CompressionCodecFactory::instance() diff --git a/tests/queries/0_stateless/01380_coded_delta_exception_code.sql b/tests/queries/0_stateless/01380_coded_delta_exception_code.sql index 3460caeef9a..fc679e30e3f 100644 --- a/tests/queries/0_stateless/01380_coded_delta_exception_code.sql +++ b/tests/queries/0_stateless/01380_coded_delta_exception_code.sql @@ -5,3 +5,6 @@ CREATE TABLE delta_codec_synthetic (`id` UInt64 NULL CODEC(Gorilla, ZSTD(22))) E CREATE TABLE delta_codec_synthetic (`id` Decimal(38, 10) CODEC(Delta, ZSTD(22))) ENGINE = MergeTree() ORDER BY tuple(); -- { serverError 36 } CREATE TABLE delta_codec_synthetic (`id` Decimal(38, 10) CODEC(DoubleDelta, ZSTD(22))) ENGINE = MergeTree() ORDER BY tuple(); -- { serverError 36 } CREATE TABLE delta_codec_synthetic (`id` Decimal(38, 10) CODEC(Gorilla, ZSTD(22))) ENGINE = MergeTree() ORDER BY tuple(); -- { serverError 36 } + +CREATE TABLE delta_codec_synthetic (`id` UInt64 CODEC(DoubleDelta(3), ZSTD(22))) ENGINE = MergeTree() ORDER BY tuple(); -- { serverError 36 } +CREATE TABLE delta_codec_synthetic (`id` UInt64 CODEC(Gorilla('hello, world'), ZSTD(22))) ENGINE = MergeTree() ORDER BY tuple(); -- { serverError 36 }