Commit d66311a
fix: enforce 255-character identifier length limit for Databricks relations (#1391)
## Summary
Enforces the 255-character identifier length limit for Databricks
relations at relation creation time, preventing a cryptic runtime
`DatabricksExecutionError` when `store_failures` generates overly-long
table names.
Closes #1309
## Problem
When `store_failures: true` is enabled, dbt generates table names by
concatenating the test name, model name, and arguments. For deep schema
tests with verbose names, this can exceed Databricks' 255-character
limit for table names, causing:
```
[RequestId=...] Invalid input: RPC CreateStagingTable Field
managedcatalog.StagingTableInfo.name: name "accepted_map_keys_stg_product_search_create_sizes__relax__..." too long.
Maximum length is 255 characters.
```
This error is unhelpful — it doesn't explain what the 255-character
limit is, which test/model caused it, or how to fix it.
## Fix
Added `relation_max_name_length()` and `__post_init__` validation to
`DatabricksRelation`, following the exact same pattern used by the
[Postgres
adapter](https://github.com/dbt-labs/dbt-adapters/blob/main/dbt-postgres/src/dbt/adapters/postgres/relation.py):
```python
MAX_CHARACTERS_IN_IDENTIFIER = 255
def relation_max_name_length(self):
return MAX_CHARACTERS_IN_IDENTIFIER
def __post_init__(self):
if (
self.identifier is not None
and self.type is not None
and len(self.identifier) > self.relation_max_name_length()
):
raise DbtRuntimeError(
f"Relation name '{self.identifier}' "
f"is longer than {self.relation_max_name_length()} characters. ..."
)
```
**Before:**
```
[RequestId=...] Invalid input: RPC CreateStagingTable ... name "accepted_map_keys_stg_..." too long.
```
**After:**
```
Relation name 'accepted_map_keys_stg_product_search_create_sizes__...'
is longer than 255 characters. Databricks has a maximum identifier
length of 255 characters. If this is a store_failures table, consider
using a shorter test name or setting a custom alias.
```
## Checklist
- [x] Follows the same pattern as the Postgres adapter
- [x] Catches the error at relation creation time, not at SQL execution
- [x] Error message includes actionable guidance
---------
Co-authored-by: Shubham Dhal <shubham.dhal@databricks.com>1 parent b082730 commit d66311a
3 files changed
Lines changed: 43 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
1 | 7 | | |
2 | 8 | | |
3 | 9 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
89 | 103 | | |
90 | 104 | | |
91 | 105 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| |||
370 | 372 | | |
371 | 373 | | |
372 | 374 | | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
373 | 396 | | |
374 | 397 | | |
375 | 398 | | |
| |||
0 commit comments