MCPcopy Create free account
hub / github.com/apache/datafusion / invoke_with_args

Method invoke_with_args

datafusion/spark/src/function/hash/sha2.rs:83–172  ·  view source on GitHub ↗
(&self, args: ScalarFunctionArgs)

Source from the content-addressed store, hash-verified

81 }
82
83 fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
84 let [values, bit_lengths] = take_function_args(self.name(), args.args.iter())?;
85
86 match (values, bit_lengths) {
87 (
88 ColumnarValue::Scalar(value_scalar),
89 ColumnarValue::Scalar(ScalarValue::Int32(Some(bit_length))),
90 ) => {
91 if value_scalar.is_null() {
92 return Ok(ColumnarValue::Scalar(ScalarValue::Utf8(None)));
93 }
94
95 // Accept both Binary and Utf8 scalars (depending on coercion)
96 let bytes = match value_scalar {
97 ScalarValue::Binary(Some(b)) => b.as_slice(),
98 ScalarValue::LargeBinary(Some(b)) => b.as_slice(),
99 ScalarValue::BinaryView(Some(b)) => b.as_slice(),
100 ScalarValue::Utf8(Some(s))
101 | ScalarValue::LargeUtf8(Some(s))
102 | ScalarValue::Utf8View(Some(s)) => s.as_bytes(),
103 other => {
104 return internal_err!(
105 "Unsupported scalar datatype for sha2: {}",
106 other.data_type()
107 );
108 }
109 };
110
111 let out = match bit_length {
112 224 => {
113 let mut digest = sha2::Sha224::default();
114 digest.update(bytes);
115 Some(hex_encode(digest.finalize()))
116 }
117 0 | 256 => {
118 let mut digest = sha2::Sha256::default();
119 digest.update(bytes);
120 Some(hex_encode(digest.finalize()))
121 }
122 384 => {
123 let mut digest = sha2::Sha384::default();
124 digest.update(bytes);
125 Some(hex_encode(digest.finalize()))
126 }
127 512 => {
128 let mut digest = sha2::Sha512::default();
129 digest.update(bytes);
130 Some(hex_encode(digest.finalize()))
131 }
132 _ => None,
133 };
134
135 Ok(ColumnarValue::Scalar(ScalarValue::Utf8(out)))
136 }
137 // Array values + scalar bit length (common case: sha2(col, 256))
138 (
139 ColumnarValue::Array(values_array),
140 ColumnarValue::Scalar(ScalarValue::Int32(Some(bit_length))),

Callers

nothing calls this directly

Calls 10

take_function_argsFunction · 0.85
finalizeMethod · 0.80
hex_encodeFunction · 0.70
make_scalar_functionFunction · 0.50
nameMethod · 0.45
iterMethod · 0.45
is_nullMethod · 0.45
updateMethod · 0.45
data_typeMethod · 0.45

Tested by

no test coverage detected