Skip to content

Commit

Permalink
kind detector now handles decimal.Decimal
Browse files Browse the repository at this point in the history
  • Loading branch information
neilotoole committed Nov 21, 2023
1 parent f85da72 commit d196df0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libsq/core/kind/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"strings"
"time"

"github.com/shopspring/decimal"

"github.com/neilotoole/sq/libsq/core/errz"
"github.com/neilotoole/sq/libsq/core/stringz"
"github.com/neilotoole/sq/libsq/core/timez"
Expand Down Expand Up @@ -54,6 +56,9 @@ func (d *Detector) Sample(v any) {
case float32, float64:
d.retain(Float, Decimal)
return
case decimal.Decimal:
d.retain(Decimal)
return
case int, int8, int16, int32, int64:
d.retain(Int, Float, Decimal)
return
Expand Down
4 changes: 4 additions & 0 deletions libsq/core/kind/kind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"testing"
"time"

"github.com/shopspring/decimal"

"github.com/stretchr/testify/require"

"github.com/neilotoole/sq/libsq/core/kind"
Expand Down Expand Up @@ -106,6 +108,8 @@ func TestDetector(t *testing.T) {
{in: []any{1, float64(2.0), float32(7.7), int32(3)}, want: kind.Float},
{in: []any{nil, nil, nil}, want: kind.Null},
{in: []any{"1.0", "2.0", "3.0", "4", nil, int64(6)}, want: kind.Decimal},
{in: []any{decimal.New(100, -2)}, want: kind.Decimal},
{in: []any{decimal.New(100, -2), int64(3), float64(1.3)}, want: kind.Decimal},
{in: []any{true, false, nil, "true", "false", "yes", "no", ""}, want: kind.Bool},
{in: []any{"0", "1"}, want: kind.Int},
{in: []any{"0", "1.0"}, want: kind.Decimal},
Expand Down

0 comments on commit d196df0

Please sign in to comment.