[SQL] Support positional parameters#38880
Conversation
1251b3e to
34e213b
Compare
Summary of ChangesHello, 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 enables support for positional parameters in Apache Beam SQL, addressing a long-standing limitation. By implementing a parameter binding mechanism during the logical plan conversion phase, the changes allow users to safely execute parameterized queries. The update includes robust handling for various temporal data types to ensure consistent behavior across different input formats. Highlights
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 AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces support for positional query parameters in Beam SQL by implementing a ParameterBinder (which extends RexShuttle) to replace dynamic parameters with their literal values. It also adds corresponding unit tests in BeamSqlDslParametersTest. Feedback on these changes highlights a compilation error in bindParameters where a RexShuttle is incorrectly passed to RelNode.accept, which expects a RelShuttle. Additionally, it is suggested to update the logging statement to output the resolved plan (relNode) rather than the original plan with unbound parameters.
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.
| private static RelNode bindParameters(RelNode rel, RexShuttle binder) { | ||
| RelNode newRel = rel.accept(binder); | ||
| java.util.List<RelNode> newInputs = new java.util.ArrayList<>(); | ||
| for (RelNode input : newRel.getInputs()) { | ||
| newInputs.add(bindParameters(input, binder)); | ||
| } | ||
| return newRel.copy(newRel.getTraitSet(), newInputs); | ||
| } |
There was a problem hiding this comment.
The bindParameters method attempts to call rel.accept(binder) where binder is a RexShuttle. However, in Apache Calcite, RelNode only has an accept(RelShuttle) method, and RexShuttle does not implement RelShuttle. This will cause a compilation error.
To apply a RexShuttle to a RelNode's expressions, you should use a RelShuttle that visits the RelNode and applies the RexShuttle to its expressions (for example, by overriding visit methods or using rel.accept(new RelShuttleImpl() { ... })). Since doing this manually for all relational operators is verbose, you can use rel.accept(new RelShuttleImpl() { ... }) and override the visit methods, or use a custom RelShuttle implementation that handles expression transformation.
| relNode, | ||
| new ParameterBinder(root.rel.getCluster().getRexBuilder(), queryParameters)); | ||
| } | ||
| LOG.info("SQLPlan>\n{}", BeamSqlRelUtils.explainLazily(root.rel)); |
There was a problem hiding this comment.
The logging statement still prints the original plan root.rel which contains unbound dynamic parameters (?). It would be more helpful to log the plan after parameter binding (relNode) so that the fully resolved query plan is visible in the logs.
| LOG.info("SQLPlan>\n{}", BeamSqlRelUtils.explainLazily(root.rel)); | |
| LOG.info("SQLPlan>\n{}", BeamSqlRelUtils.explainLazily(relNode)); |
|
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment |
34e213b to
4f96a27
Compare
| @@ -33,19 +35,17 @@ | |||
| import org.apache.beam.sdk.values.Row; | |||
| import org.junit.Rule; | |||
| import org.junit.Test; | |||
| import org.testcontainers.shaded.com.fasterxml.jackson.databind.MapperFeature; | |||
There was a problem hiding this comment.
Introduced in #30902, this test never get exercised
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #38880 +/- ##
============================================
- Coverage 57.77% 54.34% -3.44%
+ Complexity 12969 1704 -11265
============================================
Files 2509 1062 -1447
Lines 260525 166465 -94060
Branches 10658 1250 -9408
============================================
- Hits 150516 90461 -60055
+ Misses 104318 73789 -30529
+ Partials 5691 2215 -3476
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Fix #18563
Please add a meaningful description for your change here
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, commentfixes #<ISSUE NUMBER>instead.CHANGES.mdwith noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.
To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md
GitHub Actions Tests Status (on master branch)
See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.