pub fn make_sha2_udf() -> ScalarUDFExpand description
sha2(expr, bit_length) — Databricks/Spark-compatible SHA-2 returning a
lowercase HEX STRING (Utf8), NOT raw bytes.
DataFusion’s built-in sha256() returns [DataType::Binary], so wrapping it
in a string function (UPPER, CONCAT, …) fails at plan time. Databricks
sha2(col, 256) instead yields a hex string, so the surrounding string ops
are valid there. This UDF restores that contract: the digest bytes are
identical to sha256(), rendered as the same lowercase-hex text Databricks
produces, so surrogate keys stay byte-identical across engines.
bit_length selects the variant (224/256/384/512); 0 and any unsupported
value map to 256. The second argument is accepted as Int64 so a bare SQL
integer literal resolves without a cast; arg0 is accepted as Utf8.