mirror of
https://github.com/pikami/cosmium.git
synced 2025-02-13 03:16:48 +00:00
Fix OFFSET clause
This commit is contained in:
parent
5caa829ac1
commit
787cdb33cf
@ -60,6 +60,15 @@ func ExecuteQuery(query parsers.SelectStmt, documents []RowType) []RowType {
|
||||
projectedDocuments = deduplicate(projectedDocuments)
|
||||
}
|
||||
|
||||
// Apply offset
|
||||
if query.Offset > 0 {
|
||||
if query.Offset < len(projectedDocuments) {
|
||||
projectedDocuments = projectedDocuments[query.Offset:]
|
||||
} else {
|
||||
projectedDocuments = []RowType{}
|
||||
}
|
||||
}
|
||||
|
||||
// Apply result limit
|
||||
if query.Count > 0 && len(projectedDocuments) > query.Count {
|
||||
projectedDocuments = projectedDocuments[:query.Count]
|
||||
|
@ -10,10 +10,10 @@ import (
|
||||
|
||||
func Test_Execute_Select(t *testing.T) {
|
||||
mockData := []memoryexecutor.RowType{
|
||||
map[string]interface{}{"id": "12345", "pk": 123, "_self": "self1", "_rid": "rid1", "_ts": 123456, "isCool": false},
|
||||
map[string]interface{}{"id": "67890", "pk": 456, "_self": "self2", "_rid": "rid2", "_ts": 789012, "isCool": true},
|
||||
map[string]interface{}{"id": "456", "pk": 456, "_self": "self2", "_rid": "rid2", "_ts": 789012, "isCool": true},
|
||||
map[string]interface{}{"id": "123", "pk": 456, "_self": "self2", "_rid": "rid2", "_ts": 789012, "isCool": true},
|
||||
map[string]interface{}{"id": "12345", "pk": 123, "_self": "self1", "_rid": "rid1", "_ts": 123456, "isCool": false, "order": 1},
|
||||
map[string]interface{}{"id": "67890", "pk": 456, "_self": "self2", "_rid": "rid2", "_ts": 789012, "isCool": true, "order": 2},
|
||||
map[string]interface{}{"id": "456", "pk": 456, "_self": "self2", "_rid": "rid2", "_ts": 789012, "isCool": true, "order": 3},
|
||||
map[string]interface{}{"id": "123", "pk": 456, "_self": "self2", "_rid": "rid2", "_ts": 789012, "isCool": true, "order": 4},
|
||||
}
|
||||
|
||||
t.Run("Should execute simple SELECT", func(t *testing.T) {
|
||||
@ -108,15 +108,15 @@ func Test_Execute_Select(t *testing.T) {
|
||||
Offset: 1,
|
||||
OrderExpressions: []parsers.OrderExpression{
|
||||
{
|
||||
SelectItem: parsers.SelectItem{Path: []string{"c", "id"}},
|
||||
SelectItem: parsers.SelectItem{Path: []string{"c", "order"}},
|
||||
Direction: parsers.OrderDirectionDesc,
|
||||
},
|
||||
},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
map[string]interface{}{"id": "67890", "pk": 456},
|
||||
map[string]interface{}{"id": "456", "pk": 456},
|
||||
map[string]interface{}{"id": "67890", "pk": 456},
|
||||
},
|
||||
)
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user