Skip to content

Commit

Permalink
wip sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
ziflex committed Dec 3, 2024
1 parent b956f37 commit 0c5c361
Show file tree
Hide file tree
Showing 28 changed files with 753 additions and 429 deletions.
31 changes: 31 additions & 0 deletions pkg/compiler/compiler_exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1307,3 +1307,34 @@ func TestForLimit(t *testing.T) {
return values.NewInt(2), nil
}))
}

func TestForSort(t *testing.T) {
RunUseCases(t, []UseCase{
CaseArray(`
LET users = [
{
active: true,
age: 31,
gender: "m"
},
{
active: true,
age: 29,
gender: "f"
},
{
active: true,
age: 36,
gender: "m"
}
]
FOR u IN users
SORT u.age
RETURN u
`, []any{
map[string]any{"active": true, "age": 29, "gender": "f"},
map[string]any{"active": true, "age": 31, "gender": "m"},
map[string]any{"active": true, "age": 36, "gender": "m"},
}, "Should compile query with SORT statement"),
})
}
25 changes: 15 additions & 10 deletions pkg/compiler/loops.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ type (
LoopKind int

Loop struct {
Type LoopType
Kind LoopKind
Distinct bool
Allocate bool
Next int
Src runtime.Operand
Iterator runtime.Operand
Value runtime.Operand
Key runtime.Operand
Result runtime.Operand
Type LoopType
Kind LoopKind
Distinct bool
Allocate bool
Jump int
JumpOffset int
Src runtime.Operand
Iterator runtime.Operand
ValueName string
Value runtime.Operand
KeyName string
Key runtime.Operand
Result runtime.Operand
}

LoopTable struct {
Expand Down Expand Up @@ -80,6 +83,8 @@ func (lt *LoopTable) EnterLoop(loopType LoopType, kind LoopKind, distinct bool)
return lt.loops[len(lt.loops)-1]
}

//func (lt *LoopTable) Fork() *Loop {}

func (lt *LoopTable) Loop() *Loop {
if len(lt.loops) == 0 {
return nil
Expand Down
Loading

0 comments on commit 0c5c361

Please sign in to comment.