-
Notifications
You must be signed in to change notification settings - Fork 117
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff 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 ===") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
"STATEMENT_TIMEOUT": "0", | ||
"TIMEZONE": "UTC", | ||
"USE_CACHED_RESULT": "true", | ||
"QUERY_TAGS": "", | ||
} | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -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, | ||
|
@@ -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, | ||
} | ||
|
@@ -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 | ||
|
@@ -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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly two scenarios we can add here
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
assert result == expected_case_result | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a test with invalid query param format & see if we are getting the required error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the backend design docs, it is mentioned that invalid query tags will be ignored without raising error so that actual query execution won't result in failure. Tested manually in local by passing invalid/non-parsable query tags - backend doesn't throw error