Skip to content

Commit 9dfce88

Browse files
andy-trimbletejasmanohar
authored andcommitted
Adding support for 'float' datatype (#9)
* Adding support for 'float' datatype * Added float type to tests
1 parent c702346 commit 9dfce88

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

db_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func TestQuery(t *testing.T) {
4444
IntType: 2,
4545
BigintType: 3,
4646
BooleanType: true,
47+
FloatType: 3.14159,
4748
DoubleType: 1.32112345,
4849
StringType: "some string",
4950
TimestampType: athenaTimestamp(time.Date(2006, 1, 2, 3, 4, 11, 0, time.UTC)),
@@ -53,6 +54,7 @@ func TestQuery(t *testing.T) {
5354
IntType: 8,
5455
BigintType: 0,
5556
BooleanType: false,
57+
FloatType: 3.14159,
5658
DoubleType: 1.235,
5759
StringType: "another string",
5860
TimestampType: athenaTimestamp(time.Date(2017, 12, 3, 1, 11, 12, 0, time.UTC)),
@@ -63,11 +65,12 @@ func TestQuery(t *testing.T) {
6365
BigintType: 0,
6466
BooleanType: false,
6567
DoubleType: 1.235,
68+
FloatType: 3.14159,
6669
StringType: "another string",
6770
TimestampType: athenaTimestamp(time.Date(2017, 12, 3, 20, 11, 12, 0, time.UTC)),
6871
},
6972
}
70-
expectedTypeNames := []string{"varchar", "smallint", "integer", "bigint", "boolean", "double", "varchar", "timestamp"}
73+
expectedTypeNames := []string{"varchar", "smallint", "integer", "bigint", "boolean", "float", "double", "varchar", "timestamp"}
7174
harness.uploadData(expected)
7275

7376
rows := harness.mustQuery("select * from %s", harness.table)
@@ -83,6 +86,7 @@ func TestQuery(t *testing.T) {
8386
&row.IntType,
8487
&row.BigintType,
8588
&row.BooleanType,
89+
&row.FloatType,
8690
&row.DoubleType,
8791
&row.StringType,
8892
&row.TimestampType,
@@ -120,6 +124,7 @@ type dummyRow struct {
120124
IntType int `json:"intType"`
121125
BigintType int `json:"bigintType"`
122126
BooleanType bool `json:"booleanType"`
127+
FloatType float32 `json:"floatType"`
123128
DoubleType float64 `json:"doubleType"`
124129
StringType string `json:"stringType"`
125130
TimestampType athenaTimestamp `json:"timestampType"`
@@ -147,13 +152,15 @@ func setup(t *testing.T) *athenaHarness {
147152

148153
func (a *athenaHarness) setupTable() {
149154
// tables cannot start with numbers or contain dashes
150-
a.table = "t_" + strings.Replace(uuid.NewV4().String(), "-", "_", -1)
155+
id, _ := uuid.NewV4()
156+
a.table = "t_" + strings.Replace(id.String(), "-", "_", -1)
151157
a.mustExec(`CREATE EXTERNAL TABLE %[1]s (
152158
nullValue string,
153159
smallintType smallint,
154160
intType int,
155161
bigintType bigint,
156162
booleanType boolean,
163+
floatType float,
157164
doubleType double,
158165
stringType string,
159166
timestampType timestamp

value.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ func convertValue(athenaType string, rawValue *string) (interface{}, error) {
4848
return false, nil
4949
}
5050
return nil, fmt.Errorf("cannot parse '%s' as boolean", val)
51+
case "float":
52+
return strconv.ParseFloat(val, 32)
5153
case "double":
5254
return strconv.ParseFloat(val, 64)
5355
case "varchar", "string":

0 commit comments

Comments
 (0)