-
Notifications
You must be signed in to change notification settings - Fork 90
/
table.go
69 lines (57 loc) · 1.97 KB
/
table.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
package hive
import (
"net/url"
"path"
"github.com/operator-framework/operator-metering/pkg/db"
)
type Column struct {
Name string `json:"name"`
Type string `json:"type"`
}
type SortColumn struct {
Name string `json:"name"`
Decending *bool `json:"decending,omitempty"`
}
type TableParameters struct {
Database string `json:"database,omitempty"`
Name string `json:"name"`
Columns []Column `json:"columns"`
PartitionedBy []Column `json:"partitionedBy,omitempty"`
ClusteredBy []string `json:"clusteredBy,omitempty"`
SortedBy []SortColumn `json:"sortedBy,omitempty"`
NumBuckets int `json:"numBuckets,omitempty"`
Location string `json:"location,omitempty"`
RowFormat string `json:"rowFormat,omitempty"`
FileFormat string `json:"fileFormat,omitempty"`
TableProperties map[string]string `json:"tableProperties,omitempty"`
External bool `json:"external,omitempty"`
}
type TablePartition struct {
Location string `json:"location"`
PartitionSpec PartitionSpec `json:"partitionSpec"`
}
type PartitionSpec map[string]string
func ExecuteCreateTable(execer db.Execer, params TableParameters, ignoreExists bool) error {
query := generateCreateTableSQL(params, ignoreExists)
_, err := execer.Exec(query)
return err
}
func ExecuteDropTable(execer db.Execer, dbName, tableName string, ignoreNotExists bool) error {
query := generateDropTableSQL(dbName, tableName, ignoreNotExists, false)
_, err := execer.Exec(query)
return err
}
// s3Location returns the HDFS path based on an S3 bucket and prefix.
func S3Location(bucket, prefix string) (string, error) {
bucket = path.Join(bucket, prefix)
// Ensure the bucket URL has a trailing slash
if bucket[len(bucket)-1] != '/' {
bucket = bucket + "/"
}
location := "s3a://" + bucket
locationURL, err := url.Parse(location)
if err != nil {
return "", err
}
return locationURL.String(), nil
}