Skip to content

Commit

Permalink
fix(go/adbc/sqldriver): fix handling of decimal types (#970)
Browse files Browse the repository at this point in the history
Fixes #969.
  • Loading branch information
zeroshade authored Aug 15, 2023
1 parent 7de9038 commit 653683e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions go/adbc/sqldriver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ func isCorrectParamType(typ arrow.Type, val driver.Value) bool {
return checkType[arrow.Time64](val)
case arrow.TIMESTAMP:
return checkType[arrow.Timestamp](val)
case arrow.DECIMAL128:
return checkType[decimal128.Num](val)
case arrow.DECIMAL256:
return checkType[decimal256.Num](val)
}
// TODO: add more types here
return true
Expand Down Expand Up @@ -639,6 +643,10 @@ func (r *rows) Next(dest []driver.Value) error {
dest[i] = col.Value(int(r.curRow)).ToTime(col.DataType().(*arrow.Time64Type).Unit)
case *array.Timestamp:
dest[i] = col.Value(int(r.curRow)).ToTime(col.DataType().(*arrow.TimestampType).Unit)
case *array.Decimal128:
dest[i] = col.Value(int(r.curRow))
case *array.Decimal256:
dest[i] = col.Value(int(r.curRow))
default:
return &adbc.Error{
Code: adbc.StatusNotImplemented,
Expand Down
26 changes: 26 additions & 0 deletions go/adbc/sqldriver/driver_internals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"github.com/apache/arrow-adbc/go/adbc"
"github.com/apache/arrow/go/v13/arrow"
"github.com/apache/arrow/go/v13/arrow/array"
"github.com/apache/arrow/go/v13/arrow/decimal128"
"github.com/apache/arrow/go/v13/arrow/decimal256"
"github.com/apache/arrow/go/v13/arrow/memory"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -111,6 +113,14 @@ func TestColumnTypeDatabaseTypeName(t *testing.T) {
typ: &arrow.DurationType{Unit: arrow.Nanosecond},
typeName: "duration[ns]",
},
{
typ: &arrow.Decimal128Type{Precision: 9, Scale: 2},
typeName: "decimal(9, 2)",
},
{
typ: &arrow.Decimal256Type{Precision: 28, Scale: 4},
typeName: "decimal256(28, 4)",
},
}

for i, test := range tests {
Expand Down Expand Up @@ -227,6 +237,22 @@ func TestNextRowTypes(t *testing.T) {
},
golangValue: time.Date(1970, time.January, 1, testTime.Hour(), testTime.Minute(), testTime.Second(), testTime.Nanosecond(), time.UTC),
},
{
arrowType: &arrow.Decimal128Type{Precision: 9, Scale: 2},
arrowValueFunc: func(t *testing.T, b array.Builder) {
t.Helper()
b.(*array.Decimal128Builder).Append(decimal128.FromU64(10))
},
golangValue: decimal128.FromU64(10),
},
{
arrowType: &arrow.Decimal256Type{Precision: 10, Scale: 5},
arrowValueFunc: func(t *testing.T, b array.Builder) {
t.Helper()
b.(*array.Decimal256Builder).Append(decimal256.FromU64(10))
},
golangValue: decimal256.FromU64(10),
},
}

for i, test := range tests {
Expand Down

0 comments on commit 653683e

Please sign in to comment.