Repository navigation
[YAML] Fix SQL-backed Combine query generation for Calcite expressions and SQL shorthand (#41288) - #41289
[YAML] Fix SQL-backed Combine query generation for Calcite expressions and SQL shorthand (#41288)#41289vishalmore90 wants to merge 1 commit into
Conversation
…s and SQL shorthand (apache#41288)
There was a problem hiding this comment.
📋 Review Summary
This PR cleanly resolves SQL query generation bugs in Beam YAML's Combine transform when using calcite or sql dialects with full SQL expressions, shorthand column aggregations, or explicit Combine-<language> transform types. The implementation in normalize_combine and _SqlCombineTransform is well-structured and backed by unit tests covering the newly fixed scenarios.
🔍 General Feedback
- The normalization logic and fallback handling in
_SqlCombineTransformproperly handle both parameterized expressions (containing() and shorthand function names acrosssqlandcalciteconfigurations. - Unit tests directly validate the generated SQL queries without requiring an external Java/Calcite expansion service, keeping the test suite fast and deterministic.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
Assigning reviewers: R: @chamikaramj for label yaml. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
fixes #41288
Description
In Beam YAML, SQL-backed aggregations are supported via both
language: sqlandlanguage: calcite(as registered bySqlBackedProviderinapache_beam/yaml/yaml_combine.pyand documented indocumentation/sdks/yaml-combine.md).However, two related query generation bugs occurred:
language: calcitewith SQL expressions (e.g.total: "sum(col2)"),normalize_combinecheckedconfig.get('language') != 'sql', which evaluated toTrue. This mistakenly injectedagg['value'] = dest('total'). In_SqlCombineTransform, having avaluecausedcombine_colto format it assum(col2)(total) as total, which failed in Calcite withSqlParseException.language: sqlwith shorthand aggregations (e.g.col2: sum),config.get('language') != 'sql'evaluated toFalse, skippingagg['value'] = dest. In_SqlCombineTransform, having novaluecausedcombine_colto treat'sum'as a complete expression, formatting it assum as col2(instead ofsum(col2) as col2).typewas specified with an explicit provider suffix liketype: Combine-sqlorCombine-calcite,normalize_combinedid not run because it strictly checkedspec['type'] == 'Combine'.Changes Made
normalize_combine:spec['type'] == 'Combine' or spec['type'].startswith('Combine-').'sql'and'calcite'as SQL dialects.agg['value'] = destif the aggregation is already an expression containing arguments ('(' in fn_name). Shorthand aggregations (e.g.col2: sum) properly receiveagg['value'] = 'col2'._SqlCombineTransform:combine_col, checks iffn_typealready contains(. If so, uses it directly as the expression without attempting to append parentheses or arguments.fn_typedoes not contain(and novaluewas specified, defaults the argument todest(f'{fn_type}({dest})').yaml_combine_test.pyverifying Calcite expressions (sum(c),count(*)), SQL shorthand (c: sum), Calcite shorthand, andCombine-calcitetype suffixes.CHANGES.md.