datafusion_functions/crypto/
sha384.rs1use super::basic::{sha384, utf8_or_binary_to_binary_type};
20use arrow::datatypes::DataType;
21use datafusion_common::Result;
22use datafusion_expr::{
23 ColumnarValue, Documentation, ScalarFunctionArgs, ScalarUDFImpl, Signature,
24 Volatility,
25};
26use datafusion_macros::user_doc;
27use std::any::Any;
28
29#[user_doc(
30 doc_section(label = "Hashing Functions"),
31 description = "Computes the SHA-384 hash of a binary string.",
32 syntax_example = "sha384(expression)",
33 sql_example = r#"```sql
34> select sha384('foo');
35+-----------------------------------------+
36| sha384(Utf8("foo")) |
37+-----------------------------------------+
38| <sha384_hash_result> |
39+-----------------------------------------+
40```"#,
41 standard_argument(name = "expression", prefix = "String")
42)]
43#[derive(Debug)]
44pub struct SHA384Func {
45 signature: Signature,
46}
47impl Default for SHA384Func {
48 fn default() -> Self {
49 Self::new()
50 }
51}
52
53impl SHA384Func {
54 pub fn new() -> Self {
55 use DataType::*;
56 Self {
57 signature: Signature::uniform(
58 1,
59 vec![Utf8View, Utf8, LargeUtf8, Binary, LargeBinary],
60 Volatility::Immutable,
61 ),
62 }
63 }
64}
65impl ScalarUDFImpl for SHA384Func {
66 fn as_any(&self) -> &dyn Any {
67 self
68 }
69
70 fn name(&self) -> &str {
71 "sha384"
72 }
73
74 fn signature(&self) -> &Signature {
75 &self.signature
76 }
77
78 fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> {
79 utf8_or_binary_to_binary_type(&arg_types[0], self.name())
80 }
81
82 fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
83 sha384(&args.args)
84 }
85
86 fn documentation(&self) -> Option<&Documentation> {
87 self.doc()
88 }
89}