jroachgolf84 commented on code in PR #66895:
URL: https://github.com/apache/airflow/pull/66895#discussion_r3266111349
##########
providers/databricks/src/airflow/providers/databricks/hooks/databricks_sql.py:
##########
@@ -71,6 +74,35 @@ def _cancel():
return timer, timeout_event
+def _format_query_tag_value(value: str) -> str:
+ """
+ Escape special characters and truncate a single query tag value.
+
+ Databricks ``QUERY_TAGS`` uses ``key:value`` pairs delimited by commas, so
+ backslash, comma and colon inside *values* must be escaped. Values are
also
+ capped at 128 characters before escaping to keep the overall tag string
+ within reasonable bounds.
+ """
+ raw = str(value)
+ if len(raw) > 128:
+ log.warning(
+ "Query tag value truncated to 128 characters (original length %d):
%r", len(raw), raw[:128]
+ )
+ value = raw[:128]
+ return value.replace("\\", "\\\\").replace(",", "\\,").replace(":", "\\:")
+
+
+def _format_query_tags(tags: dict[str, str | None]) -> str:
+ """
+ Serialize a query-tags dict to the ``key:value,key:value`` string expected
by ``QUERY_TAGS``.
+
+ Entries whose value is ``None`` are omitted.
+ """
+ return ",".join(
+ f"{key}:{_format_query_tag_value(value)}" for key, value in
tags.items() if value is not None
Review Comment:
There is no scenario where the `key` could have a value of `None`, correct?
##########
providers/databricks/src/airflow/providers/databricks/hooks/databricks_sql.py:
##########
@@ -71,6 +74,35 @@ def _cancel():
return timer, timeout_event
+def _format_query_tag_value(value: str) -> str:
+ """
+ Escape special characters and truncate a single query tag value.
+
+ Databricks ``QUERY_TAGS`` uses ``key:value`` pairs delimited by commas, so
Review Comment:
Thanks for the comment, I was going to ask why 128.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]