Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-39238:[Go] PATCH Prevents empty record to be appended to empty resultset #39239

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions go/arrow/flight/flightsql/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,10 @@ func readEndpoint(ctx context.Context, client *flightsql.Client, endpoint *fligh
schema := reader.Schema()
var records []arrow.Record
for reader.Next() {
record := reader.Record()
record.Retain()
records = append(records, record)
if record := reader.Record(); record.NumRows() > 0 {
record.Retain()
records = append(records, record)
}
}

if err := reader.Err(); err != nil && !errors.Is(err, io.EOF) {
Expand Down
44 changes: 44 additions & 0 deletions go/arrow/flight/flightsql/driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,50 @@ func (s *SqlTestSuite) TestQuery() {
wg.Wait()
}

func (s *SqlTestSuite) TestQueryWithEmptyResultset() {
t := s.T()

// Create and start the server
server, addr, err := s.createServer()
require.NoError(t, err)

var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
require.NoError(s.T(), s.startServer(server))
}()
defer s.stopServer(server)
time.Sleep(100 * time.Millisecond)

// Configure client
cfg := s.Config
cfg.Address = addr
db, err := sql.Open("flightsql", cfg.DSN())
require.NoError(t, err)
defer db.Close()

// Create the table
_, err = db.Exec(fmt.Sprintf(s.Statements["create table"], s.TableName))
require.NoError(t, err)

rows, err := db.Query(fmt.Sprintf(s.Statements["query"], s.TableName))
require.NoError(t, err)
require.False(t, rows.Next())

row := db.QueryRow(fmt.Sprintf(s.Statements["query"], s.TableName))
require.NotNil(t, row)
require.NoError(t, row.Err())

target := make(map[string]any)
err = row.Scan(&target)
require.ErrorIs(t, err, sql.ErrNoRows)

// Tear-down server
s.stopServer(server)
wg.Wait()
}

func (s *SqlTestSuite) TestPreparedQuery() {
t := s.T()

Expand Down