From cb59ab6ef1d2abb20b19cce3ef057cdd289e144f Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Fri, 7 Dec 2018 15:09:58 -0800 Subject: [PATCH] Support the decimal type --- db_test.go | 10 ++++++++-- value.go | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/db_test.go b/db_test.go index 3c9458c..8583810 100644 --- a/db_test.go +++ b/db_test.go @@ -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, @@ -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, @@ -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) @@ -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)) @@ -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 { @@ -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 ( diff --git a/value.go b/value.go index 3b6aeee..077533a 100644 --- a/value.go +++ b/value.go @@ -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