1
|
|
|
package athena |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"time" |
5
|
|
|
|
6
|
|
|
SDK "github.com/aws/aws-sdk-go-v2/service/athena" |
7
|
|
|
"github.com/evalphobia/aws-sdk-go-v2-wrapper/private/pointers" |
8
|
|
|
) |
9
|
|
|
|
10
|
|
|
type ColumnInfo struct { |
|
|
|
|
11
|
|
|
Name string |
12
|
|
|
Type string |
13
|
|
|
|
14
|
|
|
// optional |
15
|
|
|
CaseSensitive bool |
16
|
|
|
CatalogName string |
17
|
|
|
Label string |
18
|
|
|
Nullable ColumnNullable |
19
|
|
|
Precision int64 |
20
|
|
|
Scale int64 |
21
|
|
|
SchemaName string |
22
|
|
|
TableName string |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
func NewColumnInfoListFromMetadata(o *SDK.ResultSetMetadata) []ColumnInfo { |
|
|
|
|
26
|
|
|
if o == nil { |
27
|
|
|
return nil |
28
|
|
|
} |
29
|
|
|
return NewColumnInfoList(o.ColumnInfo) |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
func NewColumnInfoList(list []SDK.ColumnInfo) []ColumnInfo { |
|
|
|
|
33
|
|
|
if len(list) == 0 { |
34
|
|
|
return nil |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
results := make([]ColumnInfo, len(list)) |
38
|
|
|
for i, v := range list { |
39
|
|
|
results[i] = NewColumnInfo(v) |
40
|
|
|
} |
41
|
|
|
return results |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
func NewColumnInfo(o SDK.ColumnInfo) ColumnInfo { |
|
|
|
|
45
|
|
|
r := ColumnInfo{} |
46
|
|
|
|
47
|
|
|
if o.Name != nil { |
48
|
|
|
r.Name = *o.Name |
49
|
|
|
} |
50
|
|
|
if o.Type != nil { |
51
|
|
|
r.Type = *o.Type |
52
|
|
|
} |
53
|
|
|
if o.CaseSensitive != nil { |
54
|
|
|
r.CaseSensitive = *o.CaseSensitive |
55
|
|
|
} |
56
|
|
|
if o.CatalogName != nil { |
57
|
|
|
r.CatalogName = *o.CatalogName |
58
|
|
|
} |
59
|
|
|
if o.Label != nil { |
60
|
|
|
r.Label = *o.Label |
61
|
|
|
} |
62
|
|
|
if o.Precision != nil { |
63
|
|
|
r.Precision = *o.Precision |
64
|
|
|
} |
65
|
|
|
if o.Scale != nil { |
66
|
|
|
r.Scale = *o.Scale |
67
|
|
|
} |
68
|
|
|
if o.SchemaName != nil { |
69
|
|
|
r.SchemaName = *o.SchemaName |
70
|
|
|
} |
71
|
|
|
if o.TableName != nil { |
72
|
|
|
r.TableName = *o.TableName |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
r.Nullable = ColumnNullable(o.Nullable) |
76
|
|
|
return r |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
type Datum struct { |
|
|
|
|
80
|
|
|
VarCharValue string |
81
|
|
|
|
82
|
|
|
HasValue bool |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
func NewDatumList(list []SDK.Datum) []Datum { |
|
|
|
|
86
|
|
|
if len(list) == 0 { |
87
|
|
|
return nil |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
results := make([]Datum, len(list)) |
91
|
|
|
for i, v := range list { |
92
|
|
|
results[i] = NewDatum(v) |
93
|
|
|
} |
94
|
|
|
return results |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
func NewDatum(o SDK.Datum) Datum { |
|
|
|
|
98
|
|
|
r := Datum{} |
99
|
|
|
if o.VarCharValue != nil { |
100
|
|
|
r.VarCharValue = *o.VarCharValue |
101
|
|
|
r.HasValue = true |
102
|
|
|
} |
103
|
|
|
return r |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
type QueryExecutionContext struct { |
|
|
|
|
107
|
|
|
Catalog string |
108
|
|
|
Database string |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
func NewQueryExecutionContext(o *SDK.QueryExecutionContext) QueryExecutionContext { |
|
|
|
|
112
|
|
|
r := QueryExecutionContext{} |
113
|
|
|
if o == nil { |
114
|
|
|
return r |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
if o.Catalog != nil { |
118
|
|
|
r.Catalog = *o.Catalog |
119
|
|
|
} |
120
|
|
|
if o.Database != nil { |
121
|
|
|
r.Database = *o.Database |
122
|
|
|
} |
123
|
|
|
return r |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
func (v QueryExecutionContext) ToSDK() *SDK.QueryExecutionContext { |
|
|
|
|
127
|
|
|
switch { |
128
|
|
|
case v.Catalog != "", |
129
|
|
|
v.Database != "": |
130
|
|
|
default: |
131
|
|
|
return nil |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
o := SDK.QueryExecutionContext{} |
135
|
|
|
if v.Catalog != "" { |
136
|
|
|
o.Catalog = pointers.String(v.Catalog) |
137
|
|
|
} |
138
|
|
|
if v.Database != "" { |
139
|
|
|
o.Database = pointers.String(v.Database) |
140
|
|
|
} |
141
|
|
|
return &o |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
type QueryExecutionStatistics struct { |
|
|
|
|
145
|
|
|
DataManifestLocation string |
146
|
|
|
DataScannedInBytes int64 |
147
|
|
|
EngineExecutionTimeInMillis int64 |
148
|
|
|
QueryPlanningTimeInMillis int64 |
149
|
|
|
QueryQueueTimeInMillis int64 |
150
|
|
|
ServiceProcessingTimeInMillis int64 |
151
|
|
|
TotalExecutionTimeInMillis int64 |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
func NewQueryExecutionStatistics(o *SDK.QueryExecutionStatistics) QueryExecutionStatistics { |
|
|
|
|
155
|
|
|
r := QueryExecutionStatistics{} |
156
|
|
|
if o == nil { |
157
|
|
|
return r |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
if o.DataManifestLocation != nil { |
161
|
|
|
r.DataManifestLocation = *o.DataManifestLocation |
162
|
|
|
} |
163
|
|
|
if o.DataScannedInBytes != nil { |
164
|
|
|
r.DataScannedInBytes = *o.DataScannedInBytes |
165
|
|
|
} |
166
|
|
|
if o.EngineExecutionTimeInMillis != nil { |
167
|
|
|
r.EngineExecutionTimeInMillis = *o.EngineExecutionTimeInMillis |
168
|
|
|
} |
169
|
|
|
if o.QueryPlanningTimeInMillis != nil { |
170
|
|
|
r.QueryPlanningTimeInMillis = *o.QueryPlanningTimeInMillis |
171
|
|
|
} |
172
|
|
|
if o.QueryQueueTimeInMillis != nil { |
173
|
|
|
r.QueryQueueTimeInMillis = *o.QueryQueueTimeInMillis |
174
|
|
|
} |
175
|
|
|
if o.ServiceProcessingTimeInMillis != nil { |
176
|
|
|
r.ServiceProcessingTimeInMillis = *o.ServiceProcessingTimeInMillis |
177
|
|
|
} |
178
|
|
|
if o.TotalExecutionTimeInMillis != nil { |
179
|
|
|
r.TotalExecutionTimeInMillis = *o.TotalExecutionTimeInMillis |
180
|
|
|
} |
181
|
|
|
return r |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
type QueryExecutionStatus struct { |
|
|
|
|
185
|
|
|
CompletionDateTime time.Time |
186
|
|
|
State QueryExecutionState |
187
|
|
|
StateChangeReason string |
188
|
|
|
SubmissionDateTime time.Time |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
func NewQueryExecutionStatus(o *SDK.QueryExecutionStatus) QueryExecutionStatus { |
|
|
|
|
192
|
|
|
r := QueryExecutionStatus{} |
193
|
|
|
if o == nil { |
194
|
|
|
return r |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
if o.CompletionDateTime != nil { |
198
|
|
|
r.CompletionDateTime = *o.CompletionDateTime |
199
|
|
|
} |
200
|
|
|
if o.StateChangeReason != nil { |
201
|
|
|
r.StateChangeReason = *o.StateChangeReason |
202
|
|
|
} |
203
|
|
|
if o.SubmissionDateTime != nil { |
204
|
|
|
r.SubmissionDateTime = *o.SubmissionDateTime |
205
|
|
|
} |
206
|
|
|
r.State = QueryExecutionState(o.State) |
207
|
|
|
return r |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
type ResultConfiguration struct { |
|
|
|
|
211
|
|
|
OutputLocation string |
212
|
|
|
EncryptionKMSKey string |
213
|
|
|
EncryptionOption EncryptionOption |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
func NewResultConfiguration(o *SDK.ResultConfiguration) ResultConfiguration { |
|
|
|
|
217
|
|
|
r := ResultConfiguration{} |
218
|
|
|
if o == nil { |
219
|
|
|
return r |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
if o.OutputLocation != nil { |
223
|
|
|
r.OutputLocation = *o.OutputLocation |
224
|
|
|
} |
225
|
|
|
if v := o.EncryptionConfiguration; v != nil { |
226
|
|
|
r.EncryptionOption = EncryptionOption(v.EncryptionOption) |
227
|
|
|
if v.KmsKey != nil { |
228
|
|
|
r.EncryptionKMSKey = *v.KmsKey |
229
|
|
|
} |
230
|
|
|
} |
231
|
|
|
return r |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
func (v ResultConfiguration) ToSDK() *SDK.ResultConfiguration { |
|
|
|
|
235
|
|
|
switch { |
236
|
|
|
case v.OutputLocation != "", |
237
|
|
|
v.EncryptionKMSKey != "", |
238
|
|
|
v.EncryptionOption != "": |
239
|
|
|
default: |
240
|
|
|
return nil |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
o := SDK.ResultConfiguration{} |
244
|
|
|
|
245
|
|
|
if v.OutputLocation != "" { |
246
|
|
|
o.OutputLocation = pointers.String(v.OutputLocation) |
247
|
|
|
} |
248
|
|
|
switch { |
249
|
|
|
case v.EncryptionKMSKey != "", |
250
|
|
|
v.EncryptionOption != "": |
251
|
|
|
vv := SDK.EncryptionConfiguration{} |
252
|
|
|
vv.EncryptionOption = SDK.EncryptionOption(v.EncryptionOption) |
253
|
|
|
if v.EncryptionKMSKey != "" { |
254
|
|
|
vv.KmsKey = pointers.String(v.EncryptionKMSKey) |
255
|
|
|
} |
256
|
|
|
o.EncryptionConfiguration = &vv |
257
|
|
|
} |
258
|
|
|
return &o |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
type ResultSet struct { |
|
|
|
|
262
|
|
|
ColumnInfo []ColumnInfo |
263
|
|
|
Rows []Row |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
func NewResultSet(o *SDK.ResultSet) ResultSet { |
|
|
|
|
267
|
|
|
r := ResultSet{} |
268
|
|
|
if o == nil { |
269
|
|
|
return r |
270
|
|
|
} |
271
|
|
|
r.ColumnInfo = NewColumnInfoListFromMetadata(o.ResultSetMetadata) |
272
|
|
|
r.Rows = NewRowList(o.Rows) |
273
|
|
|
return r |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
func (r ResultSet) ToMapString() []map[string]string { |
|
|
|
|
277
|
|
|
if len(r.Rows) < 2 { |
278
|
|
|
return nil |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
results := make([]map[string]string, len(r.Rows)-1) |
282
|
|
|
hd := r.Rows[0].Data |
283
|
|
|
header := make([]string, len(hd)) |
284
|
|
|
for i, v := range hd { |
285
|
|
|
header[i] = v.VarCharValue |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
for i, row := range r.Rows[1:] { |
289
|
|
|
m := make(map[string]string, len(row.Data)) |
290
|
|
|
for j, v := range row.Data { |
291
|
|
|
m[header[j]] = v.VarCharValue |
292
|
|
|
} |
293
|
|
|
results[i] = m |
294
|
|
|
} |
295
|
|
|
return results |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
func (r ResultSet) ToListString() [][]string { |
|
|
|
|
299
|
|
|
if len(r.Rows) < 2 { |
300
|
|
|
return nil |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
results := make([][]string, len(r.Rows)) |
304
|
|
|
for i, row := range r.Rows { |
305
|
|
|
rr := make([]string, len(r.Rows)) |
306
|
|
|
for j, v := range row.Data { |
307
|
|
|
rr[j] = v.VarCharValue |
308
|
|
|
} |
309
|
|
|
results[i] = rr |
310
|
|
|
} |
311
|
|
|
return results |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
type Row struct { |
|
|
|
|
315
|
|
|
Data []Datum |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
func NewRowList(list []SDK.Row) []Row { |
|
|
|
|
319
|
|
|
if len(list) == 0 { |
320
|
|
|
return nil |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
results := make([]Row, len(list)) |
324
|
|
|
for i, v := range list { |
325
|
|
|
results[i] = NewRow(v) |
326
|
|
|
} |
327
|
|
|
return results |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
func NewRow(o SDK.Row) Row { |
|
|
|
|
331
|
|
|
r := Row{} |
332
|
|
|
r.Data = NewDatumList(o.Data) |
333
|
|
|
return r |
334
|
|
|
} |
335
|
|
|
|