forked from dbt-msft/dbt-sqlserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_interaction_tablock_query_options.py
More file actions
65 lines (53 loc) · 2.01 KB
/
Copy pathtest_interaction_tablock_query_options.py
File metadata and controls
65 lines (53 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
"""Interaction coverage for #613 (query_options) + #640 (TABLOCK on contract INSERT).
Each feature is exercised by its own test suite in isolation. This file verifies
that when both are present, a contract-enforced table model with query_options
emits both `WITH (TABLOCK)` (the INSERT target hint) and the `OPTION (...)`
query hint without either path interfering with the other.
The test lives on a dedicated branch that merges both feature branches because
neither individual branch can exercise the combined output: #640 alone ignores
query_options config, and #613 alone uses the non-contract `SELECT * INTO`
path which has no TABLOCK to emit.
"""
import os
import pytest
from dbt.tests.util import run_dbt
model_sql = """
{{ config(materialized='table', query_options={'MAXDOP': 1}) }}
select 1 as id
"""
model_yml = """
version: 2
models:
- name: contract_with_options
config:
contract:
enforced: true
columns:
- name: id
data_type: int
"""
class TestContractTableWithQueryOptions:
@pytest.fixture(scope="class")
def models(self):
return {
"contract_with_options.sql": model_sql,
"schema.yml": model_yml,
}
def test_both_hints_in_compiled_sql(self, project):
results = run_dbt(["run"])
assert len(results) == 1
assert results[0].status == "success"
target_dir = os.path.join(project.project_root, "target", "run")
for root, _dirs, files in os.walk(target_dir):
if "contract_with_options.sql" in files:
with open(os.path.join(root, "contract_with_options.sql"), "r") as f:
sql = f.read()
break
else:
raise AssertionError("Could not find compiled contract_with_options.sql")
# TABLOCK is the INSERT target hint (#640).
assert "WITH (TABLOCK)" in sql
# MAXDOP comes from query_options (#613).
assert "MAXDOP 1" in sql
# The default LABEL is always present.
assert "LABEL =" in sql