From 24b43a21a45c1c9b9208b124bd7efcbf2e698f7b Mon Sep 17 00:00:00 2001 From: beltran Date: Mon, 26 Oct 2020 09:15:11 +0100 Subject: [PATCH] allow to add debug logs --- debug_off.go | 5 +++++ debug_on.go | 5 +++++ hive.go | 23 ++++++++++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 debug_off.go create mode 100644 debug_on.go diff --git a/debug_off.go b/debug_off.go new file mode 100644 index 0000000..7b200a2 --- /dev/null +++ b/debug_off.go @@ -0,0 +1,5 @@ +// +build !gohive_debug + +package gohive + +const gocqlDebug = false diff --git a/debug_on.go b/debug_on.go new file mode 100644 index 0000000..cf0685d --- /dev/null +++ b/debug_on.go @@ -0,0 +1,5 @@ +// +build gohive_debug + +package gohive + +const gocqlDebug = true diff --git a/hive.go b/hive.go index a70f2c1..9d7f223 100644 --- a/hive.go +++ b/hive.go @@ -5,6 +5,7 @@ import ( "crypto/tls" "encoding/base64" "fmt" + "log" "math/rand" "net/http" "net/url" @@ -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() @@ -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 @@ -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 } @@ -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 @@ -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 @@ -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 } @@ -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