Skip to content

Commit f68cc29

Browse files
adding location to user config (#47)
Adding location property to config of type `time.Location` so session param timezone can be used to parse dates and timestamps. Signed-off-by: Andre Furlan <[email protected]>
1 parent e686f76 commit f68cc29

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

connection.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ func (c *conn) QueryContext(ctx context.Context, query string, args []driver.Nam
114114
client: c.client,
115115
opHandle: opHandle,
116116
pageSize: int64(c.cfg.MaxRows),
117+
location: c.cfg.Location,
117118
}
118119

119120
if exStmtResp.DirectResults != nil {

internal/config/config.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ type UserConfig struct {
7474
MaxRows int // TODO
7575
QueryTimeoutSeconds int // There are several timeouts that can be possibly configurable
7676
UserAgentEntry string
77+
Location *time.Location
7778
SessionParams map[string]string
7879
}
7980

@@ -184,6 +185,10 @@ func ParseDSN(dsn string) (UserConfig, error) {
184185
ucfg.Schema = params.Get("schema")
185186
params.Del("schema")
186187
}
188+
if params.Has("timezone") {
189+
tz := params.Get("timezone")
190+
ucfg.Location, err = time.LoadLocation(tz)
191+
}
187192
if len(params) > 0 {
188193
sessionParams := make(map[string]string)
189194
for k := range params {
@@ -193,5 +198,5 @@ func ParseDSN(dsn string) (UserConfig, error) {
193198

194199
}
195200

196-
return ucfg, nil
201+
return ucfg, err
197202
}

internal/config/config_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package config
33
import (
44
"reflect"
55
"testing"
6+
"time"
67
)
78

89
func TestParseConfig(t *testing.T) {
910
type args struct {
1011
dsn string
1112
}
13+
tz, _ := time.LoadLocation("America/Vancouver")
1214
tests := []struct {
1315
name string
1416
args args
@@ -82,7 +84,7 @@ func TestParseConfig(t *testing.T) {
8284
},
8385
{
8486
name: "with query params and session params",
85-
args: args{dsn: "token:[email protected]:8000/sql/1.0/endpoints/12346a5b5b0e123a?timeout=100&maxRows=1000&timezone=PST"},
87+
args: args{dsn: "token:[email protected]:8000/sql/1.0/endpoints/12346a5b5b0e123a?timeout=100&maxRows=1000&timezone=America/Vancouver"},
8688
wantCfg: UserConfig{
8789
Protocol: "https",
8890
Host: "example.cloud.databricks.com",
@@ -91,7 +93,8 @@ func TestParseConfig(t *testing.T) {
9193
HTTPPath: "/sql/1.0/endpoints/12346a5b5b0e123a",
9294
QueryTimeoutSeconds: 100,
9395
MaxRows: 1000,
94-
SessionParams: map[string]string{"timezone": "PST"},
96+
Location: tz,
97+
SessionParams: map[string]string{"timezone": "America/Vancouver"},
9598
},
9699
wantURL: "https://token:[email protected]:8000/sql/1.0/endpoints/12346a5b5b0e123a",
97100
wantErr: false,

0 commit comments

Comments
 (0)