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
12 changes: 9 additions & 3 deletions arrow/scalar/scalar.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,16 @@ func (e *Extension) Validate() (err error) {
}

if !e.Valid {
if e.Value != nil {
err = fmt.Errorf("null %s scalar has storage value", e.Type)
if e.Value == nil {
return nil
}
return
if e.Value.IsValid() {
return fmt.Errorf("null %s scalar has non-null storage value", e.Type)
}
if err = e.Value.Validate(); err != nil {
return fmt.Errorf("%s scalar fails validation for storage value: %w", e.Type, err)
}
return nil
}

switch {
Expand Down
18 changes: 18 additions & 0 deletions arrow/scalar/scalar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/apache/arrow-go/v18/arrow/decimal256"
"github.com/apache/arrow-go/v18/arrow/memory"
"github.com/apache/arrow-go/v18/arrow/scalar"
"github.com/apache/arrow-go/v18/internal/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -92,6 +93,23 @@ func checkMakeNullScalar(t *testing.T, dt arrow.DataType) scalar.Scalar {
return s
}

func TestMakeNullExtensionScalar(t *testing.T) {
dt := types.NewSmallintType()
sc := checkMakeNullScalar(t, dt)
ext := sc.(*scalar.Extension)
require.NotNil(t, ext.Value)
assert.False(t, ext.Value.IsValid())
assert.True(t, arrow.TypeEqual(dt.StorageType(), ext.Value.DataType()))
}

func TestNullExtensionScalarValidateRejectsNonNullStorage(t *testing.T) {
sc := scalar.NewExtensionScalar(scalar.NewInt16Scalar(1), types.NewSmallintType())
sc.Valid = false

assert.ErrorContains(t, sc.Validate(), "non-null storage value")
assert.ErrorContains(t, sc.ValidateFull(), "non-null storage value")
}

func TestMakeScalarUint(t *testing.T) {
three := scalar.MakeScalar(uint(3))
assert.NoError(t, three.ValidateFull())
Expand Down
Loading