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

Commitbcab1df

Browse files
authored
query tags integration (#663)
* query tags integrationSigned-off-by: Sreekanth Vadigi <sreekanth.vadigi@databricks.com>* query tags with sea flowSigned-off-by: Sreekanth Vadigi <sreekanth.vadigi@databricks.com>* optmized testsSigned-off-by: Sreekanth Vadigi <sreekanth.vadigi@databricks.com>---------Signed-off-by: Sreekanth Vadigi <sreekanth.vadigi@databricks.com>
1 parent048fae1 commitbcab1df

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

‎examples/query_tags_example.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
importos
2+
importdatabricks.sqlassql
3+
4+
"""
5+
This example demonstrates how to use Query Tags.
6+
7+
Query Tags are key-value pairs that can be attached to SQL executions and will appear
8+
in the system.query.history table for analytical purposes.
9+
10+
Format: "key1:value1,key2:value2,key3:value3"
11+
"""
12+
13+
print("=== Query Tags Example ===\n")
14+
15+
withsql.connect(
16+
server_hostname=os.getenv("DATABRICKS_SERVER_HOSTNAME"),
17+
http_path=os.getenv("DATABRICKS_HTTP_PATH"),
18+
access_token=os.getenv("DATABRICKS_TOKEN"),
19+
session_configuration={
20+
'QUERY_TAGS':'team:engineering,test:query-tags',
21+
'ansi_mode':False
22+
}
23+
)asconnection:
24+
25+
withconnection.cursor()ascursor:
26+
cursor.execute("SELECT 1")
27+
result=cursor.fetchone()
28+
print(f" Result:{result[0]}")
29+
30+
print("\n=== Query Tags Example Complete ===")

‎src/databricks/sql/backend/sea/utils/constants.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"STATEMENT_TIMEOUT":"0",
1616
"TIMEZONE":"UTC",
1717
"USE_CACHED_RESULT":"true",
18+
"QUERY_TAGS":"",
1819
}
1920

2021

‎tests/e2e/test_driver.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ def test_timestamps_arrow(self):
901901
)
902902
deftest_multi_timestamps_arrow(self,extra_params):
903903
withself.cursor(
904-
{"session_configuration": {"ansi_mode":False},**extra_params}
904+
{"session_configuration": {"ansi_mode":False,"query_tags":"test:multi-timestamps,driver:python"},**extra_params}
905905
)ascursor:
906906
query,expected=self.multi_query()
907907
expected= [

‎tests/unit/test_sea_backend.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ def test_session_management(self, sea_client, mock_http_client, thrift_session_i
185185
session_config= {
186186
"ANSI_MODE":"FALSE",# Supported parameter
187187
"STATEMENT_TIMEOUT":"3600",# Supported parameter
188+
"QUERY_TAGS":"team:marketing,dashboard:abc123",# Supported parameter
188189
"unsupported_param":"value",# Unsupported parameter
189190
}
190191
catalog="test_catalog"
@@ -196,6 +197,7 @@ def test_session_management(self, sea_client, mock_http_client, thrift_session_i
196197
"session_confs": {
197198
"ansi_mode":"FALSE",
198199
"statement_timeout":"3600",
200+
"query_tags":"team:marketing,dashboard:abc123",
199201
},
200202
"catalog":catalog,
201203
"schema":schema,
@@ -641,6 +643,7 @@ def test_filter_session_configuration(self):
641643
"TIMEZONE":"UTC",
642644
"enable_photon":False,
643645
"MAX_FILE_PARTITION_BYTES":128.5,
646+
"QUERY_TAGS":"team:engineering,project:data-pipeline",
644647
"unsupported_param":"value",
645648
"ANOTHER_UNSUPPORTED":42,
646649
}
@@ -663,6 +666,7 @@ def test_filter_session_configuration(self):
663666
"timezone":"UTC",# string -> "UTC", key lowercased
664667
"enable_photon":"False",# boolean False -> "False", key lowercased
665668
"max_file_partition_bytes":"128.5",# float -> "128.5", key lowercased
669+
"query_tags":"team:engineering,project:data-pipeline",
666670
}
667671

668672
assertresult==expected_result
@@ -683,12 +687,14 @@ def test_filter_session_configuration(self):
683687
"ansi_mode":"false",# lowercase key
684688
"STATEMENT_TIMEOUT":7200,# uppercase key
685689
"TiMeZoNe":"America/New_York",# mixed case key
690+
"QueRy_TaGs":"team:marketing,test:case-insensitive",
686691
}
687692
result=_filter_session_configuration(case_insensitive_config)
688693
expected_case_result= {
689694
"ansi_mode":"false",
690695
"statement_timeout":"7200",
691696
"timezone":"America/New_York",
697+
"query_tags":"team:marketing,test:case-insensitive",
692698
}
693699
assertresult==expected_case_result
694700

‎tests/unit/test_session.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def test_socket_timeout_passthrough(self, mock_client_class):
155155

156156
@patch("%s.session.ThriftDatabricksClient"%PACKAGE_NAME)
157157
deftest_configuration_passthrough(self,mock_client_class):
158-
mock_session_config=Mock()
158+
mock_session_config={"ANSI_MODE":"FALSE","QUERY_TAGS":"team:engineering,project:data-pipeline"}
159159
databricks.sql.connect(
160160
session_configuration=mock_session_config,**self.DUMMY_CONNECTION_ARGS
161161
)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp