Skip to content

Commit

Permalink
Extract fetch request logic to separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
mdesmet authored and losipiuk committed Aug 31, 2022
1 parent cc99d59 commit 147fe28
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions trino/trino.go
Original file line number Diff line number Diff line change
Expand Up @@ -1023,29 +1023,9 @@ func (qr *driverRows) fetch(allowEOF bool) error {
}
return nil
}
hs := make(http.Header)
hs.Add(trinoUserHeader, qr.stmt.user)
req, err := qr.stmt.conn.newRequest("GET", qr.nextURI, nil, hs)
if err != nil {
return err
}
resp, err := qr.stmt.conn.roundTrip(qr.ctx, req)
if err != nil {
if qr.ctx.Err() == context.Canceled {
qr.Close()
return err
}
return err
}
defer resp.Body.Close()

var qresp queryResponse
d := json.NewDecoder(resp.Body)
d.UseNumber()
err = d.Decode(&qresp)
if err != nil {
return fmt.Errorf("trino: %v", err)
}
err = handleResponseError(resp.StatusCode, qresp.Error)
err := qr.executeFetchRequest(&qresp)
if err != nil {
return err
}
Expand Down Expand Up @@ -1081,6 +1061,32 @@ func (qr *driverRows) fetch(allowEOF bool) error {
return nil
}

func (qr *driverRows) executeFetchRequest(qresp *queryResponse) error {
hs := make(http.Header)
hs.Add(trinoUserHeader, qr.stmt.user)
req, err := qr.stmt.conn.newRequest("GET", qr.nextURI, nil, hs)
if err != nil {
return err
}
resp, err := qr.stmt.conn.roundTrip(qr.ctx, req)
if err != nil {
if qr.ctx.Err() == context.Canceled {
qr.Close()
return err
}
return err
}
defer resp.Body.Close()

d := json.NewDecoder(resp.Body)
d.UseNumber()
err = d.Decode(&qresp)
if err != nil {
return fmt.Errorf("trino: %v", err)
}
return handleResponseError(resp.StatusCode, qresp.Error)
}

func unmarshalArguments(signature *typeSignature) error {
for i, argument := range signature.Arguments {
var payload interface{}
Expand Down

0 comments on commit 147fe28

Please sign in to comment.