Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 14 additions & 19 deletions internal/binder/function/funcs_analytic.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@
fType: ast.FuncTypeScalar,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
l := len(args) - 2
if l != 1 && l != 2 && l != 3 && l != 4 {
return fmt.Errorf("expect one two or three args but got %d", l), false
if l < 1 || l > 4 {
return fmt.Errorf("expect from 1 to 4 args but got %d", l), false

Check warning on line 129 in internal/binder/function/funcs_analytic.go

View check run for this annotation

Codecov / codecov/patch

internal/binder/function/funcs_analytic.go#L129

Added line #L129 was not covered by tests
}
key := args[len(args)-1].(string)
v, err := ctx.GetState(key)
Expand All @@ -137,34 +137,29 @@
if !ok {
return fmt.Errorf("when arg is not a bool but got %v", args[len(args)-2]), false
}
size := 1
if l >= 2 {
size, err = cast.ToInt(args[1], cast.STRICT)
if err != nil {
return fmt.Errorf("error converting second arg %v to int: %v", args[1], err), false
}

Check warning on line 145 in internal/binder/function/funcs_analytic.go

View check run for this annotation

Codecov / codecov/patch

internal/binder/function/funcs_analytic.go#L144-L145

Added lines #L144 - L145 were not covered by tests
}
var dftVal interface{} = nil
if l >= 3 {
dftVal = args[2]
}
ignoreNull := true
if l == 4 {
if l >= 4 {
ignoreNull, ok = args[3].(bool)
if !ok {
return fmt.Errorf("The fourth arg is not a bool but got %v", args[0]), false
}
}
paraLen := len(args) - 2
var rq *ringqueue = nil
var rtnVal interface{} = nil

// first time call, need create state for lag
if v == nil {
size := 0
var dftVal interface{} = nil
if paraLen == 3 {
dftVal = args[2]
}
if paraLen == 1 {
size = 1
} else {
size, err = cast.ToInt(args[1], cast.STRICT)
if err != nil {
return fmt.Errorf("error converting second arg %v to int: %v", args[1], err), false
}
}
rq = newRingqueue(size)

rq.fill(dftVal)
err := ctx.PutState(key, rq)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/binder/function/funcs_analytic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ func TestLagExec(t *testing.T) {
true,
"self",
},
result: nil,
result: "default",
},
{ // 2
args: []interface{}{
Expand Down
Loading