Skip to content

Support global sort and improve UDF overload resolution in Beam SQL#38832

Draft
damccorm wants to merge 5 commits into
apache:masterfrom
damccorm:feature/spark-connect-sql-parity
Draft

Support global sort and improve UDF overload resolution in Beam SQL#38832
damccorm wants to merge 5 commits into
apache:masterfrom
damccorm:feature/spark-connect-sql-parity

Conversation

@damccorm
Copy link
Copy Markdown
Contributor

@damccorm damccorm commented Jun 5, 2026

Add a few SQL improvements

  • Enable ORDER BY without LIMIT (global sort) in BeamSortRel by sorting in-memory.
  • Add AssertSorted test helper and testOrderBy_noLimit to verify global sort.
  • Map common Java classes to Calcite SqlTypeName in CalciteUtils.sqlTypeWithAutoCast, and add testSqlTypeWithAutoCast.
  • Prioritize overloaded methods with maximum parameter count in UdfImpl lookup, and add UdfImplTest.
  • Update LazyAggregateCombineFnTest to expect SQL BIGINT type instead of Java Long class.

- Enable ORDER BY without LIMIT (global sort) in BeamSortRel by sorting in-memory.
- Add AssertSorted test helper and testOrderBy_noLimit to verify global sort.
- Map common Java classes to Calcite SqlTypeName in CalciteUtils.sqlTypeWithAutoCast, and add testSqlTypeWithAutoCast.
- Prioritize overloaded methods with maximum parameter count in UdfImpl lookup, and add UdfImplTest.
- Update LazyAggregateCombineFnTest to expect SQL BIGINT type instead of Java Long class.

TAG=agy
CONV=0df243da-2867-4795-9889-6334ba7d1599
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces several enhancements to Beam SQL, primarily focusing on expanding query capabilities and improving type system robustness. Key changes include enabling global sorting for queries without a LIMIT clause, refining how overloaded user-defined functions are resolved, and improving the mapping between Java types and Calcite SQL types.

Highlights

  • Global Sort Support: Enabled ORDER BY without LIMIT in Beam SQL by implementing an in-memory sorting mechanism using a dummy key and GroupByKey.
  • UDF Overload Resolution: Improved UDF method lookup to prioritize overloads with the maximum number of parameters, ensuring better compatibility with optional/default arguments.
  • Type Mapping Improvements: Enhanced CalciteUtils to map standard Java primitive and wrapper classes to corresponding Calcite SQL types.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for ORDER BY without a LIMIT in BeamSortRel by grouping all rows under a dummy key and sorting them in-memory. It also updates UdfImpl to prioritize overloaded methods with the maximum number of parameters and maps standard Java classes to Calcite SQL types in CalciteUtils. The reviewer suggests introducing a deterministic tie-breaker in UdfImpl to handle overloaded methods with the same parameter count consistently, and simplifying the long if-else chain in CalciteUtils using a switch statement and dynamic nullability checks.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

…terministic UdfImpl lookup

- Simplify Java class to Calcite type mapping in CalciteUtils using a switch statement and dynamic nullability check.
- Use deterministic tie-breaker in UdfImpl.findMethod when resolving overloaded methods with the same parameter count.

TAG=agy
CONV=0df243da-2867-4795-9889-6334ba7d1599
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

Assigning reviewers:

R: @ahmedabu98 for label java.

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@damccorm
Copy link
Copy Markdown
Contributor Author

damccorm commented Jun 5, 2026

/gemini review

@damccorm damccorm marked this pull request as draft June 5, 2026 17:00
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for ORDER BY without a LIMIT in Beam SQL by routing all rows to a single dummy key and sorting them in-memory. It also updates UDF method resolution to prioritize overloads with the maximum number of parameters and maps standard Java classes to Calcite SQL types with proper nullability. The review feedback highlights a critical scalability bottleneck in the global sorting implementation that could lead to OutOfMemoryError on large datasets. Additionally, the reviewer suggests using direct Class comparisons instead of string-based class name checks in CalciteUtils for better performance, and warns that the new UDF overload resolution strategy may shadow valid overloads with fewer parameters of different types.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Use a static ImmutableMap for Java to SQL type mapping instead of a switch
statement, improving lookup performance and code readability.

TAG=agy
CONV=0df243da-2867-4795-9889-6334ba7d1599
@damccorm
Copy link
Copy Markdown
Contributor Author

damccorm commented Jun 5, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for ORDER BY without a LIMIT in BeamSortRel by grouping all rows under a dummy key and sorting them in-memory. It also improves overloaded method resolution in UdfImpl to prioritize methods with more parameters, and maps standard Java classes to Calcite SQL types in CalciteUtils. Feedback on these changes includes addressing a missing import for WithKeys in BeamSortRel that would cause a compilation error, and optimizing UdfImpl by using getParameterCount() instead of getParameterTypes().length to avoid unnecessary array allocations.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

…ensions/sql/impl/UdfImpl.java

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant