From 1795c583a11098eb2b679bf13ff84092859b6b8a Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sun, 18 Dec 2022 08:00:32 +0100 Subject: [PATCH 1/2] Add a test for #29883 --- programs/server/config.d/graphite.xml | 1 + tests/queries/0_stateless/02508_bad_graphite.reference | 0 tests/queries/0_stateless/02508_bad_graphite.sql | 6 ++++++ 3 files changed, 7 insertions(+) create mode 120000 programs/server/config.d/graphite.xml create mode 100644 tests/queries/0_stateless/02508_bad_graphite.reference create mode 100644 tests/queries/0_stateless/02508_bad_graphite.sql diff --git a/programs/server/config.d/graphite.xml b/programs/server/config.d/graphite.xml new file mode 120000 index 00000000000..69a0411e243 --- /dev/null +++ b/programs/server/config.d/graphite.xml @@ -0,0 +1 @@ +../../../tests/config/config.d/graphite.xml \ No newline at end of file diff --git a/tests/queries/0_stateless/02508_bad_graphite.reference b/tests/queries/0_stateless/02508_bad_graphite.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/queries/0_stateless/02508_bad_graphite.sql b/tests/queries/0_stateless/02508_bad_graphite.sql new file mode 100644 index 00000000000..a0ca9dcf690 --- /dev/null +++ b/tests/queries/0_stateless/02508_bad_graphite.sql @@ -0,0 +1,6 @@ +DROP TABLE IF EXISTS test_graphite; +create table test_graphite (key UInt32, Path String, Time DateTime('UTC'), Value UInt8, Version UInt32, col UInt64) + engine = GraphiteMergeTree('graphite_rollup') order by key; + +INSERT INTO test_graphite (key) VALUES (0); -- { serverError BAD_ARGUMENTS } +DROP TABLE test_graphite; From 3e8dcdc155fd86cdbcf0775d5d5c3f044070c988 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sun, 18 Dec 2022 08:01:43 +0100 Subject: [PATCH 2/2] Add earlier check --- src/Processors/Merges/Algorithms/Graphite.cpp | 3 +-- .../Merges/Algorithms/GraphiteRollupSortedAlgorithm.cpp | 9 +++++++++ src/Storages/MergeTree/registerStorageMergeTree.cpp | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Processors/Merges/Algorithms/Graphite.cpp b/src/Processors/Merges/Algorithms/Graphite.cpp index c5c611366ff..0616c4bd6e6 100644 --- a/src/Processors/Merges/Algorithms/Graphite.cpp +++ b/src/Processors/Merges/Algorithms/Graphite.cpp @@ -332,8 +332,7 @@ std::string buildTaggedRegex(std::string regexp_str) * * */ -static const Pattern & -appendGraphitePattern( +static const Pattern & appendGraphitePattern( const Poco::Util::AbstractConfiguration & config, const String & config_element, Patterns & patterns, bool default_rule, diff --git a/src/Processors/Merges/Algorithms/GraphiteRollupSortedAlgorithm.cpp b/src/Processors/Merges/Algorithms/GraphiteRollupSortedAlgorithm.cpp index 467ded19f4d..c5937fe0bc5 100644 --- a/src/Processors/Merges/Algorithms/GraphiteRollupSortedAlgorithm.cpp +++ b/src/Processors/Merges/Algorithms/GraphiteRollupSortedAlgorithm.cpp @@ -9,6 +9,12 @@ namespace DB { +namespace ErrorCodes +{ + extern const int BAD_ARGUMENTS; +} + + static GraphiteRollupSortedAlgorithm::ColumnsDefinition defineColumns( const Block & header, const Graphite::Params & params) { @@ -26,6 +32,9 @@ static GraphiteRollupSortedAlgorithm::ColumnsDefinition defineColumns( if (i != def.time_column_num && i != def.value_column_num && i != def.version_column_num) def.unmodified_column_numbers.push_back(i); + if (!WhichDataType(header.getByPosition(def.value_column_num).type).isFloat64()) + throw Exception("Only `Float64` data type is allowed for the value column of GraphiteMergeTree", ErrorCodes::BAD_ARGUMENTS); + return def; } diff --git a/src/Storages/MergeTree/registerStorageMergeTree.cpp b/src/Storages/MergeTree/registerStorageMergeTree.cpp index ae2abaf8ea5..c34d7d4dacf 100644 --- a/src/Storages/MergeTree/registerStorageMergeTree.cpp +++ b/src/Storages/MergeTree/registerStorageMergeTree.cpp @@ -468,7 +468,7 @@ static StoragePtr create(const StorageFactory::Arguments & args) { String graphite_config_name; String error_msg - = "Last parameter of GraphiteMergeTree must be name (in single quotes) of element in configuration file with Graphite options"; + = "Last parameter of GraphiteMergeTree must be the name (in single quotes) of the element in configuration file with the Graphite options"; error_msg += getMergeTreeVerboseHelp(is_extended_storage_def); if (const auto * ast = engine_args[arg_cnt - 1]->as())