Add OneBucketPolygonDictionary

This commit is contained in:
Arthur Petukhovsky 2020-03-23 03:16:46 +03:00
parent 52fc7b3147
commit d8d0264acc
3 changed files with 58 additions and 1 deletions

View File

@ -187,6 +187,36 @@ bool SmartPolygonDictionary::find(const Point & point, size_t & id) const
return found; 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<const IExternalLoadable> OneBucketPolygonDictionary::clone() const
{
return std::make_shared<OneBucketPolygonDictionary>(
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 <class PolygonDictionary> template <class PolygonDictionary>
DictionaryPtr createLayout(const std::string &, DictionaryPtr createLayout(const std::string &,
const DictionaryStructure & dict_struct, const DictionaryStructure & dict_struct,
@ -255,6 +285,7 @@ void registerDictionaryPolygon(DictionaryFactory & factory)
factory.registerLayout("polygon", createLayout<SimplePolygonDictionary>, true); factory.registerLayout("polygon", createLayout<SimplePolygonDictionary>, true);
factory.registerLayout("grid_polygon", createLayout<GridPolygonDictionary>, true); factory.registerLayout("grid_polygon", createLayout<GridPolygonDictionary>, true);
factory.registerLayout("bucket_polygon", createLayout<SmartPolygonDictionary>, true); factory.registerLayout("bucket_polygon", createLayout<SmartPolygonDictionary>, true);
factory.registerLayout("one_bucket_polygon", createLayout<OneBucketPolygonDictionary>, true);
} }
} }

View File

@ -82,5 +82,26 @@ private:
static constexpr size_t kMaxDepth = 7; 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<const IExternalLoadable> clone() const override;
private:
bool find(const Point & point, size_t & id) const override;
BucketsPolygonIndex buckets_idx;
};
} }

View File

