alamb commented on code in PR #16125: URL: https://github.com/apache/datafusion/pull/16125#discussion_r2160337528
########## datafusion/spark/src/function/math/factorial.rs: ########## @@ -0,0 +1,195 @@ +// 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 std::any::Any; +use std::sync::Arc; + +use arrow::array::{Array, Int64Array}; +use arrow::datatypes::DataType; +use arrow::datatypes::DataType::Int64; +use datafusion_common::{ + cast::as_int64_array, exec_err, DataFusionError, Result, ScalarValue, +}; +use datafusion_expr::Signature; +use datafusion_expr::{ColumnarValue, ScalarFunctionArgs, ScalarUDFImpl, Volatility}; + +/// <https://spark.apache.org/docs/latest/api/sql/index.html#factorial> +#[derive(Debug)] +pub struct SparkFactorial { + signature: Signature, + aliases: Vec<String>, +} + +impl Default for SparkFactorial { + fn default() -> Self { + Self::new() + } +} + +impl SparkFactorial { + pub fn new() -> Self { + Self { + signature: Signature::uniform(1, vec![Int64], Volatility::Immutable), Review Comment: > I'm not exactly sure how the .slt tests passed, since the input is specifically Int32 in those tests. There may be some coercion behind the scenes perhaps. Yes I think the DataFusion coercion rules come into effect. DataFusion will attempt to automatically coerce arguments I would personally suggest avoiding adding additional error checking as that will result in potentially confusing error messages. Maybe we can use https://docs.rs/datafusion/latest/datafusion/logical_expr/enum.TypeSignature.html#variant.Exact to specify the types. I don't have any great ideas of how we could have automatically figured out this type discrepancy with tests however 🤔 -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org