Skip to content
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
9 changes: 6 additions & 3 deletions lib/events/athena/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
24 changes: 12 additions & 12 deletions lib/events/athena/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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 {
Expand Down