Skip to content

Fix Python UDAF Accumulator Interface example to Properly Handle State and Updates with List[Array] Types #1192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 28, 2025

Conversation

kosiew
Copy link
Contributor

@kosiew kosiew commented Jul 27, 2025

Which issue does this PR close?

Rationale for this change

This PR updates the MyAccumulator implementation in the Python UDAF example to properly handle updates and state using list[pa.Array] types, aligning with the expected interface in newer versions of PyArrow. Without this change, the accumulator may behave incorrectly or fail when integrating with systems expecting lists of arrays.

What changes are included in this PR?

  • Updated update() method signature to accept list[pa.Array] instead of a single pa.Array.
  • Modified the merge() method to correctly index into the first element of states, assuming it's a list.
  • Changed state() to return a list of pa.Array instead of a single pa.Array for consistency with updated interface expectations.

Are these changes tested?

The patch updates an example file, which may be executed to validate expected behavior. If automated tests are not available for this specific UDAF example, manual verification is recommended.

Are there any user-facing changes?

Yes, this affects users who are following or adapting the sql-using-python-udaf.py example. They should now provide and expect list[pa.Array] for update, merge, and state methods, in alignment with PyArrow expectations.

kosiew added 7 commits July 27, 2025 15:38
- Implement MyAccumulator class following Accumulator interface
- Register UDAF named "my_accumulator" in SessionContext
- Create test DataFrame and run SQL query using UDAF with GROUP BY
- Verify results match expected aggregated values
- Ensure correct integration and functionality of UDAF in Python bindings
Copy link
Contributor

@timsaucer timsaucer left a comment

Choose a reason for hiding this comment

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

Thank you @kosiew !

@timsaucer timsaucer merged commit be88837 into apache:main Jul 28, 2025
17 checks passed
@kosiew
Copy link
Contributor Author

kosiew commented Jul 29, 2025

@timsaucer , You're welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

the python udaf example cannot print the result
2 participants