Conversation
…y type (#3585) When count(*) was combined with non-aggregate projections (e.g. SELECT count(*), 2 FROM empty_type), the query returned no results instead of a row with count=0. The fix properly identifies count(*) as the sole aggregate even when aggregateProjection contains pass-through alias refs for non-aggregate items, and evaluates those non-aggregate expressions in the zero-count synthetic result. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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 resolves a bug where SQL queries using Highlights
🧠 New Feature in Public Preview: You can now enable Memory 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. Changelog
Activity
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 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 counter productive. 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. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
Code ReviewGood fix for a clear regression — the logic is sound and the approach of broadening the Bug:
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses the issue where an aggregating projection with count(*) on an empty type would incorrectly return no results. The changes are well-implemented: findCountStarItem correctly identifies count(*) as the sole aggregate function, and GuaranteeEmptyCountStep is extended to handle non-aggregate projection items, ensuring a synthetic row is produced. The addition of specific regression tests for literal and LET variable projections is a great way to verify the fix. I have one suggestion to improve code readability by refactoring a complex condition.
| final Expression exp = item.getExpression(); | ||
| if (exp.getMathExpression() != null && exp.getMathExpression() instanceof final BaseExpression base | ||
| && base.isCount() && base.getModifier() == null) | ||
| countItem = item; | ||
| else | ||
| return null; // aggregate but not count(*) | ||
| } | ||
| return countItem; | ||
| } |
There was a problem hiding this comment.
The logic to identify a count(*) expression is a bit complex and hurts readability. Extracting it into a dedicated private helper method isCountStarExpression would make the findCountStarItem method cleaner and more maintainable.
final Expression exp = item.getExpression();
if (isCountStarExpression(exp)) {
countItem = item;
} else {
return null; // aggregate but not count(*)
}
}
return countItem;
}
private static boolean isCountStarExpression(final Expression exp) {
return exp.getMathExpression() != null && exp.getMathExpression() instanceof final BaseExpression base
&& base.isCount() && base.getModifier() == null;
}- Remove dead isCountOnly() method (replaced by findCountStarItem) - Simplify redundant null check before instanceof in findCountStarItem - Add non-empty-type test for count(*) + literal projection Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Addressed the review feedback in c78fea6:
Did not extract |
Code ReviewThe fix is correct and the approach is sound. A few observations: Overall assessmentThe core fix is solid. Minor: undocumented null-Result contract in
|
| Projection | Behaviour |
|---|---|
count(*) alone |
returns count(*) item ✓ |
count(*), 2 |
non-aggregate skipped, returns count(*) item ✓ |
count(*), sum(x) |
second aggregate → countItem != null → returns null ✓ |
sum(x), count(*) |
first aggregate is not count(*) → returns null immediately ✓ |
count(*), count(*) |
second count(*) → countItem != null → returns null ✓ |
Summary
- One actionable item: add the inline comment explaining the
nullResult contract. - Nice to have: test for multiple non-aggregate projections in the same query.
- The fix itself is production-ready.
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferences |
🧪 CI InsightsHere's what we observed from your CI run for c78fea6. 🟢 All jobs passed!But CI Insights is watching 👀 |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3587 +/- ##
==========================================
- Coverage 65.71% 65.37% -0.34%
==========================================
Files 1514 1514
Lines 103661 103672 +11
Branches 21454 21457 +3
==========================================
- Hits 68118 67776 -342
- Misses 26306 26660 +354
+ Partials 9237 9236 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
Fixes #3585
SELECT count(*), 2 FROM empty_typeandSELECT count(*), $x FROM empty_type LET $x = 2now correctly return 1 row withcount(*) = 0and the non-aggregate valuesfindCountStarItem()to properly identify count(*) as the sole aggregate even whenaggregateProjectioncontains pass-through alias refs for non-aggregate itemsGuaranteeEmptyCountStepto evaluatepreAggregateProjectionitems (literals, LET variables) in the zero-count synthetic resultTest plan
countStarWithLiteralProjectionOnEmptyType— coversSELECT count(*), 2 FROM emptycountStarWithLetVariableProjectionOnEmptyType— coversSELECT count(*), $x FROM empty LET $x = 2SelectStatementExecutionTestpass🤖 Generated with Claude Code