Skip to content

Commit acad168

Browse files
authored
query tags integration (#927)
## Description This PR adds **Query Tags** support to the JDBC driver. Users can now attach labels to their SQL queries for analytical purposes. Tags follow the format `key1:value1,key2:value2"` and appear in the `system.query.history` table. ### Changes Made: - **Added `QUERY_TAGS`** to the list of allowed session configurations in `DatabricksJdbcConstants.java` ### How to Use: - URL: jdbc:databricks://host;QUERY_TAGS=team:marketing,dashboard:abc123 - Properties: properties.put("QUERY_TAGS", "team:engineering,project:pipeline") ## Testing - Tested manually by creating a connection with query tags passed as connection property and verified that they're sent to the backend successfully, and appear in the system.query.histroy table ## Additional Notes to the Reviewer - Works with both Thrift and SEA modes - Backward compatible - existing connections work unchanged ### Future Plans: - **Statement-level tags** will be added later (currently session-level only) --------- Signed-off-by: Sreekanth Vadigi <sreekanth.vadigi@databricks.com>
1 parent 7a137e1 commit acad168

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [Unreleased]
44

55
### Added
6+
- **Query Tags support**: Added ability to attach key-value tags to SQL queries for analytical purposes that would appear in `system.query.history` table. Example: `jdbc:databricks://host;QUERY_TAGS=team:marketing,dashboard:abc123`.
67

78
### Updated
89

src/main/java/com/databricks/jdbc/common/DatabricksJdbcConstants.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ public final class DatabricksJdbcConstants {
8181
"READ_ONLY_EXTERNAL_METASTORE", "false",
8282
"STATEMENT_TIMEOUT", "0",
8383
"TIMEZONE", "UTC",
84-
"USE_CACHED_RESULT", "true");
84+
"USE_CACHED_RESULT", "true",
85+
"QUERY_TAGS", "");
8586
public static final Set<String> ALLOWED_CLIENT_INFO_PROPERTIES =
8687
Set.of(
8788
ALLOWED_VOLUME_INGESTION_PATHS,

src/test/java/com/databricks/jdbc/api/impl/DatabricksConnectionTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,4 +472,15 @@ void testHoldability() throws SQLException {
472472
assertThrows(
473473
DatabricksSQLFeatureNotSupportedException.class, () -> connection.setHoldability(3));
474474
}
475+
476+
@Test
477+
public void testQueryTagsInSessionConfigs() throws SQLException {
478+
String queryTagsJdbcUrl = JDBC_URL + ";QUERY_TAGS=team:marketing,dashboard:abc123";
479+
IDatabricksConnectionContext connectionContext =
480+
DatabricksConnectionContext.parse(queryTagsJdbcUrl, new Properties());
481+
482+
Map<String, String> sessionConfigs = connectionContext.getSessionConfigs();
483+
assertTrue(sessionConfigs.containsKey("query_tags"));
484+
assertEquals("team:marketing,dashboard:abc123", sessionConfigs.get("query_tags"));
485+
}
475486
}

0 commit comments

Comments
 (0)