use super::basic::{sha512, utf8_or_binary_to_binary_type};
use arrow::datatypes::DataType;
use datafusion_common::Result;
use datafusion_expr::{ColumnarValue, ScalarUDFImpl, Signature, Volatility};
use std::any::Any;
#[derive(Debug)]
pub struct SHA512Func {
signature: Signature,
}
impl Default for SHA512Func {
fn default() -> Self {
Self::new()
}
}
impl SHA512Func {
pub fn new() -> Self {
use DataType::*;
Self {
signature: Signature::uniform(
1,
vec![Utf8, LargeUtf8, Binary, LargeBinary],
Volatility::Immutable,
),
}
}
}
impl ScalarUDFImpl for SHA512Func {
fn as_any(&self) -> &dyn Any {
self
}
fn name(&self) -> &str {
"sha512"
}
fn signature(&self) -> &Signature {
&self.signature
}
fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> {
utf8_or_binary_to_binary_type(&arg_types[0], self.name())
}
fn invoke(&self, args: &[ColumnarValue]) -> Result<ColumnarValue> {
sha512(args)
}
}