Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func TestQuery(t *testing.T) {
StringType: "some string",
TimestampType: athenaTimestamp(time.Date(2006, 1, 2, 3, 4, 11, 0, time.UTC)),
DateType: athenaDate(time.Date(2006, 1, 2, 0, 0, 0, 0, time.UTC)),
DecimalType: 1001,
},
{
SmallintType: 9,
Expand All @@ -60,6 +61,7 @@ func TestQuery(t *testing.T) {
StringType: "another string",
TimestampType: athenaTimestamp(time.Date(2017, 12, 3, 1, 11, 12, 0, time.UTC)),
DateType: athenaDate(time.Date(2017, 12, 3, 0, 0, 0, 0, time.UTC)),
DecimalType: 0,
},
{
SmallintType: 9,
Expand All @@ -71,9 +73,10 @@ func TestQuery(t *testing.T) {
StringType: "another string",
TimestampType: athenaTimestamp(time.Date(2017, 12, 3, 20, 11, 12, 0, time.UTC)),
DateType: athenaDate(time.Date(2017, 12, 3, 0, 0, 0, 0, time.UTC)),
DecimalType: 0.48,
},
}
expectedTypeNames := []string{"varchar", "smallint", "integer", "bigint", "boolean", "float", "double", "varchar", "timestamp", "date"}
expectedTypeNames := []string{"varchar", "smallint", "integer", "bigint", "boolean", "float", "double", "varchar", "timestamp", "date", "decimal"}
harness.uploadData(expected)

rows := harness.mustQuery("select * from %s", harness.table)
Expand All @@ -94,6 +97,7 @@ func TestQuery(t *testing.T) {
&row.StringType,
&row.TimestampType,
&row.DateType,
&row.DecimalType,
))

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

type athenaHarness struct {
Expand Down Expand Up @@ -169,7 +174,8 @@ func (a *athenaHarness) setupTable() {
doubleType double,
stringType string,
timestampType timestamp,
dateType date
dateType date,
decimalType decimal(11, 5)
)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
WITH SERDEPROPERTIES (
Expand Down
2 changes: 1 addition & 1 deletion value.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func convertValue(athenaType string, rawValue *string) (interface{}, error) {
return nil, fmt.Errorf("cannot parse '%s' as boolean", val)
case "float":
return strconv.ParseFloat(val, 32)
case "double":
case "double", "decimal":
return strconv.ParseFloat(val, 64)
case "varchar", "string":
return val, nil
Expand Down