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

Snowflake fix query re-run #196

Merged
merged 1 commit into from
Sep 16, 2024
Merged
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ cypress/screenshots
testtmp*

# .env
.env.*
.env.*
data
34 changes: 20 additions & 14 deletions src/server/dekart/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ func (s Server) RunQuery(ctx context.Context, req *proto.RunQueryRequest) (*prot
`select
reports.id,
queries.query_source_id,
datasets.connection_id
datasets.connection_id,
queries.query_text
from queries
left join datasets on queries.id = datasets.query_id
left join reports on (datasets.report_id = reports.id or queries.report_id = reports.id)
Expand All @@ -250,8 +251,9 @@ func (s Server) RunQuery(ctx context.Context, req *proto.RunQueryRequest) (*prot
var reportID string
var prevQuerySourceId string
var connectionID sql.NullString
var queryText string
for queriesRows.Next() {
err := queriesRows.Scan(&reportID, &prevQuerySourceId, &connectionID)
err := queriesRows.Scan(&reportID, &prevQuerySourceId, &connectionID, &queryText)
if err != nil {
log.Err(err).Send()
return nil, status.Error(codes.Internal, err.Error())
Expand All @@ -277,7 +279,7 @@ func (s Server) RunQuery(ctx context.Context, req *proto.RunQueryRequest) (*prot
return nil, status.Error(codes.NotFound, err.Error())
}

if !report.CanWrite {
if !(report.CanWrite || report.Discoverable) {
err := fmt.Errorf("permission denied")
log.Warn().Err(err).Send()
return nil, status.Error(codes.PermissionDenied, err.Error())
Expand All @@ -290,23 +292,27 @@ func (s Server) RunQuery(ctx context.Context, req *proto.RunQueryRequest) (*prot
return nil, status.Error(codes.Internal, err.Error())
}

err = s.storeQuerySync(ctx, req.QueryId, req.QueryText, prevQuerySourceId)

if err != nil {
code := codes.Internal
if _, ok := err.(*queryWasNotUpdated); ok {
code = codes.Canceled
log.Warn().Err(err).Send()
} else {
log.Error().Err(err).Send()
if report.CanWrite {
// update query text if it was changed by user if user has write permission
// otherwise use query text from db
queryText = req.QueryText
err = s.storeQuerySync(ctx, req.QueryId, req.QueryText, prevQuerySourceId)
if err != nil {
code := codes.Internal
if _, ok := err.(*queryWasNotUpdated); ok {
code = codes.Canceled
log.Warn().Err(err).Send()
} else {
log.Error().Err(err).Send()
}
return nil, status.Error(code, err.Error())
}
return nil, status.Error(code, err.Error())
}

err = s.runQuery(ctx, runQueryOptions{
reportID: reportID,
queryID: req.QueryId,
queryText: req.QueryText,
queryText: queryText,
connection: connection,
userBucketName: s.getBucketNameFromConnection(connection),
})
Expand Down
1 change: 1 addition & 0 deletions src/server/dekart/querysource.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func (s Server) storeQuerySync(ctx context.Context, queryID string, queryText st
}
affectedRows, _ := result.RowsAffected()
if affectedRows == 0 {
log.Warn().Str("prevQuerySourceId", prevQuerySourceId).Str("newQuerySourceId", newQuerySourceId).Msg("Query text not updated")
return &queryWasNotUpdated{}
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions src/server/dekart/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func (s Server) GetUserStream(req *proto.GetUserStreamRequest, srv proto.Dekart_
for {
select {
case sequence := <-ping:
return s.sendUserStreamResponse(ctx, srv, sequence)
return s.sendUserStreamResponse(srv.Context(), srv, sequence)
case <-ctx.Done():
return nil
}
Expand Down Expand Up @@ -270,7 +270,7 @@ func (s Server) GetReportListStream(req *proto.ReportListRequest, srv proto.Deka
for {
select {
case sequence := <-ping:
return s.sendReportList(ctx, srv, sequence)
return s.sendReportList(srv.Context(), srv, sequence)
case <-ctx.Done():
return nil
}
Expand Down
Loading