Skip to content

Commit

Permalink
fix sort pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Bukhin committed Mar 24, 2016
1 parent bca1787 commit de583b3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
12 changes: 11 additions & 1 deletion lib/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,15 @@ class ReadSql extends AdapterRead {
} else {
query = query.offset(this.offsetCount);
}

if (this.sortBorderValue) {
query = query.where(
this.sortFields[0].field,
this.sortFields[0].direction === 'desc' ? '<=' : '>=',
this.sortBorderValue
);
}

return query;
}

Expand Down Expand Up @@ -359,7 +368,8 @@ class ReadSql extends AdapterRead {

if (this.sortFields) {
let res = this.processPaginatedResults(points, this.sortFields[0].field);
res.readEnd = to;
this.sortBorderValue = res.borderValue;
res.readEnd = null; //read again
return res;
}

Expand Down
33 changes: 32 additions & 1 deletion test/optimize.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,38 @@ describe('test optimizations', function() {
expect(result.sinks.table).to.have.length.gt(5);
});
});
it('sort by field with pagination', function() {
return check_optimization_juttle({
program: 'read sql -fetchSize 40 -table "logs" | sort code',
optimize_param: {
type: "sort",
columns: [{
direction: "",
field: 'code'
}],
},
massage: {sort: ['host', 'level']},
})
.then(function(result) {
expect(result.sinks.table).to.have.length(150);
});
});
it('sort by field with pagination desc', function() {
return check_optimization_juttle({
program: 'read sql -fetchSize 40 -table "logs" | sort code -desc',
optimize_param: {
type: "sort",
columns: [{
direction: "desc",
field: 'code'
}],
},
massage: {sort: ['host', 'level']},
})
.then(function(result) {
expect(result.sinks.table).to.have.length(150);
});
});
it('sort by 2 fields', function() {
return check_optimization_juttle({
program: 'read sql -table "logs" | sort code, level | head 10',
Expand Down Expand Up @@ -71,7 +103,6 @@ describe('test optimizations', function() {
});
});


it('head with positive number', function() {
return check_optimization_juttle({
program: 'read sql -table "logs" level = "info" | head 5',
Expand Down

0 comments on commit de583b3

Please sign in to comment.