Skip to content

Commit 4fd3666

Browse files
committed
fix: handle presto-go-client EOF as successful row iteration
The presto-go-client v1.0.0 returns a *presto.EOF (containing the query ID) from rows.Err() after all rows are successfully consumed. This was incorrectly treated as a real error, causing the presto extractor to fail with the query ID as the error message.
1 parent 264a0e3 commit 4fd3666

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

plugins/extractors/presto/presto.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import (
44
"context"
55
"database/sql"
66
_ "embed"
7+
"errors"
78
"fmt"
89
"net/url"
910
"strings"
1011

11-
_ "github.com/prestodb/presto-go-client/presto" // presto driver
12+
prestoClient "github.com/prestodb/presto-go-client/presto" // presto driver
1213
"github.com/raystack/meteor/models"
1314
v1beta2 "github.com/raystack/meteor/models/raystack/assets/v1beta2"
1415
"github.com/raystack/meteor/plugins"
@@ -158,7 +159,7 @@ func (e *Extractor) getCatalogs(ctx context.Context) ([]string, error) {
158159

159160
catalogs = append(catalogs, catalog)
160161
}
161-
if err := rows.Err(); err != nil {
162+
if err := rows.Err(); err != nil && !isPrestoEOF(err) {
162163
return nil, fmt.Errorf("iterate over catalogs: %w", err)
163164
}
164165

@@ -215,13 +216,20 @@ func (*Extractor) extractColumns(ctx context.Context, db *sql.DB, catalog string
215216
Description: comment.String,
216217
})
217218
}
218-
if err := rows.Err(); err != nil {
219+
if err := rows.Err(); err != nil && !isPrestoEOF(err) {
219220
return nil, fmt.Errorf("iterate over columns: %w", err)
220221
}
221222

222223
return result, nil
223224
}
224225

226+
// isPrestoEOF returns true if err is a *presto.EOF, which the
227+
// presto-go-client returns after all rows have been successfully consumed.
228+
func isPrestoEOF(err error) bool {
229+
var eof *prestoClient.EOF
230+
return errors.As(err, &eof)
231+
}
232+
225233
// isNullable returns true if the string is "YES"
226234
func isNullable(value string) bool {
227235
return value == "YES"

plugins/sqlutil/sqlutils.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@ package sqlutil
33
import (
44
"context"
55
"database/sql"
6+
"errors"
67
"fmt"
78

9+
prestoClient "github.com/prestodb/presto-go-client/presto"
810
log "github.com/raystack/salt/observability/logger"
911
"go.nhat.io/otelsql"
1012
"go.opentelemetry.io/otel/attribute"
1113
)
1214

15+
// isPrestoEOF returns true if the error is a *presto.EOF, which the
16+
// presto-go-client returns after all rows have been successfully consumed.
17+
func isPrestoEOF(err error) bool {
18+
var eof *prestoClient.EOF
19+
return errors.As(err, &eof)
20+
}
21+
1322
func FetchDBs(ctx context.Context, db *sql.DB, logger log.Logger, query string) ([]string, error) {
1423
res, err := db.QueryContext(ctx, query)
1524
if err != nil {
@@ -27,7 +36,7 @@ func FetchDBs(ctx context.Context, db *sql.DB, logger log.Logger, query string)
2736
dbs = append(dbs, database)
2837

2938
}
30-
if err := res.Err(); err != nil {
39+
if err := res.Err(); err != nil && !isPrestoEOF(err) {
3140
return nil, fmt.Errorf("iterate rows: %w", err)
3241
}
3342
return dbs, nil
@@ -49,7 +58,7 @@ func FetchTablesInDB(ctx context.Context, db *sql.DB, dbName, query string) ([]s
4958
}
5059
tbls = append(tbls, table)
5160
}
52-
if err := rows.Err(); err != nil {
61+
if err := rows.Err(); err != nil && !isPrestoEOF(err) {
5362
return nil, fmt.Errorf("iterate rows: %w", err)
5463
}
5564

0 commit comments

Comments
 (0)