Skip to content

Commit dfa5f18

Browse files
sirwarttejasmanohar
authored andcommitted
Support the decimal type (segmentio#22)
1 parent 38d8239 commit dfa5f18

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

db_test.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func TestQuery(t *testing.T) {
4949
StringType: "some string",
5050
TimestampType: athenaTimestamp(time.Date(2006, 1, 2, 3, 4, 11, 0, time.UTC)),
5151
DateType: athenaDate(time.Date(2006, 1, 2, 0, 0, 0, 0, time.UTC)),
52+
DecimalType: 1001,
5253
},
5354
{
5455
SmallintType: 9,
@@ -60,6 +61,7 @@ func TestQuery(t *testing.T) {
6061
StringType: "another string",
6162
TimestampType: athenaTimestamp(time.Date(2017, 12, 3, 1, 11, 12, 0, time.UTC)),
6263
DateType: athenaDate(time.Date(2017, 12, 3, 0, 0, 0, 0, time.UTC)),
64+
DecimalType: 0,
6365
},
6466
{
6567
SmallintType: 9,
@@ -71,9 +73,10 @@ func TestQuery(t *testing.T) {
7173
StringType: "another string",
7274
TimestampType: athenaTimestamp(time.Date(2017, 12, 3, 20, 11, 12, 0, time.UTC)),
7375
DateType: athenaDate(time.Date(2017, 12, 3, 0, 0, 0, 0, time.UTC)),
76+
DecimalType: 0.48,
7477
},
7578
}
76-
expectedTypeNames := []string{"varchar", "smallint", "integer", "bigint", "boolean", "float", "double", "varchar", "timestamp", "date"}
79+
expectedTypeNames := []string{"varchar", "smallint", "integer", "bigint", "boolean", "float", "double", "varchar", "timestamp", "date", "decimal"}
7780
harness.uploadData(expected)
7881

7982
rows := harness.mustQuery("select * from %s", harness.table)
@@ -94,6 +97,7 @@ func TestQuery(t *testing.T) {
9497
&row.StringType,
9598
&row.TimestampType,
9699
&row.DateType,
100+
&row.DecimalType,
97101
))
98102

99103
assert.Equal(t, expected[index], row, fmt.Sprintf("index: %d", index))
@@ -133,6 +137,7 @@ type dummyRow struct {
133137
StringType string `json:"stringType"`
134138
TimestampType athenaTimestamp `json:"timestampType"`
135139
DateType athenaDate `json:"dateType"`
140+
DecimalType float64 `json:"decimalType"`
136141
}
137142

138143
type athenaHarness struct {
@@ -169,7 +174,8 @@ func (a *athenaHarness) setupTable() {
169174
doubleType double,
170175
stringType string,
171176
timestampType timestamp,
172-
dateType date
177+
dateType date,
178+
decimalType decimal(11, 5)
173179
)
174180
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
175181
WITH SERDEPROPERTIES (

value.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func convertValue(athenaType string, rawValue *string) (interface{}, error) {
5252
return nil, fmt.Errorf("cannot parse '%s' as boolean", val)
5353
case "float":
5454
return strconv.ParseFloat(val, 32)
55-
case "double":
55+
case "double", "decimal":
5656
return strconv.ParseFloat(val, 64)
5757
case "varchar", "string":
5858
return val, nil

0 commit comments

Comments
 (0)