This is an automated email from the ASF dual-hosted git repository.
zeroshade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-adbc.git
The following commit(s) were added to refs/heads/main by this push:
new 854d31e26 feat(go/adbc/sqldriver): read from union types (#2637)
854d31e26 is described below
commit 854d31e267bd9b4c577462acf7d3b8a11bae87a1
Author: Marin Nozhchev <[email protected]>
AuthorDate: Mon Apr 7 17:54:36 2025 +0300
feat(go/adbc/sqldriver): read from union types (#2637)
Implements reading from union types and adds a unit test. All tests
pass, except those with C shared object dependencies. I did not build
the code outside go/adbc - let me know if needed for this PR.
In addition to the added unit test, I tested the scenario from the issue
with DuckDB.
Closes #2636
---
go/adbc/sqldriver/driver.go | 4 ++-
go/adbc/sqldriver/driver_internals_test.go | 54 ++++++++++++++++++++++++++++--
2 files changed, 55 insertions(+), 3 deletions(-)
diff --git a/go/adbc/sqldriver/driver.go b/go/adbc/sqldriver/driver.go
index 878abe42f..1ba505296 100644
--- a/go/adbc/sqldriver/driver.go
+++ b/go/adbc/sqldriver/driver.go
@@ -606,7 +606,9 @@ func (r *rows) Next(dest []driver.Value) error {
dest[i] = nil
continue
}
-
+ if colUnion, ok := col.(array.Union); ok {
+ col = colUnion.Field(colUnion.ChildID(int(r.curRow)))
+ }
switch col := col.(type) {
case *array.Boolean:
dest[i] = col.Value(int(r.curRow))
diff --git a/go/adbc/sqldriver/driver_internals_test.go
b/go/adbc/sqldriver/driver_internals_test.go
index 1da956c77..539d55735 100644
--- a/go/adbc/sqldriver/driver_internals_test.go
+++ b/go/adbc/sqldriver/driver_internals_test.go
@@ -136,8 +136,16 @@ func TestColumnTypeDatabaseTypeName(t *testing.T) {
}
var (
- tz = time.FixedZone("North Idaho", -int((8 *
time.Hour).Seconds()))
- testTime = time.Date(2023, time.January, 26, 15, 40, 39, 123456789, tz)
+ tz = time.FixedZone("North Idaho", -int((8 *
time.Hour).Seconds()))
+ testTime = time.Date(2023, time.January, 26, 15, 40, 39, 123456789,
tz)
+ stringField = arrow.Field{
+ Name: "str",
+ Type: arrow.BinaryTypes.String,
+ }
+ int32Field = arrow.Field{
+ Name: "int",
+ Type: arrow.PrimitiveTypes.Int32,
+ }
)
func TestNextRowTypes(t *testing.T) {
@@ -254,6 +262,48 @@ func TestNextRowTypes(t *testing.T) {
},
golangValue: decimal256.FromU64(10),
},
+ {
+ arrowType:
arrow.SparseUnionOf([]arrow.Field{stringField, int32Field},
[]arrow.UnionTypeCode{0, 1}),
+ arrowValueFunc: func(t *testing.T, b array.Builder) {
+ t.Helper()
+ ub := b.(array.UnionBuilder)
+ ub.Append(0)
+
ub.Child(0).(*array.StringBuilder).Append("my-string")
+ ub.Child(1).AppendEmptyValue()
+ },
+ golangValue: "my-string",
+ },
+ {
+ arrowType:
arrow.SparseUnionOf([]arrow.Field{stringField, int32Field},
[]arrow.UnionTypeCode{0, 1}),
+ arrowValueFunc: func(t *testing.T, b array.Builder) {
+ t.Helper()
+ ub := b.(array.UnionBuilder)
+ ub.Append(1)
+ ub.Child(1).(*array.Int32Builder).Append(100)
+ ub.Child(0).AppendEmptyValue()
+
+ },
+ golangValue: int32(100),
+ },
+ {
+ arrowType: arrow.DenseUnionOf([]arrow.Field{int32Field,
stringField}, []arrow.UnionTypeCode{10, 20}),
+ arrowValueFunc: func(t *testing.T, b array.Builder) {
+ t.Helper()
+ ub := b.(array.UnionBuilder)
+ ub.Append(20)
+
ub.Child(1).(*array.StringBuilder).Append("my-string")
+ },
+ golangValue: "my-string",
+ },
+ {
+ arrowType: arrow.DenseUnionOf([]arrow.Field{int32Field,
stringField}, []arrow.UnionTypeCode{10, 20}),
+ arrowValueFunc: func(t *testing.T, b array.Builder) {
+ t.Helper()
+ b.(array.UnionBuilder).Append(10)
+
b.(array.UnionBuilder).Child(0).(*array.Int32Builder).Append(100)
+ },
+ golangValue: int32(100),
+ },
}
for i, test := range tests {