-
Notifications
You must be signed in to change notification settings - Fork 342
/
converter.go
249 lines (230 loc) · 7.67 KB
/
converter.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
package hive
import (
"github.com/treeverse/lakefs/pkg/metastore"
"github.com/treeverse/lakefs/pkg/metastore/hive/gen-go/hive_metastore"
)
func serDeHiveToLocal(g *hive_metastore.SerDeInfo) *metastore.SerDeInfo {
if g == nil {
return nil
}
return &metastore.SerDeInfo{
Name: g.Name,
SerializationLib: g.SerializationLib,
Parameters: g.Parameters,
}
}
func skewedHiveToLocal(g *hive_metastore.SkewedInfo) *metastore.SkewedInfo {
if g == nil {
return &metastore.SkewedInfo{}
}
return &metastore.SkewedInfo{
SkewedColNames: g.SkewedColNames,
SkewedColValues: g.SkewedColValues,
SkewedColValueLocationMaps: g.SkewedColValueLocationMaps,
}
}
func sortColumnsHiveToLocal(columns []*hive_metastore.Order) []*metastore.Order {
res := make([]*metastore.Order, len(columns))
for i, column := range columns {
res[i] = &metastore.Order{
Col: column.Col,
Order: int(column.Order),
}
}
return res
}
func columnsHiveToLocal(columns []*hive_metastore.FieldSchema) []*metastore.FieldSchema {
res := make([]*metastore.FieldSchema, len(columns))
for i, column := range columns {
res[i] = &metastore.FieldSchema{
Name: column.Name,
Type: column.Type,
Comment: column.Comment,
}
}
return res
}
func TableHiveToLocal(hiveTable *hive_metastore.Table) *metastore.Table {
sd := SDHiveToLocal(hiveTable.Sd)
ht := &metastore.Table{
TableName: hiveTable.TableName,
DBName: hiveTable.DbName,
Owner: hiveTable.Owner,
CreateTime: int64(hiveTable.CreateTime),
LastAccessTime: int64(hiveTable.LastAccessTime),
Retention: int(hiveTable.Retention),
Sd: sd,
PartitionKeys: columnsHiveToLocal(hiveTable.PartitionKeys),
Parameters: hiveTable.Parameters,
ViewOriginalText: hiveTable.ViewOriginalText,
ViewExpandedText: hiveTable.ViewExpandedText,
TableType: hiveTable.TableType,
Temporary: hiveTable.Temporary,
RewriteEnabled: hiveTable.RewriteEnabled,
}
return ht
}
func serDeLocalToHive(info *metastore.SerDeInfo) *hive_metastore.SerDeInfo {
if info == nil {
return nil
}
return &hive_metastore.SerDeInfo{
Name: info.Name,
SerializationLib: info.SerializationLib,
Parameters: info.Parameters,
}
}
func skewedLocalToHive(info *metastore.SkewedInfo) *hive_metastore.SkewedInfo {
if info == nil {
return &hive_metastore.SkewedInfo{}
}
return &hive_metastore.SkewedInfo{
SkewedColNames: info.SkewedColNames,
SkewedColValues: info.SkewedColValues,
SkewedColValueLocationMaps: info.SkewedColValueLocationMaps,
}
}
func sortColumnsLocalToHive(columns []*metastore.Order) []*hive_metastore.Order {
res := make([]*hive_metastore.Order, len(columns))
for i, column := range columns {
res[i] = &hive_metastore.Order{
Col: column.Col,
Order: int32(column.Order),
}
}
return res
}
func columnsLocalToHive(columns []*metastore.FieldSchema) []*hive_metastore.FieldSchema {
res := make([]*hive_metastore.FieldSchema, len(columns))
for i, column := range columns {
res[i] = &hive_metastore.FieldSchema{
Name: column.Name,
Type: column.Type,
Comment: column.Comment,
}
}
return res
}
func TableLocalToHive(table *metastore.Table) *hive_metastore.Table {
sd := SDLocalToHive(table.Sd)
privileges, _ := table.Privileges.(*hive_metastore.PrincipalPrivilegeSet)
ht := &hive_metastore.Table{
DbName: table.DBName,
TableName: table.TableName,
Owner: table.Owner,
CreateTime: int32(table.CreateTime),
LastAccessTime: int32(table.LastAccessTime),
Retention: int32(table.Retention),
Sd: sd,
PartitionKeys: columnsLocalToHive(table.PartitionKeys),
Parameters: table.Parameters,
ViewOriginalText: table.ViewOriginalText,
ViewExpandedText: table.ViewExpandedText,
TableType: table.TableType,
Privileges: privileges,
Temporary: table.Temporary,
RewriteEnabled: table.RewriteEnabled,
}
return ht
}
func PartitionHiveToLocal(hivePartition *hive_metastore.Partition) *metastore.Partition {
sd := SDHiveToLocal(hivePartition.Sd)
partition := &metastore.Partition{
Values: hivePartition.Values,
DBName: hivePartition.DbName,
TableName: hivePartition.TableName,
CreateTime: int(hivePartition.CreateTime),
LastAccessTime: int(hivePartition.LastAccessTime),
Sd: sd,
Parameters: hivePartition.Parameters,
}
return partition
}
func PartitionsHiveToLocal(gluePartitions []*hive_metastore.Partition) []*metastore.Partition {
partitions := make([]*metastore.Partition, len(gluePartitions))
for i, partition := range gluePartitions {
partitions[i] = PartitionHiveToLocal(partition)
}
return partitions
}
func DatabaseLocalToHive(db *metastore.Database) *hive_metastore.Database {
privileges, _ := db.HivePrivileges.(*hive_metastore.PrincipalPrivilegeSet)
ownerType, _ := db.HiveOwnerType.(*hive_metastore.PrincipalType)
return &hive_metastore.Database{
Name: db.Name,
Description: db.Description,
LocationUri: db.LocationURI,
Parameters: db.Parameters,
Privileges: privileges,
OwnerName: db.OwnerName,
OwnerType: ownerType,
}
}
func DatabaseHiveToLocal(db *hive_metastore.Database) *metastore.Database {
return &metastore.Database{
Name: db.Name,
Description: db.Description,
LocationURI: db.LocationUri,
Parameters: db.Parameters,
}
}
func PartitionLocalToHive(partition *metastore.Partition) *hive_metastore.Partition {
sd := SDLocalToHive(partition.Sd)
privileges, _ := partition.Privileges.(*hive_metastore.PrincipalPrivilegeSet)
ht := &hive_metastore.Partition{
Values: partition.Values,
DbName: partition.DBName,
TableName: partition.TableName,
CreateTime: int32(partition.CreateTime),
LastAccessTime: int32(partition.LastAccessTime),
Sd: sd,
Parameters: partition.Parameters,
Privileges: privileges,
}
return ht
}
func SDLocalToHive(sd *metastore.StorageDescriptor) *hive_metastore.StorageDescriptor {
if sd == nil {
return nil
}
return &hive_metastore.StorageDescriptor{
Cols: columnsLocalToHive(sd.Cols),
Location: sd.Location,
InputFormat: sd.InputFormat,
OutputFormat: sd.OutputFormat,
Compressed: sd.Compressed,
NumBuckets: int32(sd.NumBuckets),
SerdeInfo: serDeLocalToHive(sd.SerdeInfo),
BucketCols: sd.BucketCols,
SortCols: sortColumnsLocalToHive(sd.SortCols),
Parameters: sd.Parameters,
SkewedInfo: skewedLocalToHive(sd.SkewedInfo),
StoredAsSubDirectories: sd.StoredAsSubDirectories,
}
}
func SDHiveToLocal(sd *hive_metastore.StorageDescriptor) *metastore.StorageDescriptor {
if sd == nil {
return nil
}
return &metastore.StorageDescriptor{
Cols: columnsHiveToLocal(sd.Cols),
Location: sd.Location,
InputFormat: sd.InputFormat,
OutputFormat: sd.OutputFormat,
Compressed: sd.Compressed,
NumBuckets: int(sd.NumBuckets),
SerdeInfo: serDeHiveToLocal(sd.SerdeInfo),
BucketCols: sd.BucketCols,
SortCols: sortColumnsHiveToLocal(sd.SortCols),
Parameters: sd.Parameters,
SkewedInfo: skewedHiveToLocal(sd.SkewedInfo),
StoredAsSubDirectories: sd.StoredAsSubDirectories,
}
}
func PartitionsLocalToHive(partitions []*metastore.Partition) []*hive_metastore.Partition {
gluePartitions := make([]*hive_metastore.Partition, len(partitions))
for i, partition := range partitions {
gluePartitions[i] = PartitionLocalToHive(partition)
}
return gluePartitions
}