dbt-labs / dbt-labs/dbt-utils

dbt_utils.equal_rowcount error when comparing tables with 0 rows

Open Beginner friendly
#973 2 comments 2 reactions 0 assignees View on GitHub
bug triage
Dominant language
Makefile
Stars
1.8k
Forks
632
PR merge metrics
No merged PRs in 30d

Description

### Describe the bug

When using dbt_utils.equal_rowcount, comparing tables with 0 rows causes an error as the function returns null instead of a valid result.

### Steps to reproduce

1. Create two models with 0 rows in each.
2. Implement a test using dbt_utils.equal_rowcount to compare the two models.
3. Run the test.

### Expected results

The test should return 0 as the row count for both models matches (0 rows in each).

### Actual results

The test returns null instead of 0, causing an error.
```
03:25:12 Finished running 1 test, 2 project hooks in 0 hours 0 minutes and 4.11 seconds (4.11s).
03:25:13
03:25:13 Completed with 1 error and 0 warnings:
03:25:13
03:25:13 None is not of type 'integer'

Failed validating 'type' in schema['properties']['failures']:
{'type': 'integer'}

On instance['failures']:
None
03:25:13
03:25:13 Done. PASS=0 WARN=0 ERROR=1 SKIP=0 TOTAL=1
```

### Screenshots and log output

### System information
**The contents of your `packages.yml` file:**
- package: dbt-labs/dbt_utils
version: 1.1.1

**Which database are you using dbt with?**
- [ ] postgres
- [ ] redshift
- [x] bigquery
- [ ] snowflake
- [ ] other (specify: ____________)

**The output of `dbt --version`:**
```
Core:
- installed: 1.8.6
- latest: 1.9.1 - Update available!

Your version of dbt-core is out of date!
You can find instructions for upgrading here:
https://docs.getdbt.com/docs/installation

Plugins:
- bigquery: 1.8.2 - Update available!
```

### Additional context

https://github.com/dbt-labs/dbt-utils/blob/5c9dc0d43265cb86c5f69954e6d739dc7a1974c3/macros/generic_tests/equal_rowcount.sql#L8

### Are you interested in contributing the fix?

Sure! I would replace the implementation with something like:
`{{ config(fail_calc = 'coalesce(sum(diff_count), 0)') }}`

Contributor guide

Open the contributing guide

Research direction

Start by reading macros/generic_tests/equal_rowcount.sql at the linked line and reproduce the test with two empty models on BigQuery. Done means dbt_utils.equal_rowcount reports zero failures rather than null when both compared tables contain zero rows.

Written by the indexing model from the issue text.

Assessment

Tech stack
google-cloud, sql
Domain
databases, testing
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.