Fix pointInPolygon with const 2d array

This commit is contained in:
Alexey Ilyukhov 2020-08-26 01:13:47 +03:00
parent 1e1b30dc05
commit f32b7f48f1
3 changed files with 41 additions and 10 deletions

View File

@ -507,6 +507,23 @@ private:
} }
void parseConstPolygonFromSingleColumn(Block & block, const ColumnNumbers & arguments, Polygon & out_polygon) const void parseConstPolygonFromSingleColumn(Block & block, const ColumnNumbers & arguments, Polygon & out_polygon) const
{
if (isTwoDimensionalArray(*block.getByPosition(arguments[1]).type))
{
ColumnPtr polygon_column_float64 = castColumn(
block.getByPosition(arguments[1]),
std::make_shared<DataTypeArray>(
std::make_shared<DataTypeArray>(
std::make_shared<DataTypeTuple>(DataTypes{
std::make_shared<DataTypeFloat64>(),
std::make_shared<DataTypeFloat64>()}))));
const ColumnConst & column_const = typeid_cast<const ColumnConst &>(*polygon_column_float64);
const IColumn & column_const_data = column_const.getDataColumn();
parseConstPolygonWithHolesFromSingleColumn(column_const_data, 0, out_polygon);
}
else
{ {
ColumnPtr polygon_column_float64 = castColumn( ColumnPtr polygon_column_float64 = castColumn(
block.getByPosition(arguments[1]), block.getByPosition(arguments[1]),
@ -518,11 +535,9 @@ private:
const ColumnConst & column_const = typeid_cast<const ColumnConst &>(*polygon_column_float64); const ColumnConst & column_const = typeid_cast<const ColumnConst &>(*polygon_column_float64);
const IColumn & column_const_data = column_const.getDataColumn(); const IColumn & column_const_data = column_const.getDataColumn();
if (isTwoDimensionalArray(*block.getByPosition(arguments[1]).type))
parseConstPolygonWithHolesFromSingleColumn(column_const_data, 0, out_polygon);
else
parseConstPolygonWithoutHolesFromSingleColumn(column_const_data, 0, out_polygon); parseConstPolygonWithoutHolesFromSingleColumn(column_const_data, 0, out_polygon);
} }
}
void parseConstPolygon(Block & block, const ColumnNumbers & arguments, Polygon & out_polygon) const void parseConstPolygon(Block & block, const ColumnNumbers & arguments, Polygon & out_polygon) const
{ {

View File

@ -0,0 +1,2 @@
1
a

View File

@ -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;