alamb commented on code in PR #10083:
URL:
https://github.com/apache/arrow-datafusion/pull/10083#discussion_r1565534738
##########
datafusion/expr/src/built_in_function.rs:
##########
@@ -185,43 +167,19 @@ impl BuiltinScalarFunction {
],
self.volatility(),
),
- BuiltinScalarFunction::Factorial => {
- Signature::uniform(1, vec![Int64], self.volatility())
- }
- BuiltinScalarFunction::Ceil | BuiltinScalarFunction::Exp => {
- // math expressions expect 1 argument of type f64 or f32
- // priority is given to f64 because e.g. `sqrt(1i32)` is in IR
(real numbers) and thus we
- // return the best approximation for it (in f64).
- // We accept f32 because in this case it is clear that the
best approximation
- // will be as good as the number of digits in the number
- Signature::uniform(1, vec![Float64, Float32],
self.volatility())
- }
}
}
/// This function specifies monotonicity behaviors for built-in scalar
functions.
/// The list can be extended, only mathematical and datetime functions are
/// considered for the initial implementation of this feature.
pub fn monotonicity(&self) -> Option<FuncMonotonicity> {
- if matches!(
- &self,
- BuiltinScalarFunction::Ceil
- | BuiltinScalarFunction::Exp
- | BuiltinScalarFunction::Factorial
- ) {
- Some(vec![Some(true)])
- } else {
- None
- }
+ None
Review Comment:
wow -- `BuiltInScalarFunction` is getting pretty sparse (I think @Omega359
plans the final part)
##########
datafusion/functions/src/math/factorial.rs:
##########
@@ -0,0 +1,117 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use arrow::array::{ArrayRef, Int64Array};
+use std::any::Any;
+use std::sync::Arc;
+
+use arrow::datatypes::DataType;
+use arrow::datatypes::DataType::Int64;
+
+use crate::utils::make_scalar_function;
+use datafusion_common::{exec_err, DataFusionError, Result};
+use datafusion_expr::{ColumnarValue, ScalarUDFImpl, Signature, Volatility};
+
+#[derive(Debug)]
+pub struct FactorialFunc {
+ signature: Signature,
+}
+
+impl Default for FactorialFunc {
+ fn default() -> Self {
+ FactorialFunc::new()
+ }
+}
+
+impl FactorialFunc {
+ pub fn new() -> Self {
+ Self {
+ signature: Signature::uniform(1, vec![Int64],
Volatility::Volatile),
Review Comment:
I think factorial is immutable (not volatile)
```suggestion
signature: Signature::uniform(1, vec![Int64],
Volatility::Immutable),
```
--
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]