Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## dbt-databricks 1.11.8 (TBD)

### Features

- Add `invocation_id` to the default query comment ([#1377](https://github.com/databricks/dbt-databricks/issues/1377))

### Fixes

- Validate relation identifier length at creation time and raise a clear error when it exceeds Databricks' 255-character limit ([#1309](https://github.com/databricks/dbt-databricks/issues/1309))
Expand Down
1 change: 1 addition & 0 deletions dbt/adapters/databricks/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
databricks_sql_connector_version='{dbsql_version}',
profile_name=target.get('profile_name'),
target_name=target.get('target_name'),
invocation_id=invocation_id,
) -%}}
{{%- if node is not none -%}}
{{%- do comment_dict.update(
Expand Down
40 changes: 40 additions & 0 deletions tests/unit/test_query_comment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import json

import jinja2

from dbt.adapters.databricks.connections import DATABRICKS_QUERY_COMMENT


def _render_default_query_comment(*, node, connection_name="connection"):
captured = {}

def _return(value):
captured["value"] = value
return ""

env = jinja2.Environment(extensions=["jinja2.ext.do"])
env.globals["tojson"] = json.dumps
template = env.from_string(DATABRICKS_QUERY_COMMENT)
template.render(
dbt_version="1.11.0",
target={"profile_name": "my_profile", "target_name": "dev"},
invocation_id="abc-123-uuid",
node=node,
connection_name=connection_name,
**{"return": _return},
)
return json.loads(captured["value"])


class TestDatabricksQueryComment:
def test_includes_invocation_id_with_node(self):
node = type("Node", (), {"unique_id": "model.proj.my_model"})()
comment = _render_default_query_comment(node=node)
assert comment["invocation_id"] == "abc-123-uuid"
assert comment["node_id"] == "model.proj.my_model"

def test_includes_invocation_id_without_node(self):
comment = _render_default_query_comment(node=None, connection_name="setup")
assert comment["invocation_id"] == "abc-123-uuid"
assert "node_id" not in comment
assert comment["connection_name"] == "setup"
Loading