@ -138,7 +138,8 @@ private:
!executeDispatchComplex<TrieDictionary>(block, arguments, result, dict_ptr) && !executeDispatchComplex<TrieDictionary>(block, arguments, result, dict_ptr) &&
!executeDispatchComplex<SimplePolygonDictionary>(block, arguments, result, dict_ptr) && !executeDispatchComplex<SimplePolygonDictionary>(block, arguments, result, dict_ptr) &&
!executeDispatchComplex<GridPolygonDictionary>(block, arguments, result, dict_ptr) && !executeDispatchComplex<GridPolygonDictionary>(block, arguments, result, dict_ptr) &&
!executeDispatchComplex<SmartPolygonDictionary>(block, arguments, result, dict_ptr)) !executeDispatchComplex<SmartPolygonDictionary>(block, arguments, result, dict_ptr) &&
!executeDispatchComplex<OneBucketPolygonDictionary>(block, arguments, result, dict_ptr))
throw Exception{"Unsupported dictionary type " + dict_ptr->getTypeName(), ErrorCodes::UNKNOWN_TYPE}; throw Exception{"Unsupported dictionary type " + dict_ptr->getTypeName(), ErrorCodes::UNKNOWN_TYPE};
} }
@ -312,6 +313,7 @@ private:
!executeDispatchComplex<SimplePolygonDictionary>(block, arguments, result, dict_ptr) && !executeDispatchComplex<SimplePolygonDictionary>(block, arguments, result, dict_ptr) &&
!executeDispatchComplex<GridPolygonDictionary>(block, arguments, result, dict_ptr) && !executeDispatchComplex<GridPolygonDictionary>(block, arguments, result, dict_ptr) &&
!executeDispatchComplex<SmartPolygonDictionary>(block, arguments, result, dict_ptr) && !executeDispatchComplex<SmartPolygonDictionary>(block, arguments, result, dict_ptr) &&
!executeDispatchComplex<OneBucketPolygonDictionary>(block, arguments, result, dict_ptr) &&
!executeDispatchRange<RangeHashedDictionary>(block, arguments, result, dict_ptr)) !executeDispatchRange<RangeHashedDictionary>(block, arguments, result, dict_ptr))
throw Exception{"Unsupported dictionary type " + dict_ptr->getTypeName(), ErrorCodes::UNKNOWN_TYPE}; throw Exception{"Unsupported dictionary type " + dict_ptr->getTypeName(), ErrorCodes::UNKNOWN_TYPE};
} }
@ -495,6 +497,7 @@ private:
!executeDispatchComplex<SimplePolygonDictionary>(block, arguments, result, dict_ptr) && !executeDispatchComplex<SimplePolygonDictionary>(block, arguments, result, dict_ptr) &&
!executeDispatchComplex<GridPolygonDictionary>(block, arguments, result, dict_ptr) && !executeDispatchComplex<GridPolygonDictionary>(block, arguments, result, dict_ptr) &&
!executeDispatchComplex<SmartPolygonDictionary>(block, arguments, result, dict_ptr) && !executeDispatchComplex<SmartPolygonDictionary>(block, arguments, result, dict_ptr) &&
!executeDispatchComplex<OneBucketPolygonDictionary>(block, arguments, result, dict_ptr) &&
!executeDispatchComplex<TrieDictionary>(block, arguments, result, dict_ptr)) !executeDispatchComplex<TrieDictionary>(block, arguments, result, dict_ptr))
throw Exception{"Unsupported dictionary type " + dict_ptr->getTypeName(), ErrorCodes::UNKNOWN_TYPE}; throw Exception{"Unsupported dictionary type " + dict_ptr->getTypeName(), ErrorCodes::UNKNOWN_TYPE};
} }
@ -836,6 +839,7 @@ private:
!executeDispatchComplex<SimplePolygonDictionary>(block, arguments, result, dict_ptr) && !executeDispatchComplex<SimplePolygonDictionary>(block, arguments, result, dict_ptr) &&
!executeDispatchComplex<GridPolygonDictionary>(block, arguments, result, dict_ptr) && !executeDispatchComplex<GridPolygonDictionary>(block, arguments, result, dict_ptr) &&
!executeDispatchComplex<SmartPolygonDictionary>(block, arguments, result, dict_ptr) && !executeDispatchComplex<SmartPolygonDictionary>(block, arguments, result, dict_ptr) &&
!executeDispatchComplex<OneBucketPolygonDictionary>(block, arguments, result, dict_ptr) &&
!executeDispatchRange<RangeHashedDictionary>(block, arguments, result, dict_ptr)) !executeDispatchRange<RangeHashedDictionary>(block, arguments, result, dict_ptr))
throw Exception{"Unsupported dictionary type " + dict_ptr->getTypeName(), ErrorCodes::UNKNOWN_TYPE}; throw Exception{"Unsupported dictionary type " + dict_ptr->getTypeName(), ErrorCodes::UNKNOWN_TYPE};
} }
@ -1097,6 +1101,7 @@ private:
!executeDispatchComplex<SimplePolygonDictionary>(block, arguments, result, dict_ptr) && !executeDispatchComplex<SimplePolygonDictionary>(block, arguments, result, dict_ptr) &&
!executeDispatchComplex<GridPolygonDictionary>(block, arguments, result, dict_ptr) && !executeDispatchComplex<GridPolygonDictionary>(block, arguments, result, dict_ptr) &&
!executeDispatchComplex<SmartPolygonDictionary>(block, arguments, result, dict_ptr) && !executeDispatchComplex<SmartPolygonDictionary>(block, arguments, result, dict_ptr) &&
!executeDispatchComplex<OneBucketPolygonDictionary>(block, arguments, result, dict_ptr) &&
!executeDispatchComplex<TrieDictionary>(block, arguments, result, dict_ptr)) !executeDispatchComplex<TrieDictionary>(block, arguments, result, dict_ptr))
throw Exception{"Unsupported dictionary type " + dict_ptr->getTypeName(), ErrorCodes::UNKNOWN_TYPE}; throw Exception{"Unsupported dictionary type " + dict_ptr->getTypeName(), ErrorCodes::UNKNOWN_TYPE};
} }