datafusion_functions/crypto/
sha224.rs1use super::basic::{sha224, 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-224 hash of a binary string.",
32 syntax_example = "sha224(expression)",
33 sql_example = r#"```sql
34> select sha224('foo');
35+------------------------------------------+
36| sha224(Utf8("foo")) |
37+------------------------------------------+
38| <sha224_hash_result> |
39+------------------------------------------+
40```"#,
41 standard_argument(name = "expression", prefix = "String")
42)]
43#[derive(Debug)]
44pub struct SHA224Func {
45 signature: Signature,
46}
47
48impl Default for SHA224Func {
49 fn default() -> Self {
50 Self::new()
51 }
52}
53
54impl SHA224Func {
55 pub fn new() -> Self {
56 use DataType::*;
57 Self {
58 signature: Signature::uniform(
59 1,
60 vec![Utf8View, Utf8, LargeUtf8, Binary, LargeBinary],
61 Volatility::Immutable,
62 ),
63 }
64 }
65}
66
67impl ScalarUDFImpl for SHA224Func {
68 fn as_any(&self) -> &dyn Any {
69 self
70 }
71
72 fn name(&self) -> &str {
73 "sha224"
74 }
75
76 fn signature(&self) -> &Signature {
77 &self.signature
78 }
79
80 fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> {
81 utf8_or_binary_to_binary_type(&arg_types[0], self.name())
82 }
83
84 fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
85 sha224(&args.args)
86 }
87
88 fn documentation(&self) -> Option<&Documentation> {
89 self.doc()
90 }
91}