zclllyybb commented on code in PR #56561:
URL: https://github.com/apache/doris/pull/56561#discussion_r2385722976
##########
be/src/vec/functions/math.cpp:
##########
@@ -71,10 +71,93 @@ struct AsinhName {
};
using FunctionAsinh = FunctionMathUnary<UnaryFunctionPlain<AsinhName,
std::asinh>>;
-struct AtanName {
+class FunctionAtan : public IFunction {
+public:
static constexpr auto name = "atan";
+ static FunctionPtr create() { return std::make_shared<FunctionAtan>(); }
+
+ String get_name() const override { return name; }
+ bool is_variadic() const override { return true; }
+ size_t get_number_of_arguments() const override { return 0; }
+
+ DataTypePtr get_return_type_impl(const DataTypes& arguments) const
override {
+ return std::make_shared<DataTypeFloat64>();
+ }
+
+ Status execute_impl(FunctionContext* context, Block& block, const
ColumnNumbers& arguments,
+ uint32_t result, size_t input_rows_count) const
override {
+ if (arguments.size() == 1) {
+ return execute_unary(block, arguments, result, input_rows_count);
+ } else if (arguments.size() == 2) {
+ return execute_binary(block, arguments, result, input_rows_count);
+ } else {
+ return Status::InvalidArgument("atan function expects 1 or 2
arguments, but got {}",
+ arguments.size());
+ }
+ }
+
+private:
+ Status execute_unary(Block& block, const ColumnNumbers& arguments,
uint32_t result,
+ size_t input_rows_count) const {
+ auto res_col = ColumnFloat64::create(input_rows_count);
+ auto& res_data = res_col->get_data();
+
+ const auto& col_data =
+ assert_cast<const
ColumnFloat64*>(block.get_by_position(arguments[0]).column.get())
+ ->get_data();
+ for (size_t i = 0; i < input_rows_count; ++i) {
+ res_data[i] = std::atan(col_data[i]);
+ }
+
+ block.replace_by_position(result, std::move(res_col));
+ return Status::OK();
+ }
+
+ Status execute_binary(Block& block, const ColumnNumbers& arguments,
uint32_t result,
+ size_t input_rows_count) const {
+ auto [col_y, is_const_y] =
unpack_if_const(block.get_by_position(arguments[0]).column);
+ auto [col_x, is_const_x] =
unpack_if_const(block.get_by_position(arguments[1]).column);
+
+ auto result_column = ColumnFloat64::create(input_rows_count);
+ auto& result_data = result_column->get_data();
+
+ if (is_const_y && is_const_x) {
Review Comment:
this situation doesn't really exist
##########
regression-test/suites/function_p0/test_math_function.groovy:
##########
@@ -121,6 +121,78 @@ suite("test_math_function") {
atan2(cast('-1.0' as double), cast('inf' as double))
"""
+ qt_select_atan_with_two_args"""
Review Comment:
add some test with data in table
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]