From 69a170b42663484a3cf592b66369625ceb095e15 Mon Sep 17 00:00:00 2001 From: ragrawal Date: Thu, 26 Sep 2019 15:49:51 +0530 Subject: [PATCH 1/3] adding some logging to get the progress of the execution --- conn.go | 5 +++-- rows.go | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/conn.go b/conn.go index 5eb17df..a42e557 100644 --- a/conn.go +++ b/conn.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/athena" "github.com/aws/aws-sdk-go/service/athena/athenaiface" + "github.com/sirupsen/logrus" ) type conn struct { @@ -42,7 +43,7 @@ func (c *conn) runQuery(ctx context.Context, query string) (driver.Rows, error) if err != nil { return nil, err } - + logrus.Infof("executing query : %s :: with queryID : %s ", query, queryID) if err := c.waitOnQuery(ctx, queryID); err != nil { return nil, err } @@ -82,7 +83,7 @@ func (c *conn) waitOnQuery(ctx context.Context, queryID string) error { if err != nil { return err } - + logrus.Infof("queryID : %s :: query status %s ", queryID, *statusResp.QueryExecution.Status) switch *statusResp.QueryExecution.Status.State { case athena.QueryExecutionStateCancelled: return context.Canceled diff --git a/rows.go b/rows.go index f010cb9..3c52ef3 100644 --- a/rows.go +++ b/rows.go @@ -4,6 +4,8 @@ import ( "database/sql/driver" "io" + "github.com/sirupsen/logrus" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/athena" "github.com/aws/aws-sdk-go/service/athena/athenaiface" @@ -107,7 +109,7 @@ func (r *rows) fetchNextPage(token *string) (bool, error) { rowOffset = 1 r.skipHeaderRow = false } - + logrus.Debugf("queryId : %s :: resultset : %v ", r.queryID, r.out.ResultSet) if len(r.out.ResultSet.Rows) < rowOffset+1 { return false, nil } From cae457b40719900548ab90f51b5915b228cb8824 Mon Sep 17 00:00:00 2001 From: raj Date: Fri, 27 Sep 2019 15:17:52 +0530 Subject: [PATCH 2/3] adding a check for succeeded query --- rows.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/rows.go b/rows.go index 3c52ef3..ea96279 100644 --- a/rows.go +++ b/rows.go @@ -2,7 +2,9 @@ package athena import ( "database/sql/driver" + "fmt" "io" + "strings" "github.com/sirupsen/logrus" @@ -11,6 +13,11 @@ import ( "github.com/aws/aws-sdk-go/service/athena/athenaiface" ) +var listOfFailedQueryResult = []string{ + "FAILED:", + "Tables missing on filesystem:", +} + type rows struct { athena athenaiface.AthenaAPI queryID string @@ -110,6 +117,12 @@ func (r *rows) fetchNextPage(token *string) (bool, error) { r.skipHeaderRow = false } logrus.Debugf("queryId : %s :: resultset : %v ", r.queryID, r.out.ResultSet) + + for _, failedSubstring := range listOfFailedQueryResult { + if strings.Contains(r.out.ResultSet.String(), failedSubstring) { + return false, fmt.Errorf("queryId : %s :: failed due to : %v ", r.queryID, r.out.ResultSet.String()) + } + } if len(r.out.ResultSet.Rows) < rowOffset+1 { return false, nil } From 82021d9d9fa8e9ee1f100b9785e2dcc30f98e89b Mon Sep 17 00:00:00 2001 From: raj Date: Mon, 30 Sep 2019 12:02:10 +0530 Subject: [PATCH 3/3] adding a check for failed query execution --- conn.go | 1 + rows.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/conn.go b/conn.go index a42e557..75ad9ce 100644 --- a/conn.go +++ b/conn.go @@ -83,6 +83,7 @@ func (c *conn) waitOnQuery(ctx context.Context, queryID string) error { if err != nil { return err } + logrus.Infof("queryID : %s :: query status %s ", queryID, *statusResp.QueryExecution.Status) switch *statusResp.QueryExecution.Status.State { case athena.QueryExecutionStateCancelled: diff --git a/rows.go b/rows.go index ea96279..3f72f9e 100644 --- a/rows.go +++ b/rows.go @@ -119,7 +119,7 @@ func (r *rows) fetchNextPage(token *string) (bool, error) { logrus.Debugf("queryId : %s :: resultset : %v ", r.queryID, r.out.ResultSet) for _, failedSubstring := range listOfFailedQueryResult { - if strings.Contains(r.out.ResultSet.String(), failedSubstring) { + if len(r.out.ResultSet.Rows) > 0 && strings.Contains(r.out.ResultSet.Rows[0].String(), failedSubstring) { return false, fmt.Errorf("queryId : %s :: failed due to : %v ", r.queryID, r.out.ResultSet.String()) } }