diff --git a/lib/events/athena/querier.go b/lib/events/athena/querier.go index fc134cf58d51f..0518388cd7fe0 100644 --- a/lib/events/athena/querier.go +++ b/lib/events/athena/querier.go @@ -304,7 +304,10 @@ func prepareQuery(params searchParams) (query string, execParams []string) { qb.Append(` ORDER BY event_time DESC, uid DESC`) } - qb.Append(` LIMIT ?`, strconv.Itoa(params.limit)) + // Athena engine v2 supports ? placeholders only in Where part. + // To be compatible with v2, limit value is added as part of query. + // It's safe because it was already validated and it's just int. + qb.Append(` LIMIT ` + strconv.Itoa(params.limit) + `;`) return qb.String(), qb.Args() } @@ -361,11 +364,11 @@ func (q *querier) waitForSuccess(ctx context.Context, queryId string) error { case athenaTypes.QueryExecutionStateSucceeded: return nil case athenaTypes.QueryExecutionStateCancelled, athenaTypes.QueryExecutionStateFailed: - return trace.Errorf("got unexpected state: %s", state) + return trace.Errorf("got unexpected state: %s from queryID: %s", state, queryId) case athenaTypes.QueryExecutionStateQueued, athenaTypes.QueryExecutionStateRunning: continue default: - return trace.Errorf("got unknown state: %s", state) + return trace.Errorf("got unknown state: %s from queryID: %s", state, queryId) } } } diff --git a/lib/events/athena/querier_test.go b/lib/events/athena/querier_test.go index 82e42e9b4ed45..5ddedc7c17af1 100644 --- a/lib/events/athena/querier_test.go +++ b/lib/events/athena/querier_test.go @@ -68,8 +68,8 @@ func Test_querier_prepareQuery(t *testing.T) { tablename: tablename, }, wantQuery: selectFromPrefix + whereTimeRange + - ` ORDER BY event_time ASC, uid ASC LIMIT ?`, - wantParams: append(timeRangeParams, "100"), + ` ORDER BY event_time ASC, uid ASC LIMIT 100;`, + wantParams: timeRangeParams, }, { name: "query on time range order DESC", @@ -81,8 +81,8 @@ func Test_querier_prepareQuery(t *testing.T) { tablename: tablename, }, wantQuery: selectFromPrefix + whereTimeRange + - ` ORDER BY event_time DESC, uid DESC LIMIT ?`, - wantParams: append(timeRangeParams, "100"), + ` ORDER BY event_time DESC, uid DESC LIMIT 100;`, + wantParams: timeRangeParams, }, { name: "query with event types", @@ -94,8 +94,8 @@ func Test_querier_prepareQuery(t *testing.T) { tablename: tablename, }, wantQuery: selectFromPrefix + whereTimeRange + - ` AND event_type IN (?,?) ORDER BY event_time ASC, uid ASC LIMIT ?`, - wantParams: append(timeRangeParams, "'app.create'", "'app.delete'", "100"), + ` AND event_type IN (?,?) ORDER BY event_time ASC, uid ASC LIMIT 100;`, + wantParams: append(timeRangeParams, "'app.create'", "'app.delete'"), }, { name: "session id", @@ -107,8 +107,8 @@ func Test_querier_prepareQuery(t *testing.T) { tablename: tablename, }, wantQuery: selectFromPrefix + whereTimeRange + - ` AND session_id = ? ORDER BY event_time ASC, uid ASC LIMIT ?`, - wantParams: append(timeRangeParams, "'9762a4fe-ac4b-47b5-ba4f-5f70d065849a'", "100"), + ` AND session_id = ? ORDER BY event_time ASC, uid ASC LIMIT 100;`, + wantParams: append(timeRangeParams, "'9762a4fe-ac4b-47b5-ba4f-5f70d065849a'"), }, { name: "query on time range with keyset", @@ -123,8 +123,8 @@ func Test_querier_prepareQuery(t *testing.T) { tablename: tablename, }, wantQuery: selectFromPrefix + whereTimeRange + - ` AND (event_time, uid) > (?,?) ORDER BY event_time ASC, uid ASC LIMIT ?`, - wantParams: append(timeRangeParams, otherTimestampParam, "'9762a4fe-ac4b-47b5-ba4f-5f70d065849a'", "100"), + ` AND (event_time, uid) > (?,?) ORDER BY event_time ASC, uid ASC LIMIT 100;`, + wantParams: append(timeRangeParams, otherTimestampParam, "'9762a4fe-ac4b-47b5-ba4f-5f70d065849a'"), }, { name: "query on time range DESC with keyset", @@ -140,8 +140,8 @@ func Test_querier_prepareQuery(t *testing.T) { tablename: tablename, }, wantQuery: selectFromPrefix + whereTimeRange + - ` AND (event_time, uid) < (?,?) ORDER BY event_time DESC, uid DESC LIMIT ?`, - wantParams: append(timeRangeParams, otherTimestampParam, "'9762a4fe-ac4b-47b5-ba4f-5f70d065849a'", "100"), + ` AND (event_time, uid) < (?,?) ORDER BY event_time DESC, uid DESC LIMIT 100;`, + wantParams: append(timeRangeParams, otherTimestampParam, "'9762a4fe-ac4b-47b5-ba4f-5f70d065849a'"), }, } for _, tt := range tests {