Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

query tags integration#663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall 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
30 changes: 30 additions & 0 deletionsexamples/query_tags_example.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
import os
import databricks.sql as sql

"""
This example demonstrates how to use Query Tags.

Query Tags are key-value pairs that can be attached to SQL executions and will appear
in the system.query.history table for analytical purposes.

Format: "key1:value1,key2:value2,key3:value3"
"""

print("=== Query Tags Example ===\n")

with sql.connect(
server_hostname=os.getenv("DATABRICKS_SERVER_HOSTNAME"),
http_path=os.getenv("DATABRICKS_HTTP_PATH"),
access_token=os.getenv("DATABRICKS_TOKEN"),
session_configuration={
'QUERY_TAGS': 'team:engineering,test:query-tags',
'ansi_mode': False
}
) as connection:

with connection.cursor() as cursor:
cursor.execute("SELECT 1")
result = cursor.fetchone()
print(f" Result: {result[0]}")

print("\n=== Query Tags Example Complete ===")
1 change: 1 addition & 0 deletionssrc/databricks/sql/backend/sea/utils/constants.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,6 +15,7 @@
"STATEMENT_TIMEOUT": "0",
"TIMEZONE": "UTC",
"USE_CACHED_RESULT": "true",
"QUERY_TAGS": "",
}


Expand Down
2 changes: 1 addition & 1 deletiontests/e2e/test_driver.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -897,7 +897,7 @@ def test_timestamps_arrow(self):
)
def test_multi_timestamps_arrow(self, extra_params):
with self.cursor(
{"session_configuration": {"ansi_mode": False}, **extra_params}
{"session_configuration": {"ansi_mode": False, "query_tags": "test:multi-timestamps,driver:python"}, **extra_params}
) as cursor:
query, expected = self.multi_query()
expected = [
Expand Down
6 changes: 6 additions & 0 deletionstests/unit/test_sea_backend.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -185,6 +185,7 @@ def test_session_management(self, sea_client, mock_http_client, thrift_session_i
session_config = {
"ANSI_MODE": "FALSE", # Supported parameter
"STATEMENT_TIMEOUT": "3600", # Supported parameter
"QUERY_TAGS": "team:marketing,dashboard:abc123", # Supported parameter
"unsupported_param": "value", # Unsupported parameter
}
catalog = "test_catalog"
Expand All@@ -196,6 +197,7 @@ def test_session_management(self, sea_client, mock_http_client, thrift_session_i
"session_confs": {
"ansi_mode": "FALSE",
"statement_timeout": "3600",
"query_tags": "team:marketing,dashboard:abc123",
},
"catalog": catalog,
"schema": schema,
Expand DownExpand Up@@ -641,6 +643,7 @@ def test_filter_session_configuration(self):
"TIMEZONE": "UTC",
"enable_photon": False,
"MAX_FILE_PARTITION_BYTES": 128.5,
"QUERY_TAGS": "team:engineering,project:data-pipeline",
"unsupported_param": "value",
"ANOTHER_UNSUPPORTED": 42,
}
Expand All@@ -663,6 +666,7 @@ def test_filter_session_configuration(self):
"timezone": "UTC", # string -> "UTC", key lowercased
"enable_photon": "False", # boolean False -> "False", key lowercased
"max_file_partition_bytes": "128.5", # float -> "128.5", key lowercased
"query_tags": "team:engineering,project:data-pipeline",
}

assert result == expected_result
Expand All@@ -683,12 +687,14 @@ def test_filter_session_configuration(self):
"ansi_mode": "false", # lowercase key
"STATEMENT_TIMEOUT": 7200, # uppercase key
"TiMeZoNe": "America/New_York", # mixed case key
"QueRy_TaGs": "team:marketing,test:case-insensitive",
}
result = _filter_session_configuration(case_insensitive_config)
expected_case_result = {
"ansi_mode": "false",
"statement_timeout": "7200",
"timezone": "America/New_York",
"query_tags": "team:marketing,test:case-insensitive",
}
assert result == expected_case_result

Expand Down
2 changes: 1 addition & 1 deletiontests/unit/test_session.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -154,7 +154,7 @@ def test_socket_timeout_passthrough(self, mock_client_class):

@patch("%s.session.ThriftDatabricksClient" % PACKAGE_NAME)
def test_configuration_passthrough(self, mock_client_class):
mock_session_config =Mock()
mock_session_config ={"ANSI_MODE": "FALSE", "QUERY_TAGS": "team:engineering,project:data-pipeline"}
databricks.sql.connect(
session_configuration=mock_session_config, **self.DUMMY_CONNECTION_ARGS
)
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp