use std::any::Any;
use arrow::datatypes::DataType;
use datafusion_common::Result;
use datafusion_expr::ColumnarValue;
use datafusion_expr::{ScalarUDFImpl, Signature, Volatility};
use crate::string::common::handle;
use crate::utils::utf8_to_str_type;
#[derive(Debug)]
pub(super) struct LowerFunc {
signature: Signature,
}
impl LowerFunc {
pub fn new() -> Self {
use DataType::*;
Self {
signature: Signature::uniform(
1,
vec![Utf8, LargeUtf8],
Volatility::Immutable,
),
}
}
}
impl ScalarUDFImpl for LowerFunc {
fn as_any(&self) -> &dyn Any {
self
}
fn name(&self) -> &str {
"lower"
}
fn signature(&self) -> &Signature {
&self.signature
}
fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> {
utf8_to_str_type(&arg_types[0], "lower")
}
fn invoke(&self, args: &[ColumnarValue]) -> Result<ColumnarValue> {
handle(args, |string| string.to_lowercase(), "lower")
}
}