Skip to content

Commit b9929fa

Browse files
committed
Register EXTENSION types in driver
1 parent 485aab5 commit b9929fa

3 files changed

Lines changed: 30 additions & 41 deletions

File tree

go/adbc/driver/internal/driverbase/database.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ import (
2727
"time"
2828

2929
"github.com/apache/arrow-adbc/go/adbc"
30-
"github.com/apache/arrow-go/v18/arrow"
31-
"github.com/apache/arrow-go/v18/arrow/extensions"
3230
"github.com/apache/arrow-go/v18/arrow/memory"
3331
"go.opentelemetry.io/otel"
3432
"go.opentelemetry.io/otel/attribute"
@@ -81,34 +79,6 @@ var getExporterName = sync.OnceValue(func() string {
8179
return os.Getenv(otelTracesExporter)
8280
})
8381

84-
// registerExtensionTypes ensures that canonical Arrow extension types are registered.
85-
// This is called once during driver initialization to make sure extension types like
86-
// UUID are available for use throughout the driver.
87-
var registerExtensionTypes = sync.OnceFunc(func() {
88-
// The arrow/extensions package automatically registers canonical extension types
89-
// (UUID, Bool8, JSON, Opaque, Variant) in its init() function.
90-
// However, we explicitly ensure registration here in case the package wasn't
91-
// imported elsewhere, and to handle any registration errors gracefully.
92-
93-
// List of canonical extension types to ensure are registered
94-
canonicalTypes := []arrow.ExtensionType{
95-
extensions.NewUUIDType(),
96-
extensions.NewBool8Type(),
97-
&extensions.JSONType{},
98-
&extensions.OpaqueType{},
99-
&extensions.VariantType{},
100-
}
101-
102-
for _, extType := range canonicalTypes {
103-
// RegisterExtensionType is idempotent - it returns an error only if
104-
// a different type with the same name is already registered
105-
if err := arrow.RegisterExtensionType(extType); err != nil {
106-
// Log but don't fail - the type might already be registered
107-
// which is fine (the extensions package init() may have done it)
108-
}
109-
}
110-
})
111-
11282
// DatabaseImpl is an interface that drivers implement to provide
11383
// vendor-specific functionality.
11484
type DatabaseImpl interface {
@@ -146,7 +116,6 @@ type DatabaseImplBase struct {
146116
// driver, allowing the Arrow allocator and error handler to be reused.
147117
func NewDatabaseImplBase(ctx context.Context, driver *DriverImplBase) (DatabaseImplBase, error) {
148118
// Ensure extension types are registered before creating the database
149-
registerExtensionTypes()
150119

151120
database := DatabaseImplBase{
152121
Alloc: driver.Alloc,

go/adbc/driver/internal/driverbase/driver.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ import (
2424
"context"
2525
"runtime/debug"
2626
"strings"
27+
"sync"
2728

2829
"github.com/apache/arrow-adbc/go/adbc"
30+
"github.com/apache/arrow-go/v18/arrow"
31+
"github.com/apache/arrow-go/v18/arrow/extensions"
2932
"github.com/apache/arrow-go/v18/arrow/memory"
3033
)
3134

@@ -34,6 +37,31 @@ var (
3437
infoDriverArrowVersion string
3538
)
3639

40+
// registerExtensionTypes ensures that canonical Arrow extension types are registered.
41+
// This is called once during driver initialization to make sure extension types like
42+
// UUID are available for use throughout the driver.
43+
var RegisterExtensionTypes = sync.OnceFunc(func() {
44+
// The arrow/extensions package automatically registers canonical extension types
45+
// (UUID, Bool8, JSON, Opaque, Variant) in its init() function.
46+
// However, we explicitly ensure registration here in case the package wasn't
47+
// imported elsewhere, and to handle any registration errors gracefully.
48+
49+
// List of canonical extension types to ensure are registered
50+
canonicalTypes := []arrow.ExtensionType{
51+
extensions.NewUUIDType(),
52+
&extensions.VariantType{},
53+
}
54+
55+
for _, extType := range canonicalTypes {
56+
// RegisterExtensionType is idempotent - it returns an error only if
57+
// a different type with the same name is already registered
58+
if err := arrow.RegisterExtensionType(extType); err != nil {
59+
// Log but don't fail - the type might already be registered
60+
// which is fine (the extensions package init() may have done it)
61+
}
62+
}
63+
})
64+
3765
func init() {
3866
if info, ok := debug.ReadBuildInfo(); ok {
3967
for _, s := range info.Settings {
@@ -106,6 +134,8 @@ func NewDriverImplBase(info *DriverInfo, alloc memory.Allocator) DriverImplBase
106134
}
107135
}
108136

137+
RegisterExtensionTypes()
138+
109139
return DriverImplBase{
110140
Alloc: alloc,
111141
ErrorHelper: ErrorHelper{DriverName: info.GetName()},

go/adbc/driver/internal/shared_utils_test.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,6 @@ func TestToXdbcDataType(t *testing.T) {
102102
dataType: extensions.NewOpaqueType(arrow.BinaryTypes.String, "test.opaque", "test_vendor"),
103103
expected: internal.XdbcDataType_XDBC_VARCHAR,
104104
},
105-
{
106-
name: "Bool8 Extension Type",
107-
dataType: extensions.NewBool8Type(),
108-
expected: internal.XdbcDataType_XDBC_TINYINT,
109-
},
110-
{
111-
name: "Bool8 Extension Type",
112-
dataType: extensions.NewJSONType(arrow.BinaryTypes.String),
113-
expected: internal.XdbcDataType_XDBC_TINYINT,
114-
},
115105
}
116106

117107
for _, tt := range tests {

0 commit comments

Comments
 (0)