dbt-labs / dbt-labs/dbt-adapters

[Feature] Support pseudocolumns in unit tests

Open
#1,517 1 comment 0 reactions 0 assignees View on GitHub
triage:product type:enhancement
Dominant language
Python
Stars
233
Forks
362
Avg merge
3d 22h
Merged PRs (30d)
9

Description

### Is this your first time submitting a feature request?

- [x] I have read the [expectations for open source contributors](https://docs.getdbt.com/docs/contributing/oss-expectations)
- [x] I have searched the existing issues, and I could not find an existing issue for this feature
- [x] I am requesting a straightforward extension of existing dbt functionality, rather than a Big Idea better suited to a discussion

### Describe the feature

I would like to be able to define pseudocolumns, like BigQuery's [_file_name](https://docs.cloud.google.com/bigquery/docs/query-cloud-storage-data#query_the_file_name_pseudo-column) pseudocolumn, in unit tests.

### Describe alternatives you've considered

I've considered using the [sql](https://docs.getdbt.com/reference/resource-properties/data-formats#sql) data format for my unit test's input, but I don't want to have to define input values for all columns.

### Who will this benefit?

This feature will be useful for teams that apply logic based on file name in staging models that reference BigQuery external source tables.

### Are you interested in contributing this feature?

With a bit of direction, I'd be happy to write some code!

### Anything else?

Here's a snippet of the unit test I had written:
```yaml
unit_tests:
- name: test_is_valid_file_date_time
description: Confirm that macro correctly parses date and time from file names
model: {model_name}
given:
- input: source('{source_name}', '{table_name}')
rows:
- {_file_name: 2025-12-18.csv, appointment_id: '1'}
- {_file_name: 2025-12-23_05-00-21.csv, appointment_id: '1'}
- {_file_name: 2025-12-18.csv, appointment_id: '2'}
expect:
rows:
- {appointment_id: '1', data_last_updated: '2025-12-23 05:00:21'}
- {appointment_id: '2', data_last_updated: '2025-12-18'}
```

When I ran the test, it failed on this compilation error:
```
14:07:23 Failure in unit_test test_is_valid_file_date_time ({path/to/unit_test}.yml)
14:07:23 Compilation Error in model {model_name} ({path/to/unit_test}.yml)
Invalid column name: '_file_name' in unit test fixture for '{table_name}'.
Accepted columns for '{table_name}' are: [{column_names}]

> in macro format_row (macros/unit_test_sql/get_fixture_sql.sql)
> called by macro get_fixture_sql (macros/unit_test_sql/get_fixture_sql.sql)
> called by model charm_appointments (models/staging/charm/_charm__unit_tests.yml)
```

I believe that [format_row](https://github.com/dbt-labs/dbt-adapters/blob/1e7448f9b6c3440d28fefd5b34b6dcf86c36def1/dbt-adapters/src/dbt/include/global_project/macros/unit_test_sql/get_fixture_sql.sql#L76-L83) raises the error because the `_file_name` column doesn't appear in the information schema for the external source table.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.