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-go.git
The following commit(s) were added to refs/heads/main by this push:
new ea2ff680 fix(arrow/flight/flightsql/driver): convert unsigned, large
and view string/binary values (#1687)
ea2ff680 is described below
commit ea2ff680db33dba5239705044f3acc667525120d
Author: Guillaume Marty <[email protected]>
AuthorDate: Fri Nov 27 17:31:28 2026 +0100
fix(arrow/flight/flightsql/driver): convert unsigned, large and view
string/binary values (#1687)
### Rationale for this change
The `database/sql` driver converts each result value with
`fromArrowType`, and any Arrow type missing from its switch makes
`rows.Next` fail with `type *array.Uint32: not supported`. This happens
for:
- unsigned integers (`uint8`, `uint16`, `uint32`, `uint64`), even though
the driver already accepts Go unsigned integers as query parameters
(`toArrowDataType` / `setFieldValue`), so a value bound as `uint32`
cannot be read back;
- `large_utf8` and `large_binary`, reported in apache/arrow#43403
(closed without a fix; its PR apache/arrow#43402 was withdrawn when ADBC
was suggested as an alternative);
- `string_view` and `binary_view`, which some engines (for example
DataFusion) produce for string columns.
A query that returns any column of these types fails as soon as the
first row is read, so none of the rows can be used, not only that
column.
### What changes are included in this PR?
`fromArrowType` returns the Go value of these arrays, in the same way as
the types it already handles: `uint8`/`uint16`/`uint32`/`uint64` keep
their width (no overflow for values above `math.MaxInt64`), the string
types return `string` and the binary types return `[]byte`, like `utf8`
and `binary`.
### Are these changes tested?
Yes. `TestFromArrowTypeUnsignedAndLargeTypes` converts a value and a
null for each of the eight types. Without the change, every non-null
case fails with `ErrNotSupported`. With the change, they all pass.
Ran locally: `go test ./arrow/flight/flightsql/driver/` (whole package,
including the in-process server tests) and `go vet
./arrow/flight/flightsql/driver/`. I did not run golangci-lint.
### Are there any user-facing changes?
Yes. Results with these column types can now be read through the
`flightsql` `database/sql` driver instead of failing.
This change was written with AI assistance: an AI coding assistant wrote
the code, the test and this description.
---
arrow/flight/flightsql/driver/utils.go | 16 ++++++++++++++
arrow/flight/flightsql/driver/utils_test.go | 34 +++++++++++++++++++++++++++++
2 files changed, 50 insertions(+)
diff --git a/arrow/flight/flightsql/driver/utils.go
b/arrow/flight/flightsql/driver/utils.go
index cb895ea1..4d4fcae8 100644
--- a/arrow/flight/flightsql/driver/utils.go
+++ b/arrow/flight/flightsql/driver/utils.go
@@ -85,10 +85,26 @@ func fromArrowType(arr arrow.Array, idx int) (interface{},
error) {
return c.Value(idx), nil
case *array.Int64:
return c.Value(idx), nil
+ case *array.Uint8:
+ return c.Value(idx), nil
+ case *array.Uint16:
+ return c.Value(idx), nil
+ case *array.Uint32:
+ return c.Value(idx), nil
+ case *array.Uint64:
+ return c.Value(idx), nil
case *array.Binary:
return c.Value(idx), nil
+ case *array.LargeBinary:
+ return c.Value(idx), nil
+ case *array.BinaryView:
+ return c.Value(idx), nil
case *array.String:
return c.Value(idx), nil
+ case *array.LargeString:
+ return c.Value(idx), nil
+ case *array.StringView:
+ return c.Value(idx), nil
case *array.Time32:
d32 := arr.DataType().(*arrow.Time32Type)
v := c.Value(idx)
diff --git a/arrow/flight/flightsql/driver/utils_test.go
b/arrow/flight/flightsql/driver/utils_test.go
index 757aa6c0..6144851d 100644
--- a/arrow/flight/flightsql/driver/utils_test.go
+++ b/arrow/flight/flightsql/driver/utils_test.go
@@ -19,6 +19,7 @@ import (
"fmt"
"math/big"
"reflect"
+ "strings"
"testing"
"time"
@@ -152,3 +153,36 @@ func TestFromArrowTypeReturnsNilForNullDate32(t
*testing.T) {
require.NoError(t, err)
require.Nil(t, got)
}
+
+func TestFromArrowTypeUnsignedAndLargeTypes(t *testing.T) {
+ tests := []struct {
+ typ arrow.DataType
+ json string
+ want any
+ }{
+ {arrow.PrimitiveTypes.Uint8, `[255, null]`, uint8(255)},
+ {arrow.PrimitiveTypes.Uint16, `[65535, null]`, uint16(65535)},
+ {arrow.PrimitiveTypes.Uint32, `[4294967295, null]`,
uint32(4294967295)},
+ {arrow.PrimitiveTypes.Uint64, `[18446744073709551615, null]`,
uint64(18446744073709551615)},
+ {arrow.BinaryTypes.LargeString, `["a", null]`, "a"},
+ {arrow.BinaryTypes.LargeBinary, `["YQ==", null]`, []byte("a")},
+ {arrow.BinaryTypes.StringView, `["a", null]`, "a"},
+ {arrow.BinaryTypes.BinaryView, `["YQ==", null]`, []byte("a")},
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.typ.String(), func(t *testing.T) {
+ arr, _, err := array.FromJSON(memory.DefaultAllocator,
tt.typ, strings.NewReader(tt.json))
+ require.NoError(t, err)
+ defer arr.Release()
+
+ got, err := fromArrowType(arr, 0)
+ require.NoError(t, err)
+ require.Equal(t, tt.want, got)
+
+ got, err = fromArrowType(arr, 1)
+ require.NoError(t, err)
+ require.Nil(t, got)
+ })
+ }
+}