forked from speee/go-athena
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalue_test.go
134 lines (127 loc) · 2.78 KB
/
value_test.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
package athena
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestConvertValue(t *testing.T) {
toPtr := func(s string) *string {
return &s
}
tests := map[string]struct {
athenaType string
rawValue *string
want any
}{
"null": {
athenaType: "integer",
rawValue: nil,
want: nil,
},
"tinyint": {
athenaType: "tinyint",
rawValue: toPtr("123"),
want: int64(123),
},
"smallint": {
athenaType: "smallint",
rawValue: toPtr("123"),
want: int64(123),
},
"integer": {
athenaType: "integer",
rawValue: toPtr("2147483647"),
want: int64(2147483647),
},
"bigint": {
athenaType: "bigint",
rawValue: toPtr("9223372036854775807"),
want: int64(9223372036854775807),
},
"boolean true": {
athenaType: "boolean",
rawValue: toPtr("true"),
want: true,
},
"boolean false": {
athenaType: "boolean",
rawValue: toPtr("false"),
want: false,
},
"float": {
athenaType: "float",
rawValue: toPtr("1.75"),
want: float64(1.75),
},
"double": {
athenaType: "double",
rawValue: toPtr("1.75"),
want: float64(1.75),
},
"decimal": {
athenaType: "decimal",
rawValue: toPtr("123.45"),
want: float64(123.45),
},
"varchar": {
athenaType: "varchar",
rawValue: toPtr("hello world"),
want: "hello world",
},
"timestamp": {
athenaType: "timestamp",
rawValue: toPtr("2023-01-15 12:34:56.789"),
want: "2023-01-15 12:34:56.789",
},
"timestamp with time zone": {
athenaType: "timestamp with time zone",
rawValue: toPtr("2023-01-15 12:34:56.789 JST"),
want: "2023-01-15 12:34:56.789 JST",
},
"date": {
athenaType: "date",
rawValue: toPtr("2023-01-15"),
want: "2023-01-15",
},
"time": {
athenaType: "time",
rawValue: toPtr("12:34:56"),
want: "12:34:56",
},
"time with time zone": {
athenaType: "time with time zone",
rawValue: toPtr("12:34:56 JST"),
want: "12:34:56 JST",
},
"array": {
athenaType: "array",
rawValue: toPtr("[one, two, three]"),
want: "[one, two, three]",
},
"map": {
athenaType: "map",
rawValue: toPtr("{one=1, two=2, three=3}"),
want: "{one=1, two=2, three=3}",
},
"row": {
athenaType: "row",
rawValue: toPtr("{one, two, three}"),
want: "{one, two, three}",
},
"unknown type": {
athenaType: "unknown",
rawValue: toPtr("unknown"),
want: []byte("unknown"),
},
}
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
t.Parallel()
got, err := convertValue(tc.athenaType, tc.rawValue)
if err != nil {
t.Errorf("unexpected error: %v", err)
return
}
assert.Equal(t, got, tc.want)
})
}
}