Skip to content

Conversation

@lyne7-sc
Copy link
Contributor

Which issue does this PR close?

Part of: #15914

Rationale for this change

Implement spark compatible unhex functions:
https://spark.apache.org/docs/latest/api/sql/index.html#unhex

What changes are included in this PR?

Are these changes tested?

Yes. UTs and SLT added.

Are there any user-facing changes?

No.

@github-actions github-actions bot added sqllogictest SQL Logic Tests (.slt) spark labels Jan 20, 2026

Self {
signature: Signature::coercible(vec![string], Volatility::Immutable),
aliases: vec![],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove aliases if there are none

}

#[cfg(test)]
mod tests {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move all these tests to SLTs?

}
}

pub fn spark_unhex(args: &[ColumnarValue]) -> Result<ColumnarValue, DataFusionError> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need to be pub

Comment on lines +155 to +157
if args.len() != 1 {
return exec_err!("unhex tasks exactly 1 argument, but got: {}", args.len());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if args.len() != 1 {
return exec_err!("unhex tasks exactly 1 argument, but got: {}", args.len());
}
let arg = take_function_args("unhex", &args.args)?;

I: Iterator<Item = Option<T>>,
T: AsRef<str>,
{
let mut builder = BinaryBuilder::with_capacity(len, len * 32);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 32?

}
}

fn unhex_common(bytes: &[u8], out: &mut Vec<u8>) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to leave a simple comment on the function explaining the outputs (writes into out, returns boolean indicating if valid or not)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

spark sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants