Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions datafusion/spark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ name = "datafusion_spark"

[dependencies]
arrow = { workspace = true }
base64 = "0.23"
bigdecimal = { workspace = true }
chrono = { workspace = true }
crc32fast = "1.4"
Expand Down
2 changes: 1 addition & 1 deletion datafusion/spark/src/function/math/unhex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ where
}

/// Convert a single hex string to binary
fn unhex_scalar(s: &str) -> Option<Vec<u8>> {
pub(crate) fn unhex_scalar(s: &str) -> Option<Vec<u8>> {
let mut buffer = Vec::with_capacity(s.len().div_ceil(2));
if unhex_common(s.as_bytes(), &mut buffer) {
Some(buffer)
Expand Down
15 changes: 15 additions & 0 deletions datafusion/spark/src/function/string/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub mod quote;
pub mod soundex;
pub mod space;
pub mod substring;
pub mod to_binary;

use datafusion_expr::ScalarUDF;
use datafusion_functions::make_udf_function;
Expand All @@ -55,6 +56,8 @@ make_udf_function!(soundex::SparkSoundex, soundex);
make_udf_function!(make_valid_utf8::SparkMakeValidUtf8, make_valid_utf8);
make_udf_function!(is_valid_utf8::SparkIsValidUtf8, is_valid_utf8);
make_udf_function!(quote::SparkQuote, quote);
make_udf_function!(to_binary::SparkToBinary, to_binary);
make_udf_function!(to_binary::SparkTryToBinary, try_to_binary);

pub mod expr_fn {
use datafusion_functions::export_functions;
Expand Down Expand Up @@ -141,6 +144,16 @@ pub mod expr_fn {
"Returns str enclosed by single quotes and each instance of single quote in it is preceded by a backslash",
str
));
export_functions!((
to_binary,
"Converts the input str to a binary value based on the supplied fmt, which must be a case-insensitive literal of 'hex', 'utf-8', 'utf8' or 'base64'. Defaults to 'hex'.",
str fmt
));
export_functions!((
try_to_binary,
"Like to_binary, but returns NULL instead of raising an error when the conversion cannot be performed.",
str fmt
));
}

pub fn functions() -> Vec<Arc<ScalarUDF>> {
Expand All @@ -163,5 +176,7 @@ pub fn functions() -> Vec<Arc<ScalarUDF>> {
make_valid_utf8(),
is_valid_utf8(),
quote(),
to_binary(),
try_to_binary(),
]
}
Loading
Loading