Skip to content

Commit

Permalink
GH-120: Add initial Decimal32/Decimal64 implementation (#121)
Browse files Browse the repository at this point in the history
Fix GH-120

### Rationale for this change
Widening the Decimal128/256 type to allow for bitwidths of 32 and 64
allows for more interoperability with other libraries and utilities
which already support these types. This provides even more opportunities
for zero-copy interactions between things such as libcudf and various
databases.

### What changes are included in this PR?
This PR contains the basic Go implementations for Decimal32/Decimal64
types, arrays, builders and scalars. It also includes the minimum
necessary to get everything compiling and tests passing without also
extending the acero kernels and parquet handling (both of which will be
handled in follow-up PRs).


### Are these changes tested?
Yes, tests were extended where applicable to add decimal32/decimal64
cases.
  • Loading branch information
zeroshade authored Sep 13, 2024
1 parent eaf7703 commit f17963e
Show file tree
Hide file tree
Showing 32 changed files with 2,116 additions and 802 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.

.vscode
/apache-arrow-go.tar.gz
/dev/release/apache-rat-*.jar
/dev/release/filtered_rat.txt
Expand Down
2 changes: 2 additions & 0 deletions arrow/array/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ func init() {
arrow.TIME64: func(data arrow.ArrayData) arrow.Array { return NewTime64Data(data) },
arrow.INTERVAL_MONTHS: func(data arrow.ArrayData) arrow.Array { return NewMonthIntervalData(data) },
arrow.INTERVAL_DAY_TIME: func(data arrow.ArrayData) arrow.Array { return NewDayTimeIntervalData(data) },
arrow.DECIMAL32: func(data arrow.ArrayData) arrow.Array { return NewDecimal32Data(data) },
arrow.DECIMAL64: func(data arrow.ArrayData) arrow.Array { return NewDecimal64Data(data) },
arrow.DECIMAL128: func(data arrow.ArrayData) arrow.Array { return NewDecimal128Data(data) },
arrow.DECIMAL256: func(data arrow.ArrayData) arrow.Array { return NewDecimal256Data(data) },
arrow.LIST: func(data arrow.ArrayData) arrow.Array { return NewListData(data) },
Expand Down
2 changes: 2 additions & 0 deletions arrow/array/array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ func TestMakeFromData(t *testing.T) {
{name: "time64", d: &testDataType{arrow.TIME64}},
{name: "month_interval", d: arrow.FixedWidthTypes.MonthInterval},
{name: "day_time_interval", d: arrow.FixedWidthTypes.DayTimeInterval},
{name: "decimal32", d: &testDataType{arrow.DECIMAL32}},
{name: "decimal64", d: &testDataType{arrow.DECIMAL64}},
{name: "decimal128", d: &testDataType{arrow.DECIMAL128}},
{name: "decimal256", d: &testDataType{arrow.DECIMAL256}},
{name: "month_day_nano_interval", d: arrow.FixedWidthTypes.MonthDayNanoInterval},
Expand Down
8 changes: 8 additions & 0 deletions arrow/array/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,14 @@ func NewBuilder(mem memory.Allocator, dtype arrow.DataType) Builder {
return NewDayTimeIntervalBuilder(mem)
case arrow.INTERVAL_MONTH_DAY_NANO:
return NewMonthDayNanoIntervalBuilder(mem)
case arrow.DECIMAL32:
if typ, ok := dtype.(*arrow.Decimal32Type); ok {
return NewDecimal32Builder(mem, typ)
}
case arrow.DECIMAL64:
if typ, ok := dtype.(*arrow.Decimal64Type); ok {
return NewDecimal64Builder(mem, typ)
}
case arrow.DECIMAL128:
if typ, ok := dtype.(*arrow.Decimal128Type); ok {
return NewDecimal128Builder(mem, typ)
Expand Down
20 changes: 16 additions & 4 deletions arrow/array/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,18 @@ func Equal(left, right arrow.Array) bool {
case *Float64:
r := right.(*Float64)
return arrayEqualFloat64(l, r)
case *Decimal32:
r := right.(*Decimal32)
return arrayEqualDecimal(l, r)
case *Decimal64:
r := right.(*Decimal64)
return arrayEqualDecimal(l, r)
case *Decimal128:
r := right.(*Decimal128)
return arrayEqualDecimal128(l, r)
return arrayEqualDecimal(l, r)
case *Decimal256:
r := right.(*Decimal256)
return arrayEqualDecimal256(l, r)
return arrayEqualDecimal(l, r)
case *Date32:
r := right.(*Date32)
return arrayEqualDate32(l, r)
Expand Down Expand Up @@ -527,12 +533,18 @@ func arrayApproxEqual(left, right arrow.Array, opt equalOption) bool {
case *Float64:
r := right.(*Float64)
return arrayApproxEqualFloat64(l, r, opt)
case *Decimal32:
r := right.(*Decimal32)
return arrayEqualDecimal(l, r)
case *Decimal64:
r := right.(*Decimal64)
return arrayEqualDecimal(l, r)
case *Decimal128:
r := right.(*Decimal128)
return arrayEqualDecimal128(l, r)
return arrayEqualDecimal(l, r)
case *Decimal256:
r := right.(*Decimal256)
return arrayEqualDecimal256(l, r)
return arrayEqualDecimal(l, r)
case *Date32:
r := right.(*Date32)
return arrayEqualDate32(l, r)
Expand Down
Loading

0 comments on commit f17963e

Please sign in to comment.