|
4 | 4 | from agate import Row |
5 | 5 | from dbt.exceptions import DbtRuntimeError |
6 | 6 |
|
7 | | -from dbt.adapters.databricks.relation_configs.query import QueryConfig, QueryProcessor |
| 7 | +from dbt.adapters.databricks.relation_configs.query import ( |
| 8 | + QueryConfig, |
| 9 | + QueryProcessor, |
| 10 | + ViewQueryConfig, |
| 11 | + ViewQueryProcessor, |
| 12 | +) |
8 | 13 |
|
9 | 14 | sql = "select * from foo" |
10 | 15 |
|
@@ -50,3 +55,46 @@ def test_get_diff__different_query(self): |
50 | 55 | } |
51 | 56 | other = QueryProcessor.from_relation_results(results) |
52 | 57 | assert model.get_diff(other) is model |
| 58 | + |
| 59 | + |
| 60 | +class TestViewQueryProcessor: |
| 61 | + def test_from_results(self): |
| 62 | + results = {"information_schema.views": Row([sql, "other"], ["view_definition", "comment"])} |
| 63 | + spec = ViewQueryProcessor.from_relation_results(results) |
| 64 | + assert spec == ViewQueryConfig(query=sql) |
| 65 | + |
| 66 | + def test_from_model_node__with_query(self): |
| 67 | + model = Mock() |
| 68 | + model.compiled_code = sql |
| 69 | + spec = ViewQueryProcessor.from_relation_config(model) |
| 70 | + assert spec == ViewQueryConfig(query=sql) |
| 71 | + |
| 72 | + def test_from_model_node__without_query(self): |
| 73 | + model = Mock() |
| 74 | + model.compiled_code = None |
| 75 | + model.identifier = "1" |
| 76 | + with pytest.raises( |
| 77 | + DbtRuntimeError, |
| 78 | + match="Cannot compile model 1 with no SQL query", |
| 79 | + ): |
| 80 | + _ = ViewQueryProcessor.from_relation_config(model) |
| 81 | + |
| 82 | + def test_get_diff__always_returns_self_for_identical_query(self): |
| 83 | + model = ViewQueryConfig(query="select * from foo") |
| 84 | + results = { |
| 85 | + "information_schema.views": Row( |
| 86 | + ["(\nselect * from foo\n)", "other"], ["view_definition", "comment"] |
| 87 | + ) |
| 88 | + } |
| 89 | + other = ViewQueryProcessor.from_relation_results(results) |
| 90 | + assert model.get_diff(other) is model |
| 91 | + |
| 92 | + def test_get_diff__always_returns_self_for_different_query(self): |
| 93 | + model = ViewQueryConfig(query="select * from foo") |
| 94 | + results = { |
| 95 | + "information_schema.views": Row( |
| 96 | + ["(\nselect * from bar\n)", "other"], ["view_definition", "comment"] |
| 97 | + ) |
| 98 | + } |
| 99 | + other = ViewQueryProcessor.from_relation_results(results) |
| 100 | + assert model.get_diff(other) is model |
0 commit comments