Commit 3d3a87d
authored
fix: prevent duplicate alias in --empty mode for inline ref/source (#1397)
## Summary
- Sets `require_alias: bool = False` on `DatabricksRelation`, preventing
`render_limited()` from injecting a `_dbt_limit_subq_*` alias that
conflicts with user-provided `AS` aliases when running `dbt run --empty`
- Adds conformance tests for `--empty` mode (`BaseTestEmpty` and
`BaseTestEmptyInlineSourceRef`)
- Adds a unit test verifying `render_limited()` output has no trailing
subquery alias
## Context
When `dbt run --empty` is used, dbt wraps `ref()` and `source()` in a
zero-row subquery. `BaseRelation` defaults to `require_alias=True`,
which appends an auto-generated alias (`_dbt_limit_subq_{table}`). If
the user also has an `AS` alias in their SQL (e.g. `{{ ref('orders') }}
AS orders`), the two aliases conflict and produce invalid SQL.
Databricks SQL does not require subquery aliases, so `require_alias`
should be `False`.
Resolves dbt-labs/dbt-adapters#660 for Databricks.
## Test plan
- [x] Unit test: `test_render_limited_with_empty_no_alias` — asserts
`render_limited()` produces no trailing alias with `limit=0`
- [x] Functional test: `TestDatabricksEmptyInlineSourceRef` — end-to-end
against live cluster, `dbt run --empty` with inline source alias
- [x] Functional test: `TestDatabricksEmpty` — general `--empty`
conformance
- [x] All 721 existing unit tests pass (0 regressions)1 parent 8611c72 commit 3d3a87d
File tree
5 files changed
+24
-0
lines changed- dbt/adapters/databricks
- tests
- functional/adapter/empty
- unit
5 files changed
+24
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| 75 | + | |
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
| |||
Whitespace-only changes.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
368 | 368 | | |
369 | 369 | | |
370 | 370 | | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
0 commit comments