Naming#
Note
The below checks require catalog.json to be present.
Checks related to column naming conventions.
Functions:
| Name | Description |
|---|---|
check_column_name_complies_to_column_type |
Columns with the specified regexp naming pattern must have data types that comply to the specified regexp pattern or list of data types. |
check_column_type_complies_to_column_name |
Columns with the specified data type must have names that comply to the specified regexp pattern. |
check_column_names |
Columns must have a name that matches the supplied regex. |
check_column_name_complies_to_column_type
#
Columns with the specified regexp naming pattern must have data types that comply to the specified regexp pattern or list of data types.
Rationale
Naming conventions that encode data types (e.g. is_ prefix for booleans, _date suffix for dates, _id suffix for integers) are a common and effective way to make schemas self-describing. Without enforcement, these conventions drift over time: a column named is_active might be stored as an integer in one model and a boolean in another, causing silent cast errors downstream. This check ties naming patterns to data types, catching mismatches at CI time rather than in production queries.
Note: One of type_pattern or types must be specified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
column_name_pattern
|
str
|
Regex pattern to match the model name. |
required |
type_pattern
|
str | None
|
Regex pattern to match the data types. |
None
|
types
|
list[str] | None
|
List of data types to check. |
None
|
Receives at execution time:
| Name | Type | Description |
|---|---|---|
catalog_node |
CatalogNodeEntry
|
The CatalogNodeEntry object to check. |
Other Parameters (passed via config file):
| Name | Type | Description |
|---|---|---|
description |
str | None
|
Description of what the check does and why it is implemented. |
exclude |
str | None
|
Regex pattern to match the model path. Model paths that match the pattern will not be checked. |
include |
str | None
|
Regex pattern to match the model path. Only model paths that match the pattern will be checked. |
severity |
Literal[error, warn] | None
|
Severity level of the check. Default: |
Example(s):
catalog_checks:
# DATE columns must end with "_date"
- name: check_column_name_complies_to_column_type
column_name_pattern: .*_date$
types:
- DATE
catalog_checks:
# BOOLEAN columns must start with "is_"
- name: check_column_name_complies_to_column_type
column_name_pattern: ^is_.*
types:
- BOOLEAN
catalog_checks:
# Columns of all types must consist of lowercase letters and underscores. Note that the specified types depend on the underlying database.
- name: check_column_name_complies_to_column_type
column_name_pattern: ^[a-z_]*$
types:
- BIGINT
- BOOLEAN
- DATE
- DOUBLE
- INTEGER
- VARCHAR
catalog_checks:
# No STRUCT data types permitted.
- name: check_column_name_complies_to_column_type
column_name_pattern: ^[a-z_]*$
type_pattern: ^(?!STRUCT)
Source code in src/dbt_bouncer/checks/catalog/columns/naming.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
check_column_type_complies_to_column_name
#
Columns with the specified data type must have names that comply to the specified regexp pattern.
Rationale
This is the reverse of check_column_name_complies_to_column_type. While that check ensures columns with a given naming pattern have the correct data type, this check ensures columns with a given data type follow the correct naming convention. For example, you may want all BOOLEAN columns to start with is_ or has_, or all DATE columns to end with _date. Enforcing this direction catches columns that have the right type but the wrong name — a gap the other check cannot cover.
Note: One of type_pattern or types must be specified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
column_name_pattern
|
str
|
Regex pattern that column names must match. |
required |
type_pattern
|
str | None
|
Regex pattern to match the data types. |
None
|
types
|
list[str] | None
|
List of data types to check. |
None
|
Receives at execution time:
| Name | Type | Description |
|---|---|---|
catalog_node |
CatalogNodeEntry
|
The CatalogNodeEntry object to check. |
Other Parameters (passed via config file):
| Name | Type | Description |
|---|---|---|
description |
str | None
|
Description of what the check does and why it is implemented. |
exclude |
str | None
|
Regex pattern to match the model path. Model paths that match the pattern will not be checked. |
include |
str | None
|
Regex pattern to match the model path. Only model paths that match the pattern will be checked. |
severity |
Literal[error, warn] | None
|
Severity level of the check. Default: |
Example(s):
catalog_checks:
# BOOLEAN columns must start with "is_" or "has_"
- name: check_column_type_complies_to_column_name
column_name_pattern: ^(is|has)_.*
types:
- BOOLEAN
catalog_checks:
# DATE columns must end with "_date"
- name: check_column_type_complies_to_column_name
column_name_pattern: .*_date$
types:
- DATE
catalog_checks:
# Integer-like columns must end with "_id" or "_count"
- name: check_column_type_complies_to_column_name
column_name_pattern: .*((_id)|(_count))$
types:
- BIGINT
- INTEGER
Source code in src/dbt_bouncer/checks/catalog/columns/naming.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
check_column_names
#
Columns must have a name that matches the supplied regex.
Rationale
Consistent column naming is the foundation of a readable and maintainable dbt project. Inconsistent casing, abbreviations, or special characters make SQL harder to write, cause join errors, and confuse data consumers who query the warehouse directly. A single enforced naming pattern (e.g. ^[a-z_]*$ for snake_case) eliminates an entire class of stylistic bugs and ensures that columns look the same whether viewed in dbt docs, a BI tool, or a raw SQL editor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
column_name_pattern
|
str
|
Regexp the column name must match. |
required |
Receives at execution time:
| Name | Type | Description |
|---|---|---|
catalog_node |
CatalogNodeEntry
|
The CatalogNodeEntry object to check. |
Other Parameters (passed via config file):
| Name | Type | Description |
|---|---|---|
description |
str | None
|
Description of what the check does and why it is implemented. |
exclude |
str | None
|
Regex pattern to match the model path. Model paths that match the pattern will not be checked. |
include |
str | None
|
Regex pattern to match the model path. Only model paths that match the pattern will be checked. |
materialization |
Literal[ephemeral, incremental, table, view] | None
|
Limit check to models with the specified materialization. |
severity |
Literal[error, warn] | None
|
Severity level of the check. Default: |
Example(s):
catalog_checks:
- name: check_column_names
column_name_pattern: [a-z_] # Lowercase only, underscores allowed