Skip to content

Commit

Permalink
fix(datastore): query limit without deleted rows (#2822)
Browse files Browse the repository at this point in the history
  • Loading branch information
jialeicui authored Oct 8, 2023
1 parent 3a48759 commit 4be25a5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,11 @@ public RecordList query(DataStoreQueryRequest req) {
--skipCount;
}
while (iterator.hasNext() && limitCount > 0) {
results.add(iterator.next());
var r = iterator.next();
if (r.isDeleted()) {
continue;
}
results.add(r);
--limitCount;
}
String lastKey;
Expand Down Expand Up @@ -290,7 +294,6 @@ public RecordList query(DataStoreQueryRequest req) {
columnSchemaMap = null;
}
var records = results.stream()
.filter(r -> !r.isDeleted())
.map(r -> RecordEncoder.encodeRecord(r.getValues(), req.isRawResult(), req.isEncodeWithType()))
.collect(Collectors.toList());
return new RecordList(columnSchemaMap,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,17 @@ public void testQuery() {
.columnValueHints(List.of("1", "2", "3", "4", "5"))
.build())));

// query with limit without deleted rows
this.dataStore.update("t1", desc, List.of(Map.of("k", "0", "-", "1")));
recordList = this.dataStore.query(DataStoreQueryRequest.builder().tableName("t1").limit(2).build());
assertThat("test",
recordList.getRecords(),
is(List.of(Map.of("k", "1", "a", "00000004"),
Map.of("k", "2", "a", "00000003"))));

// revert deleted rows
this.dataStore.update("t1", desc, List.of(Map.of("k", "0", "a", "5")));

recordList = this.dataStore.query(DataStoreQueryRequest.builder()
.tableName("t1")
.filter(TableQueryFilter.builder()
Expand Down

0 comments on commit 4be25a5

Please sign in to comment.