Skip to content

Conversation

@pepijnve
Copy link
Contributor

Which issue does this PR close?

Rationale for this change

Spark's bit_count function always operators on 64-bit values, while the original bit_count implementation in datafusion_spark operated on the native size of the input value.
In order to fix this a custom bit counting implementation was ported over from the Java Spark implementation. This isn't really necessary though. Widening signed integers to i64 and then using i64::count_ones will get you the exact same result and is less obscure.

What changes are included in this PR?

Remove custom bitcount logic and use i64::count_ones instead.

Are these changes tested?

Covered by existing tests that were added for #18225

Are there any user-facing changes?

No

@github-actions github-actions bot added the spark label Nov 20, 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 like a nice improvement to me -- thanks @pepijnve

@alamb alamb changed the title Remove unnecessary bit counting code Remove unnecessary bit counting code from spark bit_count Nov 20, 2025
Copy link
Contributor

@comphead comphead left a comment

Choose a reason for hiding this comment

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

Thanks @pepijnve in Spark/JVM and Rust sometimes there are discrepancies, like treating decimals, regexp, etc.

please add tests for booleans T/F/null

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants