From 2475143ed35d6806cd75b33dcf6b3edce4279fd8 Mon Sep 17 00:00:00 2001 From: Nikita Mikhailov Date: Tue, 19 Jan 2021 20:16:10 +0300 Subject: [PATCH] fix style --- src/DataTypes/DataTypeCustomGeo.h | 2 + src/Functions/PolygonsUnion.cpp | 8 ---- src/Functions/geometryConverters.cpp | 11 ++++- src/Functions/geometryConverters.h | 35 ++++++++-------- src/Functions/polygonArea.cpp | 9 ---- src/Functions/polygonConvexHull.cpp | 8 ---- src/Functions/polygonPerimeter.cpp | 8 ---- src/Functions/polygonsDistance.cpp | 8 ---- src/Functions/polygonsEquals.cpp | 42 ++++++------------- src/Functions/polygonsIntersection.cpp | 10 ----- src/Functions/polygonsSymDifference.cpp | 10 ----- src/Functions/polygonsWithin.cpp | 42 ++++++------------- src/Functions/readWkt.cpp | 3 +- src/Functions/svg.cpp | 13 +++--- src/Functions/wkt.cpp | 3 +- .../0_stateless/01301_polygons_within.sql | 4 +- .../0_stateless/01303_polygons_equals.sql | 4 +- 17 files changed, 69 insertions(+), 151 deletions(-) diff --git a/src/DataTypes/DataTypeCustomGeo.h b/src/DataTypes/DataTypeCustomGeo.h index 00ca898f53b..8f549812b8b 100644 --- a/src/DataTypes/DataTypeCustomGeo.h +++ b/src/DataTypes/DataTypeCustomGeo.h @@ -1,3 +1,5 @@ +#pragma once + #include #include #include diff --git a/src/Functions/PolygonsUnion.cpp b/src/Functions/PolygonsUnion.cpp index 2d26e09c3de..9d45269d0cb 100644 --- a/src/Functions/PolygonsUnion.cpp +++ b/src/Functions/PolygonsUnion.cpp @@ -20,14 +20,6 @@ namespace DB { -namespace ErrorCodes -{ - extern const int TOO_FEW_ARGUMENTS_FOR_FUNCTION; - extern const int BAD_ARGUMENTS; - extern const int ILLEGAL_TYPE_OF_ARGUMENT; - extern const int ILLEGAL_COLUMN; -} - class FunctionPolygonsUnion : public IFunction { public: diff --git a/src/Functions/geometryConverters.cpp b/src/Functions/geometryConverters.cpp index 4fdc1ea5931..b8a15ff98d5 100644 --- a/src/Functions/geometryConverters.cpp +++ b/src/Functions/geometryConverters.cpp @@ -3,9 +3,16 @@ #include -namespace DB { +namespace DB +{ -namespace { +namespace ErrorCodes +{ + extern const int ILLEGAL_COLUMN; +} + +namespace +{ size_t getArrayDepth(DataTypePtr data_type, size_t max_depth) { diff --git a/src/Functions/geometryConverters.h b/src/Functions/geometryConverters.h index 134209c3b40..2dd0ce117b1 100644 --- a/src/Functions/geometryConverters.h +++ b/src/Functions/geometryConverters.h @@ -18,11 +18,11 @@ #include -namespace DB { +namespace DB +{ namespace ErrorCodes { - extern const int ILLEGAL_COLUMN; extern const int BAD_ARGUMENTS; } @@ -54,8 +54,8 @@ using GeographicMultiPolygon = MultiPolygon; using GeographicGeometry = Geometry; /** - * Class which takes some boost type and returns a pair of numbers. - * They are (x,y) in case of cartesian coordinated and (lon,lat) in case of geographic. + * Class which takes some boost type and returns a pair of numbers. + * They are (x,y) in case of cartesian coordinated and (lon,lat) in case of geographic. */ template class PointFromColumnParser @@ -154,9 +154,8 @@ public: container.reserve(r - l + 1); container.resize(r - l); - for (size_t j = l; j < r; j++) { + for (size_t j = l; j < r; j++) point_parser.get(container[j - l], j); - } // make ring closed if (!boost::geometry::equals(container[0], container.back())) @@ -289,25 +288,25 @@ public: void operator()(const Ring & ring) { - if (ring.size() != 1) { + if (ring.size() != 1) throw Exception("Unable to write ring of size " + toString(ring.size()) + " != 1 to point column", ErrorCodes::BAD_ARGUMENTS); - } + (*this)(ring[0]); } void operator()(const Polygon & polygon) { - if (polygon.inners().size() != 0) { + if (polygon.inners().size() != 0) throw Exception("Unable to write polygon with holes to point column", ErrorCodes::BAD_ARGUMENTS); - } + (*this)(polygon.outer()); } void operator()(const MultiPolygon & multi_polygon) { - if (multi_polygon.size() != 1) { + if (multi_polygon.size() != 1) throw Exception("Unable to write multi-polygon of size " + toString(multi_polygon.size()) + " != 1 to point column", ErrorCodes::BAD_ARGUMENTS); - } + (*this)(multi_polygon[0]); } @@ -357,17 +356,17 @@ public: void operator()(const Polygon & polygon) { - if (polygon.inners().size() != 0) { + if (polygon.inners().size() != 0) throw Exception("Unable to write polygon with holes to ring column", ErrorCodes::BAD_ARGUMENTS); - } + (*this)(polygon.outer()); } void operator()(const MultiPolygon & multi_polygon) { - if (multi_polygon.size() != 1) { + if (multi_polygon.size() != 1) throw Exception("Unable to write multi-polygon of size " + toString(multi_polygon.size()) + " != 1 to ring column", ErrorCodes::BAD_ARGUMENTS); - } + (*this)(multi_polygon[0]); } @@ -421,9 +420,9 @@ public: void operator()(const MultiPolygon & multi_polygon) { - if (multi_polygon.size() != 1) { + if (multi_polygon.size() != 1) throw Exception("Unable to write multi-polygon of size " + toString(multi_polygon.size()) + " != 1 to polygon column", ErrorCodes::BAD_ARGUMENTS); - } + (*this)(multi_polygon[0]); } diff --git a/src/Functions/polygonArea.cpp b/src/Functions/polygonArea.cpp index 79d95723f0e..aac9a182ea9 100644 --- a/src/Functions/polygonArea.cpp +++ b/src/Functions/polygonArea.cpp @@ -19,15 +19,6 @@ namespace DB { - -namespace ErrorCodes -{ - extern const int TOO_FEW_ARGUMENTS_FOR_FUNCTION; - extern const int BAD_ARGUMENTS; - extern const int ILLEGAL_TYPE_OF_ARGUMENT; - extern const int ILLEGAL_COLUMN; -} - template class FunctionPolygonArea : public IFunction { diff --git a/src/Functions/polygonConvexHull.cpp b/src/Functions/polygonConvexHull.cpp index 5150e344582..1cb46b81c32 100644 --- a/src/Functions/polygonConvexHull.cpp +++ b/src/Functions/polygonConvexHull.cpp @@ -20,14 +20,6 @@ namespace DB { -namespace ErrorCodes -{ - extern const int TOO_FEW_ARGUMENTS_FOR_FUNCTION; - extern const int BAD_ARGUMENTS; - extern const int ILLEGAL_TYPE_OF_ARGUMENT; - extern const int ILLEGAL_COLUMN; -} - template class FunctionPolygonConvexHull : public IFunction { diff --git a/src/Functions/polygonPerimeter.cpp b/src/Functions/polygonPerimeter.cpp index 186fef3d532..aafc07aa3b2 100644 --- a/src/Functions/polygonPerimeter.cpp +++ b/src/Functions/polygonPerimeter.cpp @@ -20,14 +20,6 @@ namespace DB { -namespace ErrorCodes -{ - extern const int TOO_FEW_ARGUMENTS_FOR_FUNCTION; - extern const int BAD_ARGUMENTS; - extern const int ILLEGAL_TYPE_OF_ARGUMENT; - extern const int ILLEGAL_COLUMN; -} - template class FunctionPolygonPerimeter : public IFunction { diff --git a/src/Functions/polygonsDistance.cpp b/src/Functions/polygonsDistance.cpp index 7a2988e8ada..67f6482ec22 100644 --- a/src/Functions/polygonsDistance.cpp +++ b/src/Functions/polygonsDistance.cpp @@ -22,14 +22,6 @@ namespace DB { -namespace ErrorCodes -{ - extern const int TOO_FEW_ARGUMENTS_FOR_FUNCTION; - extern const int BAD_ARGUMENTS; - extern const int ILLEGAL_TYPE_OF_ARGUMENT; - extern const int ILLEGAL_COLUMN; -} - template class FunctionPolygonsDistance : public IFunction { diff --git a/src/Functions/polygonsEquals.cpp b/src/Functions/polygonsEquals.cpp index d30e5b24d2a..118c5885cdd 100644 --- a/src/Functions/polygonsEquals.cpp +++ b/src/Functions/polygonsEquals.cpp @@ -22,18 +22,11 @@ namespace DB { -namespace ErrorCodes -{ - extern const int TOO_FEW_ARGUMENTS_FOR_FUNCTION; - extern const int BAD_ARGUMENTS; - extern const int ILLEGAL_TYPE_OF_ARGUMENT; - extern const int ILLEGAL_COLUMN; -} - +template class FunctionPolygonsEquals : public IFunction { public: - static inline const char * name = "polygonsEquals"; + static const char * name; explicit FunctionPolygonsEquals() = default; @@ -64,35 +57,22 @@ public: ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & /*result_type*/, size_t input_rows_count) const override { - auto get_parser = [&arguments] (size_t i) { - const auto * const_col = - checkAndGetColumn(arguments[i].column.get()); - - bool is_const = static_cast(const_col); - - return std::pair>{is_const, is_const ? - makeGeometryFromColumnParser(ColumnWithTypeAndName(const_col->getDataColumnPtr(), arguments[i].type, arguments[i].name)) : - makeGeometryFromColumnParser(arguments[i])}; - }; - - auto [is_first_polygon_const, first_parser] = get_parser(0); + auto first_parser = makeGeometryFromColumnParser(arguments[0]); auto first_container = createContainer(first_parser); - auto [is_second_polygon_const, second_parser] = get_parser(1); + auto second_parser = makeGeometryFromColumnParser(arguments[1]); auto second_container = createContainer(second_parser); auto res_column = ColumnUInt8::create(); for (size_t i = 0; i < input_rows_count; i++) { - if (!is_first_polygon_const || i == 0) - get(first_parser, first_container, i); - if (!is_second_polygon_const || i == 0) - get(second_parser, second_container, i); + get(first_parser, first_container, i); + get(second_parser, second_container, i); bool equals = boost::geometry::equals( - boost::get(first_container), - boost::get(second_container)); + boost::get>(first_container), + boost::get>(second_container)); res_column->insertValue(equals); } @@ -107,9 +87,13 @@ public: }; +template <> +const char * FunctionPolygonsEquals::name = "polygonsEqualsCartesian"; + + void registerFunctionPolygonsEquals(FunctionFactory & factory) { - factory.registerFunction(); + factory.registerFunction>(); } } diff --git a/src/Functions/polygonsIntersection.cpp b/src/Functions/polygonsIntersection.cpp index 90d129112b7..335b40322f7 100644 --- a/src/Functions/polygonsIntersection.cpp +++ b/src/Functions/polygonsIntersection.cpp @@ -19,16 +19,6 @@ namespace DB { - -namespace ErrorCodes -{ - extern const int TOO_FEW_ARGUMENTS_FOR_FUNCTION; - extern const int BAD_ARGUMENTS; - extern const int ILLEGAL_TYPE_OF_ARGUMENT; - extern const int ILLEGAL_COLUMN; -} - - class FunctionPolygonsIntersection : public IFunction { public: diff --git a/src/Functions/polygonsSymDifference.cpp b/src/Functions/polygonsSymDifference.cpp index 50558c69662..6d42e001dc8 100644 --- a/src/Functions/polygonsSymDifference.cpp +++ b/src/Functions/polygonsSymDifference.cpp @@ -20,14 +20,6 @@ namespace DB { -namespace ErrorCodes -{ - extern const int TOO_FEW_ARGUMENTS_FOR_FUNCTION; - extern const int BAD_ARGUMENTS; - extern const int ILLEGAL_TYPE_OF_ARGUMENT; - extern const int ILLEGAL_COLUMN; -} - template class FunctionPolygonsSymDifference : public IFunction { @@ -109,6 +101,4 @@ void registerFunctionPolygonsSymDifference(FunctionFactory & factory) factory.registerFunction>(); } - - } diff --git a/src/Functions/polygonsWithin.cpp b/src/Functions/polygonsWithin.cpp index 7f01330ea33..3a2c5704083 100644 --- a/src/Functions/polygonsWithin.cpp +++ b/src/Functions/polygonsWithin.cpp @@ -22,18 +22,11 @@ namespace DB { -namespace ErrorCodes -{ - extern const int TOO_FEW_ARGUMENTS_FOR_FUNCTION; - extern const int BAD_ARGUMENTS; - extern const int ILLEGAL_TYPE_OF_ARGUMENT; - extern const int ILLEGAL_COLUMN; -} - +template class FunctionPolygonsWithin : public IFunction { public: - static inline const char * name = "polygonsWithin"; + static inline const char * name; explicit FunctionPolygonsWithin() = default; @@ -64,35 +57,22 @@ public: ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & /*result_type*/, size_t input_rows_count) const override { - auto get_parser = [&arguments] (size_t i) { - const auto * const_col = - checkAndGetColumn(arguments[i].column.get()); - - bool is_const = static_cast(const_col); - - return std::pair>{is_const, is_const ? - makeGeometryFromColumnParser(ColumnWithTypeAndName(const_col->getDataColumnPtr(), arguments[i].type, arguments[i].name)) : - makeGeometryFromColumnParser(arguments[i])}; - }; - - auto [is_first_polygon_const, first_parser] = get_parser(0); + auto first_parser = makeGeometryFromColumnParser(arguments[0]); auto first_container = createContainer(first_parser); - auto [is_second_polygon_const, second_parser] = get_parser(1); + auto second_parser = makeGeometryFromColumnParser(arguments[1]); auto second_container = createContainer(second_parser); auto res_column = ColumnUInt8::create(); for (size_t i = 0; i < input_rows_count; i++) { - if (!is_first_polygon_const || i == 0) - get(first_parser, first_container, i); - if (!is_second_polygon_const || i == 0) - get(second_parser, second_container, i); + get(first_parser, first_container, i); + get(second_parser, second_container, i); bool within = boost::geometry::within( - boost::get(first_container), - boost::get(second_container)); + boost::get>(first_container), + boost::get>(second_container)); res_column->insertValue(within); } @@ -107,9 +87,13 @@ public: }; +template <> +const char * FunctionPolygonsWithin::name = "polygonsWithinCartesian"; + + void registerFunctionPolygonsWithin(FunctionFactory & factory) { - factory.registerFunction(); + factory.registerFunction>(); } } diff --git a/src/Functions/readWkt.cpp b/src/Functions/readWkt.cpp index 5e2becbe131..12007b8724b 100644 --- a/src/Functions/readWkt.cpp +++ b/src/Functions/readWkt.cpp @@ -13,8 +13,7 @@ namespace DB namespace ErrorCodes { -extern const int ILLEGAL_TYPE_OF_ARGUMENT; -extern const int BAD_ARGUMENT; + extern const int ILLEGAL_TYPE_OF_ARGUMENT; } template diff --git a/src/Functions/svg.cpp b/src/Functions/svg.cpp index 5bd84f49aa7..3d8206cc2e3 100644 --- a/src/Functions/svg.cpp +++ b/src/Functions/svg.cpp @@ -10,7 +10,9 @@ namespace DB { -namespace ErrorCodes { +namespace ErrorCodes +{ + extern const int ILLEGAL_TYPE_OF_ARGUMENT; extern const int TOO_MANY_ARGUMENTS_FOR_FUNCTION; extern const int TOO_FEW_ARGUMENTS_FOR_FUNCTION; } @@ -48,7 +50,8 @@ public: { throw Exception("Too many arguments", ErrorCodes::TOO_MANY_ARGUMENTS_FOR_FUNCTION); } - else if (arguments.empty()) { + else if (arguments.empty()) + { throw Exception("Too few arguments", ErrorCodes::TOO_FEW_ARGUMENTS_FOR_FUNCTION); } else if (arguments.size() == 2 && checkAndGetDataType(arguments[1].get()) == nullptr) @@ -75,13 +78,13 @@ public: bool has_style = arguments.size() > 1; ColumnPtr style; - if (has_style) { + if (has_style) style = arguments[1].column; - } for (size_t i = 0; i < input_rows_count; i++) { - std::stringstream str; + /// FIXME + std::stringstream str; // STYLE_CHECK_ALLOW_STD_STRING_STREAM if (!geo_column_is_const || i == 0) get(parser, container, i); diff --git a/src/Functions/wkt.cpp b/src/Functions/wkt.cpp index e184f7537aa..e56f1e2bf6a 100644 --- a/src/Functions/wkt.cpp +++ b/src/Functions/wkt.cpp @@ -45,7 +45,8 @@ public: for (size_t i = 0; i < input_rows_count; i++) { - std::stringstream str; + /// FIXME + std::stringstream str; // STYLE_CHECK_ALLOW_STD_STRING_STREAM get(parser, container, i); str << boost::geometry::wkt(container); std::string serialized = str.str(); diff --git a/tests/queries/0_stateless/01301_polygons_within.sql b/tests/queries/0_stateless/01301_polygons_within.sql index da76858c95d..11774bf6cc7 100644 --- a/tests/queries/0_stateless/01301_polygons_within.sql +++ b/tests/queries/0_stateless/01301_polygons_within.sql @@ -1,2 +1,2 @@ -select polygonsWithin([[[(0, 0),(0, 3),(1, 2.9),(2, 2.6),(2.6, 2),(2.9, 1),(3, 0),(0, 0)]]], [[[(1, 1),(1, 4),(4, 4),(4, 1),(1, 1)]]]); -select polygonsWithin([[[(2, 2), (2, 3), (3, 3), (3, 2)]]], [[[(1, 1),(1, 4),(4, 4),(4, 1),(1, 1)]]]) +select polygonsWithinCartesian([[[(0, 0),(0, 3),(1, 2.9),(2, 2.6),(2.6, 2),(2.9, 1),(3, 0),(0, 0)]]], [[[(1, 1),(1, 4),(4, 4),(4, 1),(1, 1)]]]); +select polygonsWithinCartesian([[[(2, 2), (2, 3), (3, 3), (3, 2)]]], [[[(1, 1),(1, 4),(4, 4),(4, 1),(1, 1)]]]) diff --git a/tests/queries/0_stateless/01303_polygons_equals.sql b/tests/queries/0_stateless/01303_polygons_equals.sql index fa93deaba03..b3a4d8f12b3 100644 --- a/tests/queries/0_stateless/01303_polygons_equals.sql +++ b/tests/queries/0_stateless/01303_polygons_equals.sql @@ -1,2 +1,2 @@ -select polygonsEquals([[[(0, 0),(0, 3),(1, 2.9),(2, 2.6),(2.6, 2),(2.9, 1),(3, 0),(0, 0)]]], [[[(1, 1),(1, 4),(4, 4),(4, 1),(1, 1)]]]); -select polygonsEquals([[[(1, 1),(1, 4),(4, 4),(4, 1)]]], [[[(1, 1),(1, 4),(4, 4),(4, 1),(1, 1)]]]) \ No newline at end of file +select polygonsEqualsCartesian([[[(0, 0),(0, 3),(1, 2.9),(2, 2.6),(2.6, 2),(2.9, 1),(3, 0),(0, 0)]]], [[[(1, 1),(1, 4),(4, 4),(4, 1),(1, 1)]]]); +select polygonsEqualsCartesian([[[(1, 1),(1, 4),(4, 4),(4, 1)]]], [[[(1, 1),(1, 4),(4, 4),(4, 1),(1, 1)]]]); \ No newline at end of file