-
Notifications
You must be signed in to change notification settings - Fork 204
Handle empty result in clickhouse #2002
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
Conversation
WalkthroughAdds a null/empty-result check to the get_result_rows_agate macro: runs the query, returns an empty object when no result is returned, otherwise groups the result by "elementary_test_results_id". Query construction is unchanged. Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant Macro as get_result_rows_agate
participant DB as elementary.run_query
Caller->>Macro: invoke(query)
Macro->>DB: run_query(query)
DB-->>Macro: res
alt res is truthy
Note right of Macro: Group rows by "elementary_test_results_id"
Macro-->>Caller: res.group_by("elementary_test_results_id")
else res is null/empty
Note right of Macro: Return empty object
Macro-->>Caller: {}
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
✨ Finishing Touches🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
|
👋 @ofek1weiss |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
elementary/monitor/dbt_project/macros/get_result_rows_agate.sql (1)
12-16: Also guard for empty tables and prefer explicitis none.Some adapters return an empty agate Table (truthy) rather than
Nonefor 0 rows. In that case,group_bymay still be problematic or wasteful. Usingis noneis clearer thannot resin Jinja.Suggested tweak:
- {% set res = elementary.run_query(query) %} - {% if not res %} - {% do return({}) %} - {% endif %} - {% do return(res.group_by("elementary_test_results_id")) %} + {% set res = elementary.run_query(query) %} + {% if res is none or (res|length == 0) %} + {% do return({}) %} + {% else %} + {% do return(res.group_by("elementary_test_results_id")) %} + {% endif %}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
elementary/monitor/dbt_project/macros/get_result_rows_agate.sql(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: code-quality
🔇 Additional comments (2)
elementary/monitor/dbt_project/macros/get_result_rows_agate.sql (2)
12-16: Good null-guard before group_by.Adding the guard around
elementary.run_query(query)prevents callinggroup_byonNone(likely from ClickHouse zero-row returns). Solid defensive fix.
12-16: Drop the return-type contract check: callers only use.get(...), which bothTableSetanddictimplement—returning{}is safe.Likely an incorrect or invalid review comment.
In most warehouses, when running a query with no results, we get an empty table that contains the queried columns in return
In clickhouse, we get an empty table without any columns...
Summary by CodeRabbit
Bug Fixes
Chores