Skip to content

Commit a910048

Browse files
author
Igor Polevoy
committed
#452 Too many aggregate statistics results for offsets
1 parent 1569c70 commit a910048

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

activejdbc/src/main/java/org/javalite/activejdbc/statistics/QueryExecutionEvent.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@
2525
public class QueryExecutionEvent {
2626

2727
private static final Pattern IN_PATTERN = Pattern.compile("(IN|in)\\s*\\(.*\\)", Pattern.CASE_INSENSITIVE);
28+
private static final Pattern OFFSET_PATTERN = Pattern.compile("(offset|OFFSET|Offset)\\s*\\d*", Pattern.CASE_INSENSITIVE);
2829

29-
private final String query;
30+
private String query;
3031
private final long time;
3132

3233
public QueryExecutionEvent(String query, long time) {
3334
this.query = IN_PATTERN.matcher(query).replaceAll("IN (...)");
35+
this.query = OFFSET_PATTERN.matcher(this.query).replaceAll("offset ...");
3436
this.time = time;
3537
}
3638

activejdbc/src/test/java/org/javalite/activejdbc/statistics/StatisticsQueueTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,11 @@ public void shouldNormalizeInSelects(){
109109
QueryExecutionEvent event = new QueryExecutionEvent("select * from people where id IN (1,2,3,4)", 1);
110110
the(event.getQuery()).shouldBeEqual("select * from people where id IN (...)");
111111
}
112+
113+
114+
@Test // related to: https://github.com/javalite/activejdbc/issues/452
115+
public void shouldNormalizeOffset(){
116+
QueryExecutionEvent event = new QueryExecutionEvent("select * from pages where lesson_id=? order by the_index limit 1 offset 0", 1);
117+
the(event.getQuery()).shouldBeEqual("select * from pages where lesson_id=? order by the_index limit 1 offset ...");
118+
}
112119
}

0 commit comments

Comments
 (0)