diff --git a/src/Functions/S2CapContains.cpp b/src/Functions/S2CapContains.cpp index 06278bc925f..f93c14b41f8 100644 --- a/src/Functions/S2CapContains.cpp +++ b/src/Functions/S2CapContains.cpp @@ -48,40 +48,22 @@ public: DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override { - size_t number_of_arguments = arguments.size(); + for (size_t index = 0; index < getNumberOfArguments(); ++index) + { + const auto * arg = arguments[index].get(); - if (number_of_arguments != 3) { - throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, - "Number of arguments for function {} doesn't match: passed {}, should be 3", - getName(), - toString(number_of_arguments)); - } - - const auto * arg = arguments[0].get(); - - if (!WhichDataType(arg).isUInt64()) { - throw Exception( - ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, - "Illegal type {} of argument {} of function {}. Must be UInt64", - arg->getName(), 1, getName()); - } - - arg = arguments[1].get(); - - if (!WhichDataType(arg).isFloat64()) { - throw Exception( - ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, - "Illegal type {} of argument {} of function {}. Must be Float64", - arg->getName(), 2, getName()); - } - - arg = arguments[2].get(); - - if (!WhichDataType(arg).isUInt64()) { - throw Exception( - ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, - "Illegal type {} of argument {} of function {}. Must be UInt64", - arg->getName(), 3, getName()); + if (index == 1 && !WhichDataType(arg).isFloat64()) + throw Exception( + ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, + "Illegal type {} of argument {} of function {}. Must be Float64", + arg->getName(), 2, getName()); + else if (!WhichDataType(arg).isUInt64()) { + throw Exception( + ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, + "Illegal type {} of argument {} of function {}. Must be UInt64", + arg->getName(), index + 1, getName() + ); + } } return std::make_shared(); diff --git a/src/Functions/S2CapUnion.cpp b/src/Functions/S2CapUnion.cpp index 4f759724b49..b522bc861a0 100644 --- a/src/Functions/S2CapUnion.cpp +++ b/src/Functions/S2CapUnion.cpp @@ -50,44 +50,22 @@ public: DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override { - size_t number_of_arguments = arguments.size(); - - if (number_of_arguments != 4) { - throw Exception("Number of arguments for function " + getName() + " doesn't match: passed " - + toString(number_of_arguments) + ", should be 4", - ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH); - } - - const auto * arg = arguments[0].get(); - - if (!WhichDataType(arg).isUInt64()) { - throw Exception( - "Illegal type " + arg->getName() + " of argument " + std::to_string(1) + " of function " + getName() + ". Must be UInt64", - ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); - } - - arg = arguments[1].get(); - - if (!WhichDataType(arg).isFloat64()) { - throw Exception( - "Illegal type " + arg->getName() + " of argument " + std::to_string(2) + " of function " + getName() + ". Must be Float64", - ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); - } - - arg = arguments[2].get(); - - if (!WhichDataType(arg).isUInt64()) { - throw Exception( - "Illegal type " + arg->getName() + " of argument " + std::to_string(3) + " of function " + getName() + ". Must be UInt64", - ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); - } - - arg = arguments[3].get(); - - if (!WhichDataType(arg).isFloat64()) { - throw Exception( - "Illegal type " + arg->getName() + " of argument " + std::to_string(4) + " of function " + getName() + ". Must be Float64", - ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); + for (size_t index = 0; index < getNumberOfArguments(); ++index) + { + const auto * arg = arguments[index].get(); + if ((index == 1 || index == 3) && !WhichDataType(arg).isFloat64()) + throw Exception( + ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT + "Illegal type {} of argument {} of function {}. Must be Float64", + arg->getName(), index + 1, getName() + ); + else if (!WhichDataType(arg).isUInt64()) { + throw Exception( + ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, + "Illegal type {} of argument {} of function {}. Must be UInt64", + arg->getName(), index + 1, getName() + ); + } } DataTypePtr center = std::make_shared(); diff --git a/src/Functions/S2CellsIntersect.cpp b/src/Functions/S2CellsIntersect.cpp index b5a5bfdb59f..3066add0cbd 100644 --- a/src/Functions/S2CellsIntersect.cpp +++ b/src/Functions/S2CellsIntersect.cpp @@ -44,34 +44,22 @@ public: return name; } - size_t getNumberOfArguments() const override { return 1; } + size_t getNumberOfArguments() const override { return 2; } bool useDefaultImplementationForConstants() const override { return true; } DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override { - size_t number_of_arguments = arguments.size(); - - if (number_of_arguments != 2) { - throw Exception("Number of arguments for function " + getName() + " doesn't match: passed " - + toString(number_of_arguments) + ", should be 2", - ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH); - } - - const auto * arg = arguments[0].get(); - - if (!WhichDataType(arg).isUInt64()) { - throw Exception( - "Illegal type " + arg->getName() + " of argument " + std::to_string(1) + " of function " + getName() + ". Must be UInt64", - ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); - } - - arg = arguments[1].get(); - - if (!WhichDataType(arg).isUInt64()) { - throw Exception( - "Illegal type " + arg->getName() + " of argument " + std::to_string(2) + " of function " + getName() + ". Must be UInt64", - ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); + for (size_t i = 0; i < getNumberOfArguments(); ++i) + { + const auto * arg = arguments[i].get(); + if (!WhichDataType(arg).isUInt64()) { + throw Exception( + ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, + "Illegal type {} of argument {} of function {}. Must be UInt64", + arg->getName(), i, getName() + ); + } } return std::make_shared(); diff --git a/src/Functions/S2GetNeighbors.cpp b/src/Functions/S2GetNeighbors.cpp index f335c113890..ae77bffc812 100644 --- a/src/Functions/S2GetNeighbors.cpp +++ b/src/Functions/S2GetNeighbors.cpp @@ -48,20 +48,14 @@ public: DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override { - size_t number_of_arguments = arguments.size(); - - if (number_of_arguments != 1) { - throw Exception("Number of arguments for function " + getName() + " doesn't match: passed " - + toString(number_of_arguments) + ", should be 2", - ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH); - } - const auto * arg = arguments[0].get(); if (!WhichDataType(arg).isUInt64()) { throw Exception( - "Illegal type " + arg->getName() + " of argument " + std::to_string(1) + " of function " + getName() + ". Must be Float64", - ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); + ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, + "Illegal type {} of argument {} of function {}. Must be Float64", + arg->getName(), 1, getName() + ); } return std::make_shared(std::make_shared()); diff --git a/src/Functions/S2RectAdd.cpp b/src/Functions/S2RectAdd.cpp index abfd60de9ff..a721ddc1b17 100644 --- a/src/Functions/S2RectAdd.cpp +++ b/src/Functions/S2RectAdd.cpp @@ -50,36 +50,16 @@ public: DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override { - size_t number_of_arguments = arguments.size(); - - if (number_of_arguments != 3) { - throw Exception("Number of arguments for function " + getName() + " doesn't match: passed " - + toString(number_of_arguments) + ", should be 3", - ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH); - } - - const auto * arg = arguments[0].get(); - - if (!WhichDataType(arg).isUInt64()) { - throw Exception( - "Illegal type " + arg->getName() + " of argument " + std::to_string(1) + " of function " + getName() + ". Must be UInt64", - ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); - } - - arg = arguments[1].get(); - - if (!WhichDataType(arg).isUInt64()) { - throw Exception( - "Illegal type " + arg->getName() + " of argument " + std::to_string(2) + " of function " + getName() + ". Must be UInt64", - ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); - } - - arg = arguments[2].get(); - - if (!WhichDataType(arg).isUInt64()) { - throw Exception( - "Illegal type " + arg->getName() + " of argument " + std::to_string(3) + " of function " + getName() + ". Must be UInt64", - ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); + for (size_t index = 0; index < getNumberOfArguments(); ++index) + { + const auto * arg = arguments[index].get(); + if (!WhichDataType(arg).isUInt64()) { + throw Exception( + ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, + "Illegal type {} of argument {} of function {}. Must be UInt64", + arg->getName(), i, getName() + ); + } } DataTypePtr element = std::make_shared(); diff --git a/src/Functions/S2RectContains.cpp b/src/Functions/S2RectContains.cpp index bde1242bbe9..e242f471ddd 100644 --- a/src/Functions/S2RectContains.cpp +++ b/src/Functions/S2RectContains.cpp @@ -50,36 +50,16 @@ public: DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override { - size_t number_of_arguments = arguments.size(); - - if (number_of_arguments != 3) { - throw Exception("Number of arguments for function " + getName() + " doesn't match: passed " - + toString(number_of_arguments) + ", should be 3", - ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH); - } - - const auto * arg = arguments[0].get(); - - if (!WhichDataType(arg).isUInt64()) { - throw Exception( - "Illegal type " + arg->getName() + " of argument " + std::to_string(1) + " of function " + getName() + ". Must be UInt64", - ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); - } - - arg = arguments[1].get(); - - if (!WhichDataType(arg).isUInt64()) { - throw Exception( - "Illegal type " + arg->getName() + " of argument " + std::to_string(2) + " of function " + getName() + ". Must be UInt64", - ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); - } - - arg = arguments[2].get(); - - if (!WhichDataType(arg).isUInt64()) { - throw Exception( - "Illegal type " + arg->getName() + " of argument " + std::to_string(3) + " of function " + getName() + ". Must be UInt64", - ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); + for (size_t i = 0; i < getNumberOfArguments(); ++i) + { + const auto * arg = arguments[i].get(); + if (!WhichDataType(arg).isUInt64()) { + throw Exception( + ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, + "Illegal type {} of argument {} of function {}. Must be UInt64", + arg->getName(), i, getName() + ); + } } return std::make_shared(); diff --git a/src/Functions/S2RectIntersection.cpp b/src/Functions/S2RectIntersection.cpp index c9404a70fc6..39a0f272078 100644 --- a/src/Functions/S2RectIntersection.cpp +++ b/src/Functions/S2RectIntersection.cpp @@ -50,49 +50,16 @@ public: DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override { - size_t number_of_arguments = arguments.size(); - - if (number_of_arguments != 4) { - throw Exception( - ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, - "Number of arguments for function {} doesn't match: passed {}, should be 4", - getName(), number_of_arguments); - } - - const auto * arg = arguments[0].get(); - - if (!WhichDataType(arg).isUInt64()) { - throw Exception( - ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, - "Illegal type {} of argument {} of function {}. Must be UInt64", - arg->getName(), 1, getName()); - } - - arg = arguments[1].get(); - - if (!WhichDataType(arg).isUInt64()) { - throw Exception( - ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, - "Illegal type {} of argument {} of function {}. Must be UInt64", - arg->getName(), 2, getName()); - } - - arg = arguments[2].get(); - - if (!WhichDataType(arg).isUInt64()) { - throw Exception( - ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, - "Illegal type {} of argument {} of function {}. Must be UInt64", - arg->getName(), 3, getName()); - } - - arg = arguments[3].get(); - - if (!WhichDataType(arg).isUInt64()) { - throw Exception( - ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, - "Illegal type {} of argument {} of function {}. Must be UInt64", - arg->getName(), 4, getName()); + for (size_t i = 0; i < getNumberOfArguments(); ++i) + { + const auto * arg = arguments[i].get(); + if (!WhichDataType(arg).isUInt64()) { + throw Exception( + ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, + "Illegal type {} of argument {} of function {}. Must be UInt64", + arg->getName(), i, getName() + ); + } } DataTypePtr element = std::make_shared(); diff --git a/src/Functions/S2RectUnion.cpp b/src/Functions/S2RectUnion.cpp index 0d66d600253..fbfe4fa8182 100644 --- a/src/Functions/S2RectUnion.cpp +++ b/src/Functions/S2RectUnion.cpp @@ -50,49 +50,16 @@ public: DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override { - size_t number_of_arguments = arguments.size(); - - if (number_of_arguments != 4) { - throw Exception( - ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, - "Number of arguments for function {} doesn't match: passed {}, should be 4", - getName(), number_of_arguments); - } - - const auto * arg = arguments[0].get(); - - if (!WhichDataType(arg).isUInt64()) { - throw Exception( - ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, - "Illegal type {} of argument {} of function {}. Must be UInt64", - arg->getName(), 1, getName()); - } - - arg = arguments[1].get(); - - if (!WhichDataType(arg).isUInt64()) { - throw Exception( - ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, - "Illegal type {} of argument {} of function {}. Must be UInt64", - arg->getName(), 2, getName()); - } - - arg = arguments[2].get(); - - if (!WhichDataType(arg).isUInt64()) { - throw Exception( - ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, - "Illegal type {} of argument {} of function {}. Must be UInt64", - arg->getName(), 3, getName()); - } - - arg = arguments[3].get(); - - if (!WhichDataType(arg).isUInt64()) { - throw Exception( - ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, - "Illegal type {} of argument {} of function {}. Must be UInt64", - arg->getName(), 4, getName()); + for (size_t i = 0; i < getNumberOfArguments(); ++i) + { + const auto * arg = arguments[i].get(); + if (!WhichDataType(arg).isUInt64()) { + throw Exception( + ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, + "Illegal type {} of argument {} of function {}. Must be UInt64", + arg->getName(), i, getName() + ); + } } DataTypePtr element = std::make_shared(); diff --git a/src/Functions/degreesToS2.cpp b/src/Functions/degreesToS2.cpp index f32621ba861..685025022a2 100644 --- a/src/Functions/degreesToS2.cpp +++ b/src/Functions/degreesToS2.cpp @@ -48,27 +48,16 @@ public: DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override { - size_t number_of_arguments = arguments.size(); - - if (number_of_arguments != 2) { - throw Exception("Number of arguments for function " + getName() + " doesn't match: passed " - + toString(number_of_arguments) + ", should be 2", - ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH); - } - - const auto * arg = arguments[0].get(); - - if (!WhichDataType(arg).isFloat64()) { - throw Exception( - "Illegal type " + arg->getName() + " of argument " + std::to_string(1) + " of function " + getName() + ". Must be Float64", - ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); - } - - arg = arguments[1].get(); - if (!WhichDataType(arg).isFloat64()) { - throw Exception( - "Illegal type " + arg->getName() + " of argument " + std::to_string(2) + " of function " + getName() + ". Must be Float64", - ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); + for (size_t i = 0; i < getNumberOfArguments(); ++i) + { + const auto * arg = arguments[i].get(); + if (!WhichDataType(arg).isFloat64()) { + throw Exception( + ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, + "Illegal type {} of argument {} of function {}. Must be Float64", + arg->getName(), i, getName() + ); + } } return std::make_shared(); diff --git a/src/Functions/radiansToS2.cpp b/src/Functions/radiansToS2.cpp index a1ea2fb152f..fbfe4cbad2f 100644 --- a/src/Functions/radiansToS2.cpp +++ b/src/Functions/radiansToS2.cpp @@ -48,30 +48,16 @@ public: DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override { - size_t number_of_arguments = arguments.size(); - - if (number_of_arguments != 2) { - throw Exception( - ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, - "Number of arguments for function {} doesn't match: passed {}, should be 2", - getName(), number_of_arguments); - } - - const auto * arg = arguments[0].get(); - - if (!WhichDataType(arg).isFloat64()) { - throw Exception( - ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, - "Illegal type {} of argument {} of function {}. Must be Float64", - arg->getName(), 1, getName()); - } - - arg = arguments[1].get(); - if (!WhichDataType(arg).isFloat64()) { - throw Exception( - ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, - "Illegal type {} of argument {} of function {}. Must be Float64", - arg->getName(), 2, getName()); + for (size_t i = 0; i < getNumberOfArguments(); ++i) + { + const auto * arg = arguments[i].get(); + if (!WhichDataType(arg).isFloat64()) { + throw Exception( + ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, + "Illegal type {} of argument {} of function {}. Must be Float64", + arg->getName(), i, getName() + ); + } } return std::make_shared(); diff --git a/tests/queries/0_stateless/01849_degrees_to_s2.sql b/tests/queries/0_stateless/01849_degrees_to_s2.sql index 14e1bc74ebb..21855121551 100644 --- a/tests/queries/0_stateless/01849_degrees_to_s2.sql +++ b/tests/queries/0_stateless/01849_degrees_to_s2.sql @@ -1,4 +1,4 @@ select degreesToS2(55.77922738, 37.63098076); select degreesToS2(55.76324100, 37.66018300); -select degreesToS2(90, 45); -select degreesToS2(-12, 34); +select degreesToS2(90.0, 45.0); +select degreesToS2(-12.0, 34.0); diff --git a/tests/queries/0_stateless/01850_radians_to_s2.sql b/tests/queries/0_stateless/01850_radians_to_s2.sql index 651d1f69f8a..fe48b2d0d8a 100644 --- a/tests/queries/0_stateless/01850_radians_to_s2.sql +++ b/tests/queries/0_stateless/01850_radians_to_s2.sql @@ -1,4 +1,4 @@ -select radiansToS2(0.97353117, 0.65678451) -select radiansToS2(0.97325215, 0.65729419) -select radiansToS2(1.57079632, 0.78539816) -select radiansToS2(-0.20943951, 0.59341194) +select radiansToS2(0.97353117, 0.65678451); +select radiansToS2(0.97325215, 0.65729419); +select radiansToS2(1.57079632, 0.78539816); +select radiansToS2(-0.20943951, 0.59341194); diff --git a/tests/queries/0_stateless/01851_s2_to_geo.sql b/tests/queries/0_stateless/01851_s2_to_geo.sql index 474d8e6a691..4a6a4cdddab 100644 --- a/tests/queries/0_stateless/01851_s2_to_geo.sql +++ b/tests/queries/0_stateless/01851_s2_to_geo.sql @@ -1,2 +1,2 @@ -select S2ToGeo(4573520603753570041) -select S2ToGeo(4573517609713934091) +select S2ToGeo(4573520603753570041); +select S2ToGeo(4573517609713934091); diff --git a/tests/queries/0_stateless/01852_s2_get_neighbours.reference b/tests/queries/0_stateless/01852_s2_get_neighbours.reference new file mode 100644 index 00000000000..3182a1c5e00 --- /dev/null +++ b/tests/queries/0_stateless/01852_s2_get_neighbours.reference @@ -0,0 +1 @@ +[5074766987100422144,5074766712222515200,5074767536856236032,5074767261978329088] diff --git a/tests/queries/0_stateless/01852_s2_get_neighbours.sql b/tests/queries/0_stateless/01852_s2_get_neighbours.sql index bb41f4affa7..73be4393b2c 100644 --- a/tests/queries/0_stateless/01852_s2_get_neighbours.sql +++ b/tests/queries/0_stateless/01852_s2_get_neighbours.sql @@ -1 +1 @@ -select S2GetNeigbors(5074766849661468672) +select S2GetNeighbors(5074766849661468672); diff --git a/tests/queries/0_stateless/01853_s2_cells_intersect.sql b/tests/queries/0_stateless/01853_s2_cells_intersect.sql index f34418c0ee3..a92f5150f09 100644 --- a/tests/queries/0_stateless/01853_s2_cells_intersect.sql +++ b/tests/queries/0_stateless/01853_s2_cells_intersect.sql @@ -1,2 +1,2 @@ -select S2CellsIntersect(9926595209846587392, 9926594385212866560) -select S2CellsIntersect(9926595209846587392, 9937259648002293760) +select S2CellsIntersect(9926595209846587392, 9926594385212866560); +select S2CellsIntersect(9926595209846587392, 9937259648002293760); diff --git a/tests/queries/0_stateless/01854_s2_cap_contains.sql b/tests/queries/0_stateless/01854_s2_cap_contains.sql index a6266d912d9..9022842e5ce 100644 --- a/tests/queries/0_stateless/01854_s2_cap_contains.sql +++ b/tests/queries/0_stateless/01854_s2_cap_contains.sql @@ -1,2 +1,2 @@ -select S2CapContains(1157339245694594829, 1.0, 1157347770437378819) -select S2CapContains(1157339245694594829, 1.0, 1152921504606846977) +select S2CapContains(1157339245694594829, 1.0, 1157347770437378819); +select S2CapContains(1157339245694594829, 1.0, 1152921504606846977);