Skip to content

Commit 3509255

Browse files
authored
Merge pull request dbt-msft#679 from Benjamin-Knight/test/tablock-query-options-interaction
Test tablock and query options interaction
2 parents 2b785c5 + bdf7b5d commit 3509255

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"""Interaction coverage for #613 (query_options) + #640 (TABLOCK on contract INSERT).
2+
3+
Each feature is exercised by its own test suite in isolation. This file verifies
4+
that when both are present, a contract-enforced table model with query_options
5+
emits both `WITH (TABLOCK)` (the INSERT target hint) and the `OPTION (...)`
6+
query hint without either path interfering with the other.
7+
8+
The test lives on a dedicated branch that merges both feature branches because
9+
neither individual branch can exercise the combined output: #640 alone ignores
10+
query_options config, and #613 alone uses the non-contract `SELECT * INTO`
11+
path which has no TABLOCK to emit.
12+
"""
13+
14+
import os
15+
16+
import pytest
17+
18+
from dbt.tests.util import run_dbt
19+
20+
model_sql = """
21+
{{ config(materialized='table', query_options={'MAXDOP': 1}) }}
22+
select 1 as id
23+
"""
24+
25+
model_yml = """
26+
version: 2
27+
models:
28+
- name: contract_with_options
29+
config:
30+
contract:
31+
enforced: true
32+
columns:
33+
- name: id
34+
data_type: int
35+
"""
36+
37+
38+
class TestContractTableWithQueryOptions:
39+
@pytest.fixture(scope="class")
40+
def models(self):
41+
return {
42+
"contract_with_options.sql": model_sql,
43+
"schema.yml": model_yml,
44+
}
45+
46+
def test_both_hints_in_compiled_sql(self, project):
47+
results = run_dbt(["run"])
48+
assert len(results) == 1
49+
assert results[0].status == "success"
50+
51+
target_dir = os.path.join(project.project_root, "target", "run")
52+
for root, _dirs, files in os.walk(target_dir):
53+
if "contract_with_options.sql" in files:
54+
with open(os.path.join(root, "contract_with_options.sql"), "r") as f:
55+
sql = f.read()
56+
break
57+
else:
58+
raise AssertionError("Could not find compiled contract_with_options.sql")
59+
60+
# TABLOCK is the INSERT target hint (#640).
61+
assert "WITH (TABLOCK)" in sql
62+
# MAXDOP comes from query_options (#613).
63+
assert "MAXDOP 1" in sql
64+
# The default LABEL is always present.
65+
assert "LABEL =" in sql

0 commit comments

Comments
 (0)