1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-04 10:35:08 +02:00

Fixed incorrectly compiled LIMIT clause.

This commit is contained in:
Tim Voronov 2018-10-08 16:04:49 -04:00
parent d3f1a2d88d
commit da446892b5
3 changed files with 24 additions and 14 deletions

BIN
assets/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

View File

@ -497,9 +497,11 @@ func TestFor(t *testing.T) {
Convey("Should compile query with LIMIT 2, 2", t, func() {
c := compiler.New()
// 4 is offset
// 2 is count
prog, err := c.Compile(`
FOR i IN [ 1, 2, 3, 4, 1, 3 ]
LIMIT 2, 2
FOR i IN [ 1,2,3,4,5,6,7,8 ]
LIMIT 4, 2
RETURN i
`)
@ -509,7 +511,7 @@ func TestFor(t *testing.T) {
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `[3,4]`)
So(string(out), ShouldEqual, `[5,6]`)
})
Convey("Should compile query with FILTER i > 2", t, func() {

View File

@ -292,29 +292,37 @@ func (v *visitor) doVisitForExpression(ctx *fql.ForExpressionContext, scope *sco
}
func (v *visitor) createLimit(ctx *fql.LimitClauseContext) (int, int, error) {
var limit int
var err error
var count int
var offset int
intLiterals := ctx.AllIntegerLiteral()
limitLiteral := intLiterals[0]
limit, err := strconv.Atoi(limitLiteral.GetText())
if err != nil {
return 0, 0, err
}
if len(intLiterals) > 1 {
offsetLiteral := intLiterals[1]
offset, err = v.parseInt(intLiterals[0])
offset, err = strconv.Atoi(offsetLiteral.GetText())
if err != nil {
return 0, 0, err
}
count, err = v.parseInt(intLiterals[1])
if err != nil {
return 0, 0, err
}
} else {
count, err = strconv.Atoi(intLiterals[0].GetText())
if err != nil {
return 0, 0, err
}
}
return limit, offset, nil
return count, offset, nil
}
func (v *visitor) parseInt(node antlr.TerminalNode) (int, error) {
return strconv.Atoi(node.GetText())
}
func (v *visitor) createFilter(ctx *fql.FilterClauseContext, scope *scope) (core.Expression, error) {