Skip to content

Conversation

@ofek1weiss
Copy link
Contributor

@ofek1weiss ofek1weiss commented Sep 3, 2025

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

    • Improved handling of empty query results to prevent errors during result grouping.
    • Ensures a consistent empty response when no data is returned, improving stability in edge cases.
  • Chores

    • Minor internal adjustments to result processing logic for safer execution paths with no data.

@linear
Copy link

linear bot commented Sep 3, 2025

@ofek1weiss ofek1weiss temporarily deployed to elementary_test_env September 3, 2025 13:39 — with GitHub Actions Inactive
@coderabbitai
Copy link

coderabbitai bot commented Sep 3, 2025

Walkthrough

Adds 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

Cohort / File(s) Summary of Changes
Result handling guard
elementary/monitor/dbt_project/macros/get_result_rows_agate.sql
Replaced direct return of grouped query result with two-step flow: assign run_query output to res, return {} if falsy, else return res.group_by("elementary_test_results_id").

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I tapped my paw, awaited rows—
The query hummed, but nothing shows.
No carrots here? I won’t despair,
I’ll hand you {} with careful care.
When harvest comes, I’ll group and sort—
A tidy burrowed data report. 🥕

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch app-60-fix-group-by-in-clickhouse

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 3, 2025

👋 @ofek1weiss
Thank you for raising your pull request.
Please make sure to add tests and document all user-facing changes.
You can do this by editing the docs files in this pull request.

Copy link

@coderabbitai coderabbitai bot left a 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 explicit is none.

Some adapters return an empty agate Table (truthy) rather than None for 0 rows. In that case, group_by may still be problematic or wasteful. Using is none is clearer than not res in 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.

📥 Commits

Reviewing files that changed from the base of the PR and between fd4bfd8 and 5f38f20.

📒 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 calling group_by on None (likely from ClickHouse zero-row returns). Solid defensive fix.


12-16: Drop the return-type contract check: callers only use .get(...), which both TableSet and dict implement—returning {} is safe.

Likely an incorrect or invalid review comment.

@ofek1weiss ofek1weiss temporarily deployed to elementary_test_env September 7, 2025 07:35 — with GitHub Actions Inactive
@ofek1weiss ofek1weiss merged commit 44f8f8a into master Sep 7, 2025
5 checks passed
@ofek1weiss ofek1weiss deleted the app-60-fix-group-by-in-clickhouse branch September 7, 2025 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants