From e0efb7e8c1da284add3df22b8135bfb14d0bb599 Mon Sep 17 00:00:00 2001 From: KochetovNicolai Date: Wed, 20 Sep 2017 05:30:44 +0300 Subject: [PATCH] Point in polygon (#1264) * added FunctionPointInPolygonWithGrid [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix PointInPolygonWithGrid [#CLICKHOUSE-3201] * fix PointInPolygonWithGrid [#CLICKHOUSE-3201] * fix PointInPolygonWithGrid [#CLICKHOUSE-3201] * fix PointInPolygonWithGrid [#CLICKHOUSE-3201] * added test for PointInPolygonWithGrid [#CLICKHOUSE-3201] * added test for PointInPolygonWithGrid with holes [#CLICKHOUSE-3201] * added arbitrary orientation for polygons in PointInPolygonWithGrid [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix arbitrary orientation for polygons in PointInPolygonWithGrid [#CLICKHOUSE-3201] * added test for arbitrary orientation for polygons in PointInPolygonWithGrid [#CLICKHOUSE-3201] * fixed shifted grid for PointInPolygonWithGrid, added test [CLICKHOUSE-3201] * expand box for complex polygons in PointInPolygonWithGrid [#CLICKHOUSE-3201] * fixed build [#CLICKHOUSE-3201] * fix expand box for complex polygons in PointInPolygonWithGrid [#CLICKHOUSE-3201] * added pool to PointInPolygonWithGrid [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * changed FunctionPointInPolygonWithGrid signature [#CLICKHOUSE-3201] * changed FunctionPointInPolygonWithGrid signature [#CLICKHOUSE-3201] * fixed test [#CLICKHOUSE-3201] * unified signature for PointInPolygon [#CLICKHOUSE-3201] * fixed build [#CLICKHOUSE-3201] * fixed build [#CLICKHOUSE-3201] * fixed build [#CLICKHOUSE-3201] * fixed build [#CLICKHOUSE-3201] * fixed build [#CLICKHOUSE-3201] * fixed build [#CLICKHOUSE-3201] * fixed build [#CLICKHOUSE-3201] * fixed build [#CLICKHOUSE-3201] * fixed build [#CLICKHOUSE-3201] * fixed build [#CLICKHOUSE-3201] * fixed build [#CLICKHOUSE-3201] * fixed build [#CLICKHOUSE-3201] * supported Float64 for pointInPolygon [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fix build [#CLICKHOUSE-3201] * fixed check for numeric tuple in PointInPolygon function [#CLICKHOUSE-3201] * fixed build [#CLICKHOUSE-3201] * fixed build [#CLICKHOUSE-3201] * added profile events polygons pool [#CLICKHOUSE-3201] * fixed build [#CLICKHOUSE-3201] * fixed build [#CLICKHOUSE-3201] * Update FunctionsGeo.cpp --- dbms/src/Common/ProfileEvents.cpp | 5 +- dbms/src/Functions/FunctionsGeo.cpp | 281 +++++--- dbms/src/Functions/GeoUtils.h | 653 ++++++++++++++++++ .../00500_point_in_polygon.reference | 56 ++ .../0_stateless/00500_point_in_polygon.sql | 84 ++- 5 files changed, 971 insertions(+), 108 deletions(-) create mode 100644 dbms/src/Functions/GeoUtils.h diff --git a/dbms/src/Common/ProfileEvents.cpp b/dbms/src/Common/ProfileEvents.cpp index 70bbee64b75..1488d6c8c0d 100644 --- a/dbms/src/Common/ProfileEvents.cpp +++ b/dbms/src/Common/ProfileEvents.cpp @@ -124,8 +124,9 @@ M(DictCacheLockReadNs) \ \ M(DistributedSyncInsertionTimeoutExceeded) \ - M(DataAfterMergeDiffersFromReplica) - + M(DataAfterMergeDiffersFromReplica) \ + M(PolygonsAddedToPool) \ + M(PolygonsInPoolAllocatedBytes) \ namespace ProfileEvents { diff --git a/dbms/src/Functions/FunctionsGeo.cpp b/dbms/src/Functions/FunctionsGeo.cpp index 2dae9288d71..9cddbb5688e 100644 --- a/dbms/src/Functions/FunctionsGeo.cpp +++ b/dbms/src/Functions/FunctionsGeo.cpp @@ -1,5 +1,7 @@ #include #include +#include +#include #include #include @@ -9,36 +11,79 @@ #include #include #include +#include +#include +#include +namespace ProfileEvents +{ + extern const Event PolygonsAddedToPool; + extern const Event PolygonsInPoolAllocatedBytes; +} namespace DB { + namespace ErrorCodes { extern const int TOO_LESS_ARGUMENTS_FOR_FUNCTION; extern const int BAD_ARGUMENTS; + extern const int ILLEGAL_TYPE_OF_ARGUMENT; } +namespace FunctionPointInPolygonDetail +{ -template -using PointInPolygonCrossing = boost::geometry::strategy::within::crossings_multiply; -template -using PointInPolygonWinding = boost::geometry::strategy::within::winding; -template -using PointInPolygonFranklin = boost::geometry::strategy::within::franklin; +template +ColumnPtr callPointInPolygonImplWithPool(const IColumn & x, const IColumn & y, Polygon & polygon) +{ + using Pool = ObjectPoolMap; + /// C++11 has thread-safe function-local statics on most modern compilers. + static Pool known_polygons; -template