From d8d0264acca5beee9e3e6929a60e788e332668af Mon Sep 17 00:00:00 2001 From: Arthur Petukhovsky Date: Mon, 23 Mar 2020 03:16:46 +0300 Subject: [PATCH] Add OneBucketPolygonDictionary --- .../PolygonDictionaryImplementations.cpp | 31 +++++++++++++++++++ .../PolygonDictionaryImplementations.h | 21 +++++++++++++ .../Functions/FunctionsExternalDictionaries.h | 7 ++++- 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/dbms/src/Dictionaries/PolygonDictionaryImplementations.cpp b/dbms/src/Dictionaries/PolygonDictionaryImplementations.cpp index 5f3b1d25cf4..55f9e2a5507 100644 --- a/dbms/src/Dictionaries/PolygonDictionaryImplementations.cpp +++ b/dbms/src/Dictionaries/PolygonDictionaryImplementations.cpp @@ -187,6 +187,36 @@ bool SmartPolygonDictionary::find(const Point & point, size_t & id) const return found; } +OneBucketPolygonDictionary::OneBucketPolygonDictionary( + const std::string & database_, + const std::string & name_, + const DictionaryStructure & dict_struct_, + DictionarySourcePtr source_ptr_, + const DictionaryLifetime dict_lifetime_, + InputType input_type_, + PointType point_type_) + : IPolygonDictionary(database_, name_, dict_struct_, std::move(source_ptr_), dict_lifetime_, input_type_, point_type_), + buckets_idx(this->polygons) +{ +} + +std::shared_ptr OneBucketPolygonDictionary::clone() const +{ + return std::make_shared( + this->database, + this->name, + this->dict_struct, + this->source_ptr->clone(), + this->dict_lifetime, + this->input_type, + this->point_type); +} + +bool OneBucketPolygonDictionary::find(const Point & point, size_t & id) const +{ + return this->buckets_idx.find(point, id); +} + template DictionaryPtr createLayout(const std::string &, const DictionaryStructure & dict_struct, @@ -255,6 +285,7 @@ void registerDictionaryPolygon(DictionaryFactory & factory) factory.registerLayout("polygon", createLayout, true); factory.registerLayout("grid_polygon", createLayout, true); factory.registerLayout("bucket_polygon", createLayout, true); + factory.registerLayout("one_bucket_polygon", createLayout, true); } } diff --git a/dbms/src/Dictionaries/PolygonDictionaryImplementations.h b/dbms/src/Dictionaries/PolygonDictionaryImplementations.h index 0f328a6fe3a..55ace80eb40 100644 --- a/dbms/src/Dictionaries/PolygonDictionaryImplementations.h +++ b/dbms/src/Dictionaries/PolygonDictionaryImplementations.h @@ -82,5 +82,26 @@ private: static constexpr size_t kMaxDepth = 7; }; +/** Uses single BucketsPolygonIndex for all queries. */ +class OneBucketPolygonDictionary : public IPolygonDictionary +{ +public: + OneBucketPolygonDictionary( + const std::string & database_, + const std::string & name_, + const DictionaryStructure & dict_struct_, + DictionarySourcePtr source_ptr_, + DictionaryLifetime dict_lifetime_, + InputType input_type_, + PointType point_type_); + + std::shared_ptr clone() const override; + +private: + bool find(const Point & point, size_t & id) const override; + + BucketsPolygonIndex buckets_idx; +}; + } diff --git a/dbms/src/Functions/FunctionsExternalDictionaries.h b/dbms/src/Functions/FunctionsExternalDictionaries.h index 56f722cb2ed..299db7e0fbd 100644 --- a/dbms/src/Functions/FunctionsExternalDictionaries.h +++ b/dbms/src/Functions/FunctionsExternalDictionaries.h @@ -138,7 +138,8 @@ private: !executeDispatchComplex(block, arguments, result, dict_ptr) && !executeDispatchComplex(block, arguments, result, dict_ptr) && !executeDispatchComplex(block, arguments, result, dict_ptr) && - !executeDispatchComplex(block, arguments, result, dict_ptr)) + !executeDispatchComplex(block, arguments, result, dict_ptr) && + !executeDispatchComplex(block, arguments, result, dict_ptr)) throw Exception{"Unsupported dictionary type " + dict_ptr->getTypeName(), ErrorCodes::UNKNOWN_TYPE}; } @@ -312,6 +313,7 @@ private: !executeDispatchComplex(block, arguments, result, dict_ptr) && !executeDispatchComplex(block, arguments, result, dict_ptr) && !executeDispatchComplex(block, arguments, result, dict_ptr) && + !executeDispatchComplex(block, arguments, result, dict_ptr) && !executeDispatchRange(block, arguments, result, dict_ptr)) throw Exception{"Unsupported dictionary type " + dict_ptr->getTypeName(), ErrorCodes::UNKNOWN_TYPE}; } @@ -495,6 +497,7 @@ private: !executeDispatchComplex(block, arguments, result, dict_ptr) && !executeDispatchComplex(block, arguments, result, dict_ptr) && !executeDispatchComplex(block, arguments, result, dict_ptr) && + !executeDispatchComplex(block, arguments, result, dict_ptr) && !executeDispatchComplex(block, arguments, result, dict_ptr)) throw Exception{"Unsupported dictionary type " + dict_ptr->getTypeName(), ErrorCodes::UNKNOWN_TYPE}; } @@ -836,6 +839,7 @@ private: !executeDispatchComplex(block, arguments, result, dict_ptr) && !executeDispatchComplex(block, arguments, result, dict_ptr) && !executeDispatchComplex(block, arguments, result, dict_ptr) && + !executeDispatchComplex(block, arguments, result, dict_ptr) && !executeDispatchRange(block, arguments, result, dict_ptr)) throw Exception{"Unsupported dictionary type " + dict_ptr->getTypeName(), ErrorCodes::UNKNOWN_TYPE}; } @@ -1097,6 +1101,7 @@ private: !executeDispatchComplex(block, arguments, result, dict_ptr) && !executeDispatchComplex(block, arguments, result, dict_ptr) && !executeDispatchComplex(block, arguments, result, dict_ptr) && + !executeDispatchComplex(block, arguments, result, dict_ptr) && !executeDispatchComplex(block, arguments, result, dict_ptr)) throw Exception{"Unsupported dictionary type " + dict_ptr->getTypeName(), ErrorCodes::UNKNOWN_TYPE}; }