From 9c5198f8a11f029330c396e689e82ee34f8e7e25 Mon Sep 17 00:00:00 2001 From: miguel pragier Date: Fri, 15 Dec 2023 11:10:26 +0100 Subject: [PATCH 1/2] patch out-of-range record scanning --- go/arrow/flight/flightsql/driver/driver.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/go/arrow/flight/flightsql/driver/driver.go b/go/arrow/flight/flightsql/driver/driver.go index e31e572586557..f74bfa378a303 100644 --- a/go/arrow/flight/flightsql/driver/driver.go +++ b/go/arrow/flight/flightsql/driver/driver.go @@ -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) { From 7f4763761d2db7d2b884a406b5fb1ccc6e78b5bb Mon Sep 17 00:00:00 2001 From: miguel pragier Date: Fri, 15 Dec 2023 13:06:30 +0100 Subject: [PATCH 2/2] tests empty resultset --- .../flight/flightsql/driver/driver_test.go | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/go/arrow/flight/flightsql/driver/driver_test.go b/go/arrow/flight/flightsql/driver/driver_test.go index a388bf155ec99..24eb5ee6812c0 100644 --- a/go/arrow/flight/flightsql/driver/driver_test.go +++ b/go/arrow/flight/flightsql/driver/driver_test.go @@ -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()