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

PIPE-1439 adding logging and error check for failed query. #2

Open
wants to merge 3 commits 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
4 changes: 3 additions & 1 deletion conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -83,6 +84,7 @@ func (c *conn) waitOnQuery(ctx context.Context, queryID string) error {
return err
}

logrus.Infof("queryID : %s :: query status %s ", queryID, *statusResp.QueryExecution.Status)
switch *statusResp.QueryExecution.Status.State {
case athena.QueryExecutionStateCancelled:
return context.Canceled
Expand Down
15 changes: 15 additions & 0 deletions rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@ package athena

import (
"database/sql/driver"
"fmt"
"io"
"strings"

"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"
)

var listOfFailedQueryResult = []string{
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taken a route of matching an error string with resultset. This may not be an exhaustive list, we can keep on adding to this list for the resultset which we think is an error.

"FAILED:",
"Tables missing on filesystem:",
}

type rows struct {
athena athenaiface.AthenaAPI
queryID string
Expand Down Expand Up @@ -107,7 +116,13 @@ func (r *rows) fetchNextPage(token *string) (bool, error) {
rowOffset = 1
r.skipHeaderRow = false
}
logrus.Debugf("queryId : %s :: resultset : %v ", r.queryID, r.out.ResultSet)

for _, failedSubstring := range listOfFailedQueryResult {
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())
}
}
if len(r.out.ResultSet.Rows) < rowOffset+1 {
return false, nil
}
Expand Down