Skip to content

Commit c8ba88e

Browse files
committed
fix(arreflect): hasViewableType accepts all view/large-list/view-typed variants; add idempotency regression test
1 parent d976f08 commit c8ba88e

3 files changed

Lines changed: 37 additions & 1 deletion

File tree

arrow/array/arreflect/reflect_infer.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@ func applyViewOpts(dt arrow.DataType) arrow.DataType {
284284

285285
func hasViewableType(dt arrow.DataType) bool {
286286
switch dt.ID() {
287-
case arrow.STRING, arrow.BINARY, arrow.LARGE_STRING, arrow.LARGE_BINARY, arrow.LIST:
287+
case arrow.STRING, arrow.BINARY, arrow.LARGE_STRING, arrow.LARGE_BINARY,
288+
arrow.STRING_VIEW, arrow.BINARY_VIEW,
289+
arrow.LIST, arrow.LIST_VIEW, arrow.LARGE_LIST, arrow.LARGE_LIST_VIEW:
288290
return true
289291
case arrow.STRUCT:
290292
st := dt.(*arrow.StructType)

arrow/array/arreflect/reflect_infer_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,4 +851,19 @@ func TestHasViewableType(t *testing.T) {
851851
t.Run("large_binary is true", func(t *testing.T) {
852852
assert.True(t, hasViewableType(arrow.BinaryTypes.LargeBinary))
853853
})
854+
t.Run("string_view is true", func(t *testing.T) {
855+
assert.True(t, hasViewableType(arrow.BinaryTypes.StringView))
856+
})
857+
t.Run("binary_view is true", func(t *testing.T) {
858+
assert.True(t, hasViewableType(arrow.BinaryTypes.BinaryView))
859+
})
860+
t.Run("list_view is true", func(t *testing.T) {
861+
assert.True(t, hasViewableType(arrow.ListViewOf(arrow.PrimitiveTypes.Int64)))
862+
})
863+
t.Run("large_list is true", func(t *testing.T) {
864+
assert.True(t, hasViewableType(arrow.LargeListOf(arrow.PrimitiveTypes.Int64)))
865+
})
866+
t.Run("large_list_view is true", func(t *testing.T) {
867+
assert.True(t, hasViewableType(arrow.LargeListViewOf(arrow.PrimitiveTypes.Int64)))
868+
})
854869
}

arrow/array/arreflect/reflect_public_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,4 +798,23 @@ func TestWithViewRoundTrip(t *testing.T) {
798798
require.Error(t, err)
799799
assert.ErrorIs(t, err, ErrUnsupportedType)
800800
})
801+
802+
t.Run("struct with view-tagged fields via WithView is idempotent", func(t *testing.T) {
803+
// Fields already tagged ,view infer to STRING_VIEW; WithView() should still
804+
// accept the struct and the top-level applyViewOpts walk is a no-op on views.
805+
type Row struct {
806+
Name string `arrow:"name,view"`
807+
Code int32 `arrow:"code"`
808+
}
809+
input := []Row{{"click", 1}, {"view", 2}}
810+
arr, err := FromSlice(input, mem, WithView())
811+
require.NoError(t, err)
812+
defer arr.Release()
813+
sa := arr.(*array.Struct)
814+
assert.Equal(t, arrow.STRING_VIEW, sa.Field(0).DataType().ID())
815+
816+
got, err := ToSlice[Row](arr)
817+
require.NoError(t, err)
818+
assert.Equal(t, input, got)
819+
})
801820
}

0 commit comments

Comments
 (0)