|
19 | 19 | use super::basic::{digest, utf8_or_binary_to_binary_type}; |
20 | 20 | use arrow::datatypes::DataType; |
21 | 21 | use datafusion_common::Result; |
22 | | -use datafusion_expr::scalar_doc_sections::DOC_SECTION_HASHING; |
23 | 22 | use datafusion_expr::{ |
24 | 23 | ColumnarValue, Documentation, ScalarUDFImpl, Signature, TypeSignature::*, Volatility, |
25 | 24 | }; |
| 25 | +use datafusion_macros::user_doc; |
26 | 26 | use std::any::Any; |
27 | | -use std::sync::OnceLock; |
28 | 27 |
|
| 28 | +#[user_doc( |
| 29 | + doc_section(label = "Hashing Functions"), |
| 30 | + description = "Computes the binary hash of an expression using the specified algorithm.", |
| 31 | + syntax_example = "digest(expression, algorithm)", |
| 32 | + sql_example = r#"```sql |
| 33 | +> select digest('foo', 'sha256'); |
| 34 | ++------------------------------------------+ |
| 35 | +| digest(Utf8("foo"), Utf8("sha256")) | |
| 36 | ++------------------------------------------+ |
| 37 | +| <binary_hash_result> | |
| 38 | ++------------------------------------------+ |
| 39 | +```"#, |
| 40 | + standard_argument(name = "expression", prefix = "String"), |
| 41 | + argument( |
| 42 | + name = "algorithm", |
| 43 | + description = "String expression specifying algorithm to use. Must be one of: |
| 44 | + - md5 |
| 45 | + - sha224 |
| 46 | + - sha256 |
| 47 | + - sha384 |
| 48 | + - sha512 |
| 49 | + - blake2s |
| 50 | + - blake2b |
| 51 | + - blake3" |
| 52 | + ) |
| 53 | +)] |
29 | 54 | #[derive(Debug)] |
30 | 55 | pub struct DigestFunc { |
31 | 56 | signature: Signature, |
@@ -78,43 +103,6 @@ impl ScalarUDFImpl for DigestFunc { |
78 | 103 | } |
79 | 104 |
|
80 | 105 | fn documentation(&self) -> Option<&Documentation> { |
81 | | - Some(get_digest_doc()) |
| 106 | + self.doc() |
82 | 107 | } |
83 | 108 | } |
84 | | - |
85 | | -static DOCUMENTATION: OnceLock<Documentation> = OnceLock::new(); |
86 | | - |
87 | | -fn get_digest_doc() -> &'static Documentation { |
88 | | - DOCUMENTATION.get_or_init(|| { |
89 | | - Documentation::builder( |
90 | | - DOC_SECTION_HASHING, |
91 | | - "Computes the binary hash of an expression using the specified algorithm.", |
92 | | - "digest(expression, algorithm)", |
93 | | - ) |
94 | | - .with_sql_example( |
95 | | - r#"```sql |
96 | | -> select digest('foo', 'sha256'); |
97 | | -+------------------------------------------+ |
98 | | -| digest(Utf8("foo"), Utf8("sha256")) | |
99 | | -+------------------------------------------+ |
100 | | -| <binary_hash_result> | |
101 | | -+------------------------------------------+ |
102 | | -```"#, |
103 | | - ) |
104 | | - .with_standard_argument("expression", Some("String")) |
105 | | - .with_argument( |
106 | | - "algorithm", |
107 | | - "String expression specifying algorithm to use. Must be one of: |
108 | | - |
109 | | -- md5 |
110 | | -- sha224 |
111 | | -- sha256 |
112 | | -- sha384 |
113 | | -- sha512 |
114 | | -- blake2s |
115 | | -- blake2b |
116 | | -- blake3", |
117 | | - ) |
118 | | - .build() |
119 | | - }) |
120 | | -} |
0 commit comments