]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/go/arrow/datatype_extension_test.go
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / go / arrow / datatype_extension_test.go
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16
17 package arrow_test
18
19 import (
20 "reflect"
21 "testing"
22
23 "github.com/apache/arrow/go/v6/arrow"
24 "github.com/apache/arrow/go/v6/arrow/internal/testing/types"
25 "github.com/stretchr/testify/assert"
26 "github.com/stretchr/testify/suite"
27 )
28
29 type BadExtensionType struct{}
30
31 func (BadExtensionType) ID() arrow.Type { return arrow.EXTENSION }
32 func (BadExtensionType) ArrayType() reflect.Type { return nil }
33 func (BadExtensionType) Name() string { return "bad" }
34 func (BadExtensionType) StorageType() arrow.DataType { return arrow.Null }
35 func (BadExtensionType) ExtensionEquals(arrow.ExtensionType) bool { return false }
36 func (BadExtensionType) ExtensionName() string { return "bad" }
37 func (BadExtensionType) Serialize() string { return "" }
38 func (BadExtensionType) Deserialize(_ arrow.DataType, _ string) (arrow.ExtensionType, error) {
39 return nil, nil
40 }
41
42 func TestMustEmbedBase(t *testing.T) {
43 var ext interface{} = &BadExtensionType{}
44 assert.Panics(t, func() {
45 var _ arrow.ExtensionType = ext.(arrow.ExtensionType)
46 })
47 }
48
49 type ExtensionTypeTestSuite struct {
50 suite.Suite
51 }
52
53 func (e *ExtensionTypeTestSuite) SetupTest() {
54 e.NoError(arrow.RegisterExtensionType(types.NewUUIDType()))
55 }
56
57 func (e *ExtensionTypeTestSuite) TearDownTest() {
58 if arrow.GetExtensionType("uuid") != nil {
59 e.NoError(arrow.UnregisterExtensionType("uuid"))
60 }
61 }
62
63 func (e *ExtensionTypeTestSuite) TestExtensionType() {
64 e.Nil(arrow.GetExtensionType("uuid-unknown"))
65 e.NotNil(arrow.GetExtensionType("uuid"))
66
67 e.Error(arrow.RegisterExtensionType(types.NewUUIDType()))
68 e.Error(arrow.UnregisterExtensionType("uuid-unknown"))
69
70 typ := types.NewUUIDType()
71 e.Implements((*arrow.ExtensionType)(nil), typ)
72 e.Equal(arrow.EXTENSION, typ.ID())
73 e.Equal("extension", typ.Name())
74
75 serialized := typ.Serialize()
76 deserialized, err := typ.Deserialize(&arrow.FixedSizeBinaryType{ByteWidth: 16}, serialized)
77 e.NoError(err)
78
79 e.True(arrow.TypeEqual(deserialized.StorageType(), &arrow.FixedSizeBinaryType{ByteWidth: 16}))
80 e.True(arrow.TypeEqual(deserialized, typ))
81 e.False(arrow.TypeEqual(deserialized, &arrow.FixedSizeBinaryType{ByteWidth: 16}))
82 }
83
84 func TestExtensionTypes(t *testing.T) {
85 suite.Run(t, new(ExtensionTypeTestSuite))
86 }