diff --git a/src/Functions/pointInPolygon.cpp b/src/Functions/pointInPolygon.cpp index 00df42bdc1a..25a14699c5d 100644 --- a/src/Functions/pointInPolygon.cpp +++ b/src/Functions/pointInPolygon.cpp @@ -508,20 +508,35 @@ private: void parseConstPolygonFromSingleColumn(Block & block, const ColumnNumbers & arguments, Polygon & out_polygon) const { - ColumnPtr polygon_column_float64 = castColumn( - block.getByPosition(arguments[1]), - std::make_shared( - std::make_shared(DataTypes{ - std::make_shared(), - std::make_shared()}))); - - const ColumnConst & column_const = typeid_cast(*polygon_column_float64); - const IColumn & column_const_data = column_const.getDataColumn(); - if (isTwoDimensionalArray(*block.getByPosition(arguments[1]).type)) + { + ColumnPtr polygon_column_float64 = castColumn( + block.getByPosition(arguments[1]), + std::make_shared( + std::make_shared( + std::make_shared(DataTypes{ + std::make_shared(), + std::make_shared()})))); + + const ColumnConst & column_const = typeid_cast(*polygon_column_float64); + const IColumn & column_const_data = column_const.getDataColumn(); + parseConstPolygonWithHolesFromSingleColumn(column_const_data, 0, out_polygon); + } else + { + ColumnPtr polygon_column_float64 = castColumn( + block.getByPosition(arguments[1]), + std::make_shared( + std::make_shared(DataTypes{ + std::make_shared(), + std::make_shared()}))); + + const ColumnConst & column_const = typeid_cast(*polygon_column_float64); + const IColumn & column_const_data = column_const.getDataColumn(); + parseConstPolygonWithoutHolesFromSingleColumn(column_const_data, 0, out_polygon); + } } void parseConstPolygon(Block & block, const ColumnNumbers & arguments, Polygon & out_polygon) const diff --git a/tests/queries/0_stateless/00500_point_in_polygon_2d_const.reference b/tests/queries/0_stateless/00500_point_in_polygon_2d_const.reference new file mode 100644 index 00000000000..e439850d6fa --- /dev/null +++ b/tests/queries/0_stateless/00500_point_in_polygon_2d_const.reference @@ -0,0 +1,2 @@ +1 +a diff --git a/tests/queries/0_stateless/00500_point_in_polygon_2d_const.sql b/tests/queries/0_stateless/00500_point_in_polygon_2d_const.sql new file mode 100644 index 00000000000..53d741b609f --- /dev/null +++ b/tests/queries/0_stateless/00500_point_in_polygon_2d_const.sql @@ -0,0 +1,14 @@ +SELECT pointInPolygon((0, 0), [[(0, 0), (10, 0), (10, 10), (0, 10)]]); + +DROP TABLE IF EXISTS s; +create table s (`id` String, `lng` Int64, `lat` Int64) engine = Memory(); + +DROP TABLE IF EXISTS p; +CREATE TABLE p ( `polygon_id` Int64, `polygon_name` String, `shape` Array(Array(Tuple(Float64, Float64))), `state` String ) engine = Memory(); + +INSERT INTO s VALUES ( 'a', 0, 0 ); +INSERT INTO p VALUES (8, 'a', [[(0, 0), (10, 0), (10, 10), (0, 10)]], 'a'); +SELECT id FROM s WHERE pointInPolygon((lng,lat), (select shape from p where polygon_id = 8)); + +DROP TABLE s; +DROP TABLE p;