Skip to content

Commit

Permalink
Fixing issues with hive URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
kenshaw committed Nov 30, 2023
1 parent f19a1d2 commit 718c97c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
18 changes: 18 additions & 0 deletions dburl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,24 @@ func TestParse(t *testing.T) {
`dbname=mydb host=/var/run/postgresql password=pass user=user`,
`/var/run/postgresql`,
},
{
`hive://myhost/mydb`,
`hive`,
`myhost:10000/mydb`,
``,
},
{
`hi://myhost:9999/mydb?auth=PLAIN`,
`hive`,
`myhost:9999/mydb?auth=PLAIN`,
``,
},
{
`hive2://user:pass@myhost:9999/mydb?auth=PLAIN`,
`hive`,
`user:pass@myhost:9999/mydb?auth=PLAIN`,
``,
},
}
m := make(map[string]bool)
for i, tt := range tests {
Expand Down
11 changes: 1 addition & 10 deletions dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@ func GenScheme(scheme string) func(*URL) (string, string, error) {
}
}

// GenSchemeTruncate generates a DSN by truncating the scheme://.
func GenSchemeTruncate(u *URL) (string, string, error) {
s := u.String()
if i := strings.Index(s, "://"); i != -1 {
return s[i+3:], "", nil
}
return s, "", nil
}

// GenFromURL returns a func that generates a DSN based on parameters of the
// passed URL.
func GenFromURL(urlstr string) func(*URL) (string, string, error) {
Expand Down Expand Up @@ -90,7 +81,7 @@ func GenFromURL(urlstr string) func(*URL) (string, string, error) {
RawQuery: q.Encode(),
Fragment: fragment,
}
return y.String(), "", nil
return strings.TrimPrefix(y.String(), "truncate://"), "", nil
}
}

Expand Down
6 changes: 4 additions & 2 deletions scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ func BaseSchemes() []Scheme {
},
{
"hive",
GenSchemeTruncate, 0, false, nil, "",
GenFromURL("truncate://localhost:10000/"), 0, false,
[]string{"hive2"},
"",
},
{
"ignite",
Expand All @@ -250,7 +252,7 @@ func BaseSchemes() []Scheme {
},
{
"maxcompute",
GenSchemeTruncate, 0, false,
GenFromURL("truncate://localhost/"), 0, false,
[]string{"mc"},
"",
},
Expand Down

0 comments on commit 718c97c

Please sign in to comment.