Commit 5f3e28b
authored
[PECOBLR-676] passing session params in open session request instead of SET commands (#283)
<!-- We welcome contributions. All patches must include a sign-off.
Please see CONTRIBUTING.md for details -->
## Description
This PR **refactors session parameter handling** in the Go SQL Connector
to align with other Databricks drivers (Java, Python). Previously,
session parameters were set using `SET` statements after connection
establishment, which was inefficient and inconsistent with other
drivers. This new implementation also supports usage of QUERY_TAGS
session parameter. Query Tags allow users to attach key-value pairs to
SQL executions that appear in the `system.query.history` table.
### Changes Made:
1. **Refactored Session Parameter Flow** (`connector.go`):
- **Before**: Session parameters were sent via `SET` statements after
`OpenSession`
- **After**: Session parameters are passed directly to
`TOpenSessionReq.Configuration` during session creation
- **Benefit**: Aligns with Java and Python drivers, and improves
performance
2. **Created Example** (`examples/query_tags/main.go`):
- Demonstrates the usage of Query Tags
4. **Enhanced Unit Tests** (`internal/config/config_test.go`):
- Added `QUERY_TAGS` to DSN parsing test to verify parameter extraction
### Change from User Perspective:
The key difference is in **error timing**: Previously, invalid session
parameters would fail during connection establishment (SET command
execution), but now they fail during the first query execution. This
happens because the Databricks backend uses lazy validation - it accepts
session parameters during connection but validates them only when the
first query is executed. This matches Python driver behavior.
### Query tags usage example:
```go
connector, err := dbsql.NewConnector(
dbsql.WithSessionParams(map[string]string{
"timezone": "America/Sao_Paulo",
"ansi_mode": "true",
"QUERY_TAGS": "team:engineering",
}),
)
```
## How is this tested?
- [x] Unit tests
- [x] Manually
### Testing Details:
**Unit Tests**:
- Enhanced DSN parsing tests to verify session parameter extraction for
query tags
- All existing tests pass with the new implementation
**Manual Testing**:
- Verified session parameters including query tags work correctly with
real backend using the created exampleFile tree
4 files changed
+58
-13
lines changed- examples/query_tags
- internal/config
4 files changed
+58
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | 68 | | |
77 | 69 | | |
78 | 70 | | |
| |||
215 | 207 | | |
216 | 208 | | |
217 | 209 | | |
218 | | - | |
219 | | - | |
| 210 | + | |
220 | 211 | | |
221 | 212 | | |
222 | 213 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
132 | | - | |
| 132 | + | |
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
| |||
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
143 | | - | |
| 143 | + | |
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
| |||
0 commit comments