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

allow to add debug logs #122

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions debug_off.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// +build !gohive_debug

package gohive

const gocqlDebug = false
5 changes: 5 additions & 0 deletions debug_on.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// +build gohive_debug

package gohive

const gocqlDebug = true
23 changes: 22 additions & 1 deletion hive.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/tls"
"encoding/base64"
"fmt"
"log"
"math/rand"
"net/http"
"net/url"
Expand Down Expand Up @@ -336,6 +337,9 @@ func (c *Connection) Close() error {
closeRequest.SessionHandle = c.sessionHandle
// This context is ignored
responseClose, err := c.client.CloseSession(context.Background(), closeRequest)
if gocqlDebug {
log.Println(responseClose)
}

if c.transport != nil {
errTransport := c.transport.Close()
Expand Down Expand Up @@ -485,7 +489,9 @@ func (c *Cursor) executeAsync(ctx context.Context, query string) {
var responseExecute *hiveserver.TExecuteStatementResp

responseExecute, c.Err = c.conn.client.ExecuteStatement(ctx, executeReq)

if gocqlDebug {
log.Println(responseExecute)
}
if c.Err != nil {
if strings.Contains(c.Err.Error(), "context deadline exceeded") {
c.state = _CONTEXT_DONE
Expand Down Expand Up @@ -519,6 +525,9 @@ func (c *Cursor) Poll(getProgres bool) (status *hiveserver.TGetOperationStatusRe
var responsePoll *hiveserver.TGetOperationStatusResp
// Context ignored
responsePoll, c.Err = c.conn.client.GetOperationStatus(context.Background(), pollRequest)
if gocqlDebug {
log.Println(responsePoll)
}
if c.Err != nil {
return nil
}
Expand Down Expand Up @@ -877,6 +886,9 @@ func (c *Cursor) Description() [][]string {
metaRequest := hiveserver.NewTGetResultSetMetadataReq()
metaRequest.OperationHandle = c.operationHandle
metaResponse, err := c.conn.client.GetResultSetMetadata(context.Background(), metaRequest)
if gocqlDebug {
log.Println(metaResponse)
}
if err != nil {
c.Err = err
return nil
Expand Down Expand Up @@ -935,6 +947,9 @@ func (c *Cursor) pollUntilData(ctx context.Context, n int) (err error) {
fetchRequest.Orientation = hiveserver.TFetchOrientation_FETCH_NEXT
fetchRequest.MaxRows = c.conn.configuration.FetchSize
responseFetch, err := c.conn.client.FetchResults(context.Background(), fetchRequest)
if gocqlDebug {
log.Println(responseFetch)
}
if err != nil {
rowsAvailable <- err
return
Expand Down Expand Up @@ -990,6 +1005,9 @@ func (c *Cursor) Cancel() {
var responseCancel *hiveserver.TCancelOperationResp
// This context is simply ignored
responseCancel, c.Err = c.conn.client.CancelOperation(context.Background(), cancelRequest)
if gocqlDebug {
log.Println(responseCancel)
}
if c.Err != nil {
return
}
Expand Down Expand Up @@ -1018,6 +1036,9 @@ func (c *Cursor) resetState() error {
closeRequest.OperationHandle = c.operationHandle
// This context is ignored
responseClose, err := c.conn.client.CloseOperation(context.Background(), closeRequest)
if gocqlDebug {
log.Println(responseClose)
}
c.operationHandle = nil
if err != nil {
return err
Expand Down