zclllyybb commented on code in PR #57144:
URL: https://github.com/apache/doris/pull/57144#discussion_r2444957719


##########
be/src/vec/functions/math.cpp:
##########
@@ -388,6 +388,70 @@ double csc(double x) {
 }
 using FunctionCosec = FunctionMathUnary<UnaryFunctionPlain<CscName, csc>>;
 
+static const Int64 FACT_TABLE[] = {
+    1LL, 1LL, 2LL, 6LL, 24LL, 120LL, 720LL, 5040LL, 40320LL, 362880LL, 
3628800LL,
+    39916800LL, 479001600LL, 6227020800LL, 87178291200LL, 1307674368000LL,
+    20922789888000LL, 355687428096000LL, 6402373705728000LL,
+    121645100408832000LL, 2432902008176640000LL
+};
+
+class FunctionFactorial : public IFunction {
+public:
+    static constexpr auto name = "factorial";
+    static FunctionPtr create() { return 
std::make_shared<FunctionFactorial>(); }
+
+private:
+    String get_name() const override { return name; }
+    size_t get_number_of_arguments() const override { return 1; }
+
+    DataTypePtr get_return_type_impl(const DataTypes& arguments) const 
override {
+        return make_nullable(std::make_shared<DataTypeInt64>());
+    }
+
+    Status execute_impl(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
+                        uint32_t result, size_t input_rows_count) const 
override {
+        ColumnPtr int_col = 
block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();

Review Comment:
   no need to do this, we have framework to do for const



##########
be/src/vec/functions/math.cpp:
##########
@@ -388,6 +388,70 @@ double csc(double x) {
 }
 using FunctionCosec = FunctionMathUnary<UnaryFunctionPlain<CscName, csc>>;
 
+static const Int64 FACT_TABLE[] = {
+    1LL, 1LL, 2LL, 6LL, 24LL, 120LL, 720LL, 5040LL, 40320LL, 362880LL, 
3628800LL,
+    39916800LL, 479001600LL, 6227020800LL, 87178291200LL, 1307674368000LL,
+    20922789888000LL, 355687428096000LL, 6402373705728000LL,
+    121645100408832000LL, 2432902008176640000LL
+};
+
+class FunctionFactorial : public IFunction {
+public:
+    static constexpr auto name = "factorial";
+    static FunctionPtr create() { return 
std::make_shared<FunctionFactorial>(); }
+
+private:
+    String get_name() const override { return name; }
+    size_t get_number_of_arguments() const override { return 1; }
+
+    DataTypePtr get_return_type_impl(const DataTypes& arguments) const 
override {
+        return make_nullable(std::make_shared<DataTypeInt64>());
+    }
+
+    Status execute_impl(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
+                        uint32_t result, size_t input_rows_count) const 
override {
+        ColumnPtr int_col = 
block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
+        
+        const ColumnUInt8* input_null_map = nullptr;
+        if (int_col->is_nullable()) {

Review Comment:
   ditto. we have framework for nullable input



##########
be/src/vec/functions/math.cpp:
##########
@@ -388,6 +388,70 @@ double csc(double x) {
 }
 using FunctionCosec = FunctionMathUnary<UnaryFunctionPlain<CscName, csc>>;
 
+static const Int64 FACT_TABLE[] = {
+    1LL, 1LL, 2LL, 6LL, 24LL, 120LL, 720LL, 5040LL, 40320LL, 362880LL, 
3628800LL,
+    39916800LL, 479001600LL, 6227020800LL, 87178291200LL, 1307674368000LL,
+    20922789888000LL, 355687428096000LL, 6402373705728000LL,
+    121645100408832000LL, 2432902008176640000LL
+};
+
+class FunctionFactorial : public IFunction {
+public:
+    static constexpr auto name = "factorial";
+    static FunctionPtr create() { return 
std::make_shared<FunctionFactorial>(); }
+
+private:
+    String get_name() const override { return name; }
+    size_t get_number_of_arguments() const override { return 1; }
+
+    DataTypePtr get_return_type_impl(const DataTypes& arguments) const 
override {
+        return make_nullable(std::make_shared<DataTypeInt64>());
+    }
+
+    Status execute_impl(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
+                        uint32_t result, size_t input_rows_count) const 
override {
+        ColumnPtr int_col = 
block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
+        
+        const ColumnUInt8* input_null_map = nullptr;
+        if (int_col->is_nullable()) {
+            const auto& nullable_col = static_cast<const 
ColumnNullable&>(*int_col);
+            int_col = nullable_col.get_nested_column_ptr();
+            input_null_map = static_cast<const 
ColumnUInt8*>(nullable_col.get_null_map_column_ptr().get());
+        }
+
+        const auto* data_col = 
check_and_get_column<ColumnInt64>(int_col.get());
+
+        if (!data_col) {
+            return Status::InvalidArgument("Illegal column {} of argument of 
function {}",

Review Comment:
   should be InternalError for wrong type.



-- 
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]

Reply via email to