From 8a95eb9dc12c29235a1e5fe44c436efe77a9430b Mon Sep 17 00:00:00 2001 From: alesapin Date: Fri, 14 Dec 2018 16:27:35 +0300 Subject: [PATCH] More tests for parser --- dbms/src/Compression/CompressionCodecZSTD.cpp | 5 ++++ ...4_test_custom_compression_codecs.reference | 7 +++-- .../00804_test_custom_compression_codecs.sql | 29 +++++++++++++++---- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/dbms/src/Compression/CompressionCodecZSTD.cpp b/dbms/src/Compression/CompressionCodecZSTD.cpp index f907ae93498..9da1454a539 100644 --- a/dbms/src/Compression/CompressionCodecZSTD.cpp +++ b/dbms/src/Compression/CompressionCodecZSTD.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -15,6 +16,7 @@ namespace ErrorCodes { extern const int CANNOT_COMPRESS; extern const int CANNOT_DECOMPRESS; + extern const int ILLEGAL_SYNTAX_FOR_CODEC_TYPE; } char CompressionCodecZSTD::getMethodByte() @@ -66,6 +68,9 @@ void registerCodecZSTD(CompressionCodecFactory & factory) int level = 0; if (arguments && !arguments->children.empty()) { + if (arguments->children.size() != 1) + throw Exception("ZSTD codec must have 1 parameter, given " + std::to_string(arguments->children.size()), ErrorCodes::ILLEGAL_SYNTAX_FOR_CODEC_TYPE); + const auto children = arguments->children; const ASTLiteral * literal = static_cast(children[0].get()); level = literal->value.safeGet(); diff --git a/dbms/tests/queries/0_stateless/00804_test_custom_compression_codecs.reference b/dbms/tests/queries/0_stateless/00804_test_custom_compression_codecs.reference index c67c9c6f042..fd1689b374b 100644 --- a/dbms/tests/queries/0_stateless/00804_test_custom_compression_codecs.reference +++ b/dbms/tests/queries/0_stateless/00804_test_custom_compression_codecs.reference @@ -1,3 +1,4 @@ -1 hello -2 world -3 ! +1 hello 2018-12-14 1.1 +2 world 2018-12-15 2.2 +3 ! 2018-12-16 3.3 +2 diff --git a/dbms/tests/queries/0_stateless/00804_test_custom_compression_codecs.sql b/dbms/tests/queries/0_stateless/00804_test_custom_compression_codecs.sql index 60b09a8c7c6..3991232a010 100644 --- a/dbms/tests/queries/0_stateless/00804_test_custom_compression_codecs.sql +++ b/dbms/tests/queries/0_stateless/00804_test_custom_compression_codecs.sql @@ -1,11 +1,30 @@ +SET send_logs_level = 'none'; DROP TABLE IF EXISTS test.compression_codec; -CREATE TABLE test.compression_codec(id UInt64 CODEC(LZ4), data String CODEC(ZSTD)) ENGINE = MergeTree() order by tuple(); +CREATE TABLE test.compression_codec(id UInt64 CODEC(LZ4), data String CODEC(ZSTD), ddd Date CODEC(NONE), somenum Float64 CODEC(ZSTD(2))) ENGINE = MergeTree() ORDER BY tuple(); -INSERT INTO test.compression_codec VALUES(1, 'hello'); -INSERT INTO test.compression_codec VALUES(2, 'world'); -INSERT INTO test.compression_codec VALUES(3, '!'); +INSERT INTO test.compression_codec VALUES(1, 'hello', toDate('2018-12-14'), 1.1); +INSERT INTO test.compression_codec VALUES(2, 'world', toDate('2018-12-15'), 2.2); +INSERT INTO test.compression_codec VALUES(3, '!', toDate('2018-12-16'), 3.3); -SELECT * FROM test.compression_codec order by id; +SELECT * FROM test.compression_codec ORDER BY id; + +OPTIMIZE TABLE test.compression_codec FINAL; + +INSERT INTO test.compression_codec VALUES(2, '', toDate('2018-12-13'), 4.4); + +SELECT count(*) FROM test.compression_codec WHERE id = 2 GROUP BY id; DROP TABLE IF EXISTS test.compression_codec; + +DROP TABLE IF EXISTS test.bad_codec; +DROP TABLE IF EXISTS test.params_when_no_params; +DROP TABLE IF EXISTS test.too_many_params; + +CREATE TABLE test.bad_codec(id UInt64 CODEC(adssadads)) ENGINE = MergeTree() order by tuple(); -- { serverError 429 } +CREATE TABLE test.too_many_params(id UInt64 CODEC(ZSTD(2,3,4,5))) ENGINE = MergeTree() order by tuple(); -- { serverError 428 } +CREATE TABLE test.params_when_no_params(id UInt64 CODEC(LZ4(1))) ENGINE = MergeTree() ORDER BY tuple(); -- { serverError 378 } + +DROP TABLE IF EXISTS test.bad_codec; +DROP TABLE IF EXISTS test.params_when_no_params; +DROP TABLE IF EXISTS test.too_many_params;