Skip to content

Conversation

@Jefffrey
Copy link
Contributor

Which issue does this PR close?

Part of #12725

Rationale for this change

Prefer to avoid user_defined for consistency in function definitions.

What changes are included in this PR?

Refactor signature of bit_get away from user_defined.

Various other refactors.

Are these changes tested?

Existing tests.

Are there any user-facing changes?

There's a public function I made private but I don't think it was ever intended to be public.

@github-actions github-actions bot added sqllogictest SQL Logic Tests (.slt) spark labels Nov 20, 2025
pub fn new() -> Self {
Self {
signature: Signature::user_defined(Volatility::Immutable),
signature: Signature::coercible(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Signature change here

)
}
}?;
fn spark_bit_get(args: &[ArrayRef]) -> Result<ArrayRef> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function I made private, and also did a few refactors to make it more compact.

}

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

Choose a reason for hiding this comment

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

These tests were duplicated by the SLTs so removed them

@Jefffrey Jefffrey marked this pull request as ready for review November 20, 2025 06:30
}?;
fn spark_bit_get(args: &[ArrayRef]) -> Result<ArrayRef> {
let [value, position] = take_function_args("bit_get", args)?;
let pos_arg = position.as_primitive::<Int32Type>();
Copy link
Member

Choose a reason for hiding this comment

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

Is this safe to be done ?
From the other PR few days ago we know that position could be Null here.

Suggested change
let pos_arg = position.as_primitive::<Int32Type>();
let pos_arg = position.as_primitive_opt::<Int32Type>()
+ .ok_or_else(|| internal_err!("Expected Int32 for position argument"))?;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's safe, since we use Coercion::new_implicit then null types are casted to the target type (Int8). Also have an SLT test to verify this behaviour.

@alamb alamb changed the title Refactor bit_get() signature away from user defined Refactor spark bit_get() signature away from user defined Nov 21, 2025
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Looks great to me -- thank you @Jefffrey and @martin-g

fn spark_bit_get(args: &[ArrayRef]) -> Result<ArrayRef> {
let [value, position] = take_function_args("bit_get", args)?;
let pos_arg = position.as_primitive::<Int32Type>();
let ret = downcast_integer_array!(
Copy link
Contributor

Choose a reason for hiding this comment

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

that is certainly nicer

@Jefffrey Jefffrey added this pull request to the merge queue Nov 22, 2025
Merged via the queue into apache:main with commit 5e36b05 Nov 22, 2025
29 checks passed
@Jefffrey Jefffrey deleted the refactor-bit-get branch November 22, 2025 01:34
logan-keede pushed a commit to logan-keede/datafusion that referenced this pull request Nov 23, 2025
…8836)

## Which issue does this PR close?

<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closes apache#123` indicates that this PR will close issue apache#123.
-->

Part of apache#12725

## Rationale for this change

<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->

Prefer to avoid user_defined for consistency in function definitions.

## What changes are included in this PR?

<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->

Refactor signature of bit_get away from user_defined.

Various other refactors.

## Are these changes tested?

<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code

If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
-->

Existing tests.

## Are there any user-facing changes?

<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->

<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->

There's a public function I made private but I don't think it was ever
intended to be public.
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.

3 participants