-
Notifications
You must be signed in to change notification settings - Fork 351
/
metastore_utils.go
71 lines (61 loc) · 1.67 KB
/
metastore_utils.go
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package metastore
import (
"errors"
"fmt"
"net/url"
"github.com/treeverse/lakefs/pkg/gateway/path"
)
const symlinkInputFormat = "org.apache.hadoop.hive.ql.io.SymlinkTextInputFormat"
var ErrInvalidLocation = errors.New("got empty schema or host wile parsing location url, location should be schema://host/path")
func ReplaceBranchName(location, branch string) (string, error) {
u, err := url.Parse(location)
if err != nil {
return "", err
}
if u.Scheme == "" || u.Host == "" {
return "", ErrInvalidLocation
}
p, err := path.ResolvePath(u.Path)
if err != nil {
return "", err
}
return u.Scheme + "://" + u.Host + "/" + branch + "/" + p.Path, nil
}
func ReplaceExternalToLakeFSImported(location, repo, branch string) (string, error) {
u, err := url.Parse(location)
if err != nil {
return "", err
}
if u.Scheme == "" || u.Host == "" {
return "", fmt.Errorf("%w: %s", ErrInvalidLocation, location)
}
return u.Scheme + "://" + repo + "/" + branch + "/" + u.Path, nil
}
func GetSymlinkLocation(location, locationPrefix string) (string, error) {
u, err := url.Parse(location)
if err != nil {
return "", err
}
if u.Scheme == "" || u.Host == "" {
return "", ErrInvalidLocation
}
p, err := path.ResolvePath(u.Path)
if err != nil {
return "", err
}
return locationPrefix + "/" + u.Host + "/" + p.Ref + "/" + p.Path, nil
}
func ExtractRepoAndBranch(metastoreLocationURI string) (string, string, error) {
u, err := url.Parse(metastoreLocationURI)
if err != nil {
return "", "", err
}
if u.Scheme == "" || u.Host == "" {
return "", "", ErrInvalidLocation
}
p, err := path.ResolvePath(u.Path)
if err != nil {
return "", "", err
}
return u.Host, p.Ref, nil
